- See Also:
- Top Examples, Source Code
public void remove(Object primaryKey)
throws RemoveException,
EJBException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[637]GOF: Service Locator pattern
By Anonymous on 2004/02/03 17:54:07 Rate
public class ServiceLocator {
private Context _context;
private Map _cache;
private static ServiceLocator _instance;
private ServiceLocator ( ) throws Exception {
try {
_context = getInitialContext ( ) ;
_cache = Collections.synchronizedMap ( new HashMap ( ) ) ;
} catch ( Exception ex ) {
System.out.println ( ex ) ;
throw ex;
}
}
static public ServiceLocator getInstance ( ) throws Exception {
if ( _instance == null ) {
_instance = new ServiceLocator ( ) ;
return _instance;
}
return _instance;
}
public EJBLocalHome getLocalHome ( String jndiHomeName ) throws Exception {
EJBLocalHome home = null;
try {
if ( _cache.containsKey ( jndiHomeName ) ) {
home = ( EJBLocalHome ) _cache.get ( jndiHomeName ) ;
} else {
home = ( EJBLocalHome ) _context.lookup ( jndiHomeName ) ;
_cache.put ( jndiHomeName, home ) ;
}
} catch ( Exception ex ) {
System.out.println ( ex ) ;
throw ex;
}
return home;
}
public EJBHome getRemoteHome ( String jndiHomeName, Class className )
throws Exception {
EJBHome home = null;
try {
if ( _cache.containsKey ( jndiHomeName ) ) {
home = ( EJBHome ) _cache.get ( jndiHomeName ) ;
} else {
Object objref = _context.lookup ( jndiHomeName ) ;
Object obj = PortableRemoteObject.narrow ( objref, className ) ;
home = ( EJBHome ) obj;
_cache.put ( jndiHomeName, home ) ;
}
} catch ( Exception ex ) {
System.out.println ( ex ) ;
throw ex;
}
return home;
}
public static Context getInitialContext ( ) throws NamingException {
Hashtable env = new Hashtable ( ) ;
env.put (
Context.INITIAL_CONTEXT_FACTORY,
AcmeProperties.getProperty ( "jndi.INITIAL_CONTEXT_FACTORY" ) ) ;
env.put (
Context.SECURITY_PRINCIPAL,
AcmeProperties.getProperty ( "jndi.SECURITY_PRINCIPAL" ) ) ;
env.put (
Context.SECURITY_CREDENTIALS,
AcmeProperties.getProperty ( "jndi.SECURITY_CREDENTIALS" ) ) ;
env.put (
Context.PROVIDER_URL,
AcmeProperties.getProperty ( "jndi.PROVIDER_URL" ) ) ;
return new InitialContext ( env ) ;
}
}
//remove