FileDocCategorySizeDatePackage
ObjectServerImpl.javaAPI DocExample5191Fri Aug 25 09:05:54 BST 2000com.imaginary.lwp

ObjectServerImpl

public class ObjectServerImpl extends UnicastRemoteObject implements ObjectServer

Fields Summary
private Authenticator
authenticator
private HashMap
homes
Constructors Summary
private ObjectServerImpl()

    
        
        super();
        {
            String acl = System.getProperty(LWPProperties.AUTHENTICATOR);

            try {
                authenticator =(Authenticator)Class.forName(acl).newInstance();
            }
            catch( Exception e ) {
                authenticator = new JDBCAuthenticator();
            }
        }
    
Methods Summary
private booleanisAuthenticated(Identifier id)

        return Identifier.isAuthenticated(id);
    
public Identifierlogin(java.lang.String uid, java.lang.String pw)

        authenticator.authenticate(uid, pw);
        return new Identifier(uid);
    
public Identifierlogin(java.lang.String uid, java.lang.String pw, AuthenticationRole r)

        authenticator.authenticate(uid, pw, r);
        return new Identifier(uid, r);
    
public Homelookup(Identifier id, java.lang.String cname)

        String hname;
        Home home;
        int len;

        if( !isAuthenticated(id) ) {
            return null;
        }
        len = cname.length();
        if( len > 4 ) {
            if( cname.substring(len-4).equals("Impl") ) {
                hname = cname.substring(0, len-4);
            }
            else if( len > 6 ) {
                if( cname.substring(len-6).equals("Facade") ) {
                    hname = cname.substring(0, len-6);
                }
                else {
                    hname = cname;
                }
            }
            else {
                hname = cname;
            }
        }
        else {
            hname = cname;
        }
        hname = hname + "HomeImpl";
        synchronized( homes ) {
            if( homes.containsKey(hname) ) {
                return (Home)homes.get(hname);
            }
            try {
                home = (Home)Class.forName(hname).newInstance();
            }
            catch( ClassCastException e ) {
                throw new LookupException(e.getMessage());
            }
            catch( ClassNotFoundException e ) {
                throw new LookupException(e.getMessage());
            }
            catch( IllegalAccessException e ) {
                throw new LookupException(e.getMessage());
            }
            catch( InstantiationException e ) {
                throw new LookupException(e.getMessage());
            }
            homes.put(hname, home);
            return home;
        }
    
public static voidmain(java.lang.String[] args)

        try {
            String bundle = System.getProperty(LWPProperties.PROPS_BUNDLE);
            Thread t;

            t = new Thread() {
                public void run() {
                    Identifier id = Identifier.getServerID();
                }
            };
            t.setPriority(Thread.MIN_PRIORITY);
            t.start();
            if( bundle != null ) {
                PropertyReader r = new PropertyReader();

                r.read(bundle);
            }
            else {
                String fname = System.getProperty(LWPProperties.PROPS_FILE);

                if( fname != null ) {
                    PropertyReader r = new PropertyReader();

                    r.read(new File(fname));
                }
            }
            Naming.rebind(System.getProperty(LWPProperties.RMI_URL),
                          new ObjectServerImpl());
        }
        catch( Exception e ) {
            e.printStackTrace();
        }
    
public SessionstartSession(Identifier id, java.lang.String cname)

        String sname;
        int len;
        
        if( !isAuthenticated(id) ) {
            return null;
        }
        len = cname.length();
        if( len > 7 ) {
            if( cname.substring(len-7).equals("Session") ) {
                sname = cname.substring(0, len-7);
            }
            else {
                sname = cname;
            }
        }
        else {
            sname = cname;
        }
        sname = sname + "Session";
        try {
            return (Session)Class.forName(sname).newInstance();
        }
        catch( ClassCastException e ) {
            throw new LookupException(e.getMessage());
        }
        catch( ClassNotFoundException e ) {
            throw new LookupException(e.getMessage());
        }
        catch( IllegalAccessException e ) {
            throw new LookupException(e.getMessage());
        }
        catch( InstantiationException e ) {
            throw new LookupException(e.getMessage());
        }