[jboss-user] [JNDI/Naming/Network] - Re: EJB3 - NameNotFoundException HELP! ITALIANO

marasma1 do-not-reply at jboss.com
Tue May 22 02:12:15 EDT 2007


  | package org.srdemo.view.util;
  | 
  | import java.util.HashMap;
  | import java.util.Hashtable;
  | 
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | 
  | public class ServiceLocator {
  |      /**
  |       * Singleton Instance of this class
  |       */
  |      private static ServiceLocator serviceLocator = null;
  | 
  |      /**
  |       * InitialContext object
  |       */
  |      InitialContext context = null;
  | 
  |      /**
  |       * Cache where the objects can be stored for later 
  |       * retrieval.
  |       * This enhances the performance.
  |       */
  |      HashMap serviceCache = null;
  | 
  |     /**
  |      * Constructor to initialize the class
  |      *
  |      * @exception NamingException In case an exception is 
  |      * generated
  |      */
  |      public ServiceLocator() throws NamingException {
  |       // Start the initial context
  |       
  |        /*Hashtable props = new Hashtable();
  |        props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  |        props.put("java.naming.provider.url", "jnp://localhost:1099");
  |        props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  |        context = new InitialContext(props);*/
  |       
  |       
  |       context = new InitialContext();
  |       // Initialize the HashMap to store 3 objects
  |       serviceCache = new HashMap(5);
  |      }
  |     
  |     /**
  |      * Returns the singleton instance
  |      *
  |      * @exception NamingException In case an exception is      
  |      * generated
  |      * @return Singleton Instance
  |      */
  |    public static ServiceLocator getInstance() throws 
  |      NamingException {
  |       if (serviceLocator == null) {
  |         // If the object is not created, then create it
  |         serviceLocator = new ServiceLocator();
  |       }
  | 
  |       // Return the singleton instance
  |       return serviceLocator;
  |     }
  |     
  |     /**
  |      * This is the method that returns the service
  |      *
  |      * @param jndiName JNDI Lookup needed for invoking the 
  |      * service
  |      * @exception NamingException In case an exception is 
  |      * generated
  |      * @return Service Object
  |      */
  |     public Object getService(String jndiName) throws 
  |      NamingException {
  |       if (!serviceCache.containsKey(jndiName)) {
  |         // If the object is not saved in the cache, then do a         
  |         //lookup and save it
  |         serviceCache.put(jndiName, context.lookup(jndiName));
  |       }
  |       // Return the required object
  |       return serviceCache.get(jndiName);
  |     }
  |     
  |     public Object getFacadeService(String jndiName)throws 
  |       NamingException{
  |         if (!serviceCache.containsKey(jndiName)) {
  |            //lookup and save in cache
  |             serviceCache.put(jndiName, context.lookup(jndiName));
  |         }
  |         return serviceCache.get(jndiName);
  |     }
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4047436#4047436

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4047436



More information about the jboss-user mailing list