Email web hosting - home references will likely be created, but no
home references will likely be created, but no harm will be done. Notice that our EJBHomeFactory class accepts the JNDI name and class for the home interface it is requested to locate. If we needed to access more than one session bean in the application tier, we would simply implement a delegate class for each session bean and use our factory to locate the corresponding home interface. Besides the performance improvements the caching of homes gives us, all the ugly narrowing and exception handling that goes along with looking up these references is kept in one place. The EJBHomeFactory constructor also takes care of externalizing the provider and factory parameters we need to access the naming service. A standard approach for doing this is to use a jndi.properties file that includes entries like the following: java.naming.factory.initial=org.jnp.interfaces.NamingContextFactoryjava.naming.provider.url=localhost If you call the no-argument constructor for the InitialContext class, the classpath is searched for a jndi.properties file. If this file is found, its entries are used to initialize the naming context. In our example, the factory class explicitly loads this file from the classpath. Otherwise, classloader priorities within the web server could prevent these settings from being picked up before the default values defined for the server. The example in Chapter 9 demonstrated how the naming service parameters could be read from the web.xml file and stored in the ServletContext. We’re not using that approach here because we want to keep our factory independent of the web tier. 13.2.2.2 Using an EJBHomeFactory in a business delegate Our business delegate can be simplified now that we have a standard approach for locating the home interface. We can change the implementation of the init( )method to the following: private void init( ) { try { StorefrontHome sfHome = (StorefrontHome)EJBHomeFactory.getInstance( ). lookupHome(”com.oreilly.struts.storefront.service.Storefront”, StorefrontHome.class); storefront = sfHome.create( ); } catch (NamingException e) { throw new RuntimeException(e.getMessage( )); } catch (CreateException e) { throw new RuntimeException(e.getMessage( )); }
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.