[CJ-dev] commonjava-projects/commonjava-enterprise-services/src/java/org/commonjava/j2ee/services Se
Brought to you by:
johnqueso
From: <joh...@co...> - 2004-02-18 06:22:07
|
Update of /cvsroot/commonjava/commonjava-projects/commonjava-enterprise-services/src/java/org/commonjava/j2ee/services In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26828/src/java/org/commonjava/j2ee/services Modified Files: ServiceLocator.java Log Message: updated documentation in project.xml files, and added functionality to: Console: - provide convenient way to prompt the user for more information Config: - Provide snap-in container stacking, or scoping - Provide a JBoss service implementation of a snap-in container Probably other things, but I don't honestly remember everything... Index: ServiceLocator.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-enterprise-services/src/java/org/commonjava/j2ee/services/ServiceLocator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ServiceLocator.java 10 Oct 2003 03:14:36 -0000 1.2 +++ ServiceLocator.java 18 Feb 2004 06:12:47 -0000 1.3 @@ -88,6 +88,39 @@ return result; } + /** Retrieve the JNDI configuration for service lookups, then lookup the specified + * service object. + * @param jndiName The JNDI binding. + * @param serviceClass The class of the service to retrieve. + */ + public static Object getService(String jndiName, Class serviceClass) + throws EnterpriseConfigurationException, NamingException + { + Object result = null; + InitialContext ctx = null; + try{ + EnterpriseConfiguration config = EnterpriseConfiguration.getConfiguration(); + JndiConfig jndiConfig = config.getEjbJndiConfig(); + if(jndiConfig.useContextEnvironment()){ + ctx = new InitialContext(jndiConfig.getEnvironment()); + } + else{ + ctx = new InitialContext(); + } + result = ctx.lookup(jndiName); + if(!serviceClass.isInstance(result)){ + result = PortableRemoteObject.narrow(result, serviceClass); + } + } + finally{ + if(ctx != null){ + ctx.close(); + } + } + + return result; + } + /** Retrieve the JNDI configuration for JDBC lookups, then lookup the specified * jndi binding and return a JMS queue connection information object. * @param jndiName The JNDI binding @@ -98,4 +131,88 @@ return null; } + /** Retrieve the JNDI configuration for EJB lookups, then lookup the specified + * jndi binding and return an EJB home interface, cast to the specified class. + * @param jndiName The JNDI binding + * @param castTo The class to cast the lookup result to. + */ + public static Object getLocalEjbHome(String jndiName, Class castTo) + throws EnterpriseConfigurationException, NamingException + { + Object result = null; + InitialContext ctx = null; + try{ + ctx = new InitialContext(); + result = ctx.lookup(jndiName); + if(!castTo.isInstance(result)){ + result = PortableRemoteObject.narrow(result, castTo); + } + } + finally{ + if(ctx != null){ + ctx.close(); + } + } + + return result; + } + + /** Retrieve the JNDI configuration for JDBC lookups, then lookup the specified + * jndi binding and return a JDBC DataSource. + * @param jndiName The JNDI binding + */ + public static DataSource getLocalDataSource(String jndiName) + throws EnterpriseConfigurationException, NamingException + { + DataSource result = null; + InitialContext ctx = null; + try{ + ctx = new InitialContext(); + result = (DataSource)ctx.lookup(jndiName); + } + finally{ + if(ctx != null){ + ctx.close(); + } + } + + return result; + } + + /** Retrieve the JNDI configuration for service lookups, then lookup the specified + * service object. + * @param jndiName The JNDI binding. + * @param serviceClass The class of the service to retrieve. + */ + public static Object getLocalService(String jndiName, Class serviceClass) + throws EnterpriseConfigurationException, NamingException + { + Object result = null; + InitialContext ctx = null; + try{ + ctx = new InitialContext(); + result = ctx.lookup(jndiName); + if(!serviceClass.isInstance(result)){ + result = PortableRemoteObject.narrow(result, serviceClass); + } + } + finally{ + if(ctx != null){ + ctx.close(); + } + } + + return result; + } + + /** Retrieve the JNDI configuration for JDBC lookups, then lookup the specified + * jndi binding and return a JMS queue connection information object. + * @param jndiName The JNDI binding + */ + public static JmsQueueInfo getLocalJmsQueue(String jndiName) + { + //FINISH Implement getJmsQueue(String):JmsQueueInfo in ServiceLocator. + return null; + } + } |