public final class FactoryPoolClient implements FactoryPool { 
    public FactoryPoolClient() { 
        super(); 
    }     private static String FACTORYPOOLEJB = "FactoryPoolEJB";     private Context _context = null; 
    private FactoryPoolEJB _factoryPoolEJB = null; 
    private FactoryPoolEJBHome _factoryPoolEJBHome = null;     private ContextInfo _contextInfo = new ContextInfo();     private class ContextInfo { 
        public ContextInfo() {         }         String _url = ""; 
        String _initial_context = ""; 
        String _user = ""; 
        String _pass = "";         public boolean EqualContext(String url, String initial_context, String user, String pass) { 
            if (url.equals(_url)) { 
                if (initial_context.equals(_initial_context)) { 
                    if (user.equals(_user)) { 
                        if (pass.equals(_pass)) { 
                            return true; 
                        } else { 
                            _pass = pass; 
                        } 
                    } else { 
                        _user = user; 
                    } 
                } else { 
                    _initial_context = initial_context; 
                } 
            } else { 
                _url = url; 
            }             return false; 
        } 
    } 
    public PoolMark CreatePoolMark(String host, String url, String initial_context, String user, 
        String pass, String database) throws CreatePoolMarkException { 
    boolean bCreateFlag = CreateFactoryPoolEJB(url, initial_context, user, pass); 
    System.out.println(bCreateFlag); 
    
        if (bCreateFlag) { 
            try { 
                return _factoryPoolEJB.CreatePoolMark(host, url, initial_context, user, pass, 
                    database); 
            } catch (RemoteException ex) { 
                throw new CreatePoolMarkException(ex); 
            } 
        } 
        return null; 
    }     public ServiceFactory AcquireServiceFactory(PoolMark poolMark) throws 
        UnsupportedProtocolException, StartupException, AcquireServiceFactoryException, 
        PoolMarkNotExistException { 
        try { 
            return _factoryPoolEJB.AcquireServiceFactory(poolMark); 
        } catch (RemoteException ex) { 
            throw new StartupException(ex); 
        } 
    }     public void ReleaseServiceFactory(PoolMark poolMark) throws ShutdownException { 
        try { 
            _factoryPoolEJB.ReleaseServiceFactory(poolMark); 
        } catch (RemoteException ex) { 
            throw new ShutdownException(ex.getMessage()); 
        } 
    }     protected Context getInitialContext(String url, String user, String password, 
        String inital_context) throws Exception { 
        Properties properties; 
        try { 
            properties = new Properties(); 
            properties.put(Context.INITIAL_CONTEXT_FACTORY, inital_context); 
            properties.put(Context.PROVIDER_URL, url); 
            if (user != null) { 
                properties.put(Context.SECURITY_PRINCIPAL, user); 
                properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password); 
            } 
            return new javax.naming.InitialContext(properties); 
        } catch (Exception e) { 
        e.printStackTrace(); 
            throw e; 
        } 
    }     protected boolean CreateFactoryPoolEJB(String url, String initial_context, String user, 
        String pass) { 
        try { 
            if (_contextInfo.EqualContext(url, initial_context, user, pass)) { 
                if (_context == null) { 
                    _context = getInitialContext(url, initial_context, user, pass); 
                } else { 
                    if (_factoryPoolEJB != null) { 
                        return true; 
                    } 
                } 
            } else { 
                _context = getInitialContext(url, initial_context, user, pass); 
            }             if (_context == null) { 
                return false; 
            }             Object ref = _context.lookup(FACTORYPOOLEJB); 
            _factoryPoolEJBHome = (FactoryPoolEJBHome) PortableRemoteObject.narrow(ref, 
                FactoryPoolEJBHome.class);             _factoryPoolEJB = _factoryPoolEJBHome.create();             return true; 
        } catch (Exception ex) { 
        ex.printStackTrace(); 
            return false; 
        } 
    }     public void ForceReleaseServiceFactory(PoolMark poolMark) throws ShutdownException { 
    } 
    
    public void setMinMax(int iMin, int iMax) throws RemoteException { 
    _factoryPoolEJB.setMinMax(iMin, iMax); 
    } 
}