JBoss 4.0.2. RemoteServiceLocator used by standalone web-app looks like this:





package com.massolit;



import javax.naming.Context;

import javax.naming.NamingException;

import javax.naming.InitialContext;

import java.util.Hashtable;

import org.apache.log4j.*;

import com.massolit.service.ejb.*;









/**

 * Locates and provides all available application services.

 */

public class RemoteServiceLocator {



  /**

   * The shared instance of this ServiceLocator.

   */

  private static RemoteServiceLocator instance;

  private static Logger logger = 
Logger.getLogger("RemoteServiceLocator");



  protected RemoteServiceLocator() {

    // shouldn't be instantiated

  }



  /**

   * Gets the shared instance of this Class

   *

   * @return the shared service locator instance.

   */

  public static final RemoteServiceLocator instance() {

    if (instance == null) {

      instance = new RemoteServiceLocator();

    }

    return instance;

  }



  private static InitialContext getInitialContext() throws 
NamingException {

    Hashtable environment = new Hashtable();





    environment.put(Context.INITIAL_CONTEXT_FACTORY,

                    
"org.jnp.interfaces.NamingContextFactory");

    environment.put(Context.URL_PKG_PREFIXES,

                    
"org.jboss.naming:org.jnp.interfaces");

    environment.put(Context.PROVIDER_URL, "jnp://" + hostname 
+ ":1099");

    logger.debug("initial context set with 
hostname:"+hostname+":1099");







    InitialContext toRet = new InitialContext(environment);



    return toRet;

  }





  private static Object lookupHome(java.util.Hashtable environment,

                      
             String jndiName, Class 
narrowTo) throws

      javax.naming.NamingException {

    logger.debug("getting initial context...");

    javax.naming.InitialContext initialContext = 
getInitialContext();

    logger.debug("looking up "+jndiName+" JNDI name...");



    try {

      Object object = initialContext.lookup(jndiName);

      // only narrow if necessary

      logger.debug("checking if should narrow...");

      if 
(narrowTo.isInstance(java.rmi.Remote.class)) {

        logger.debug("narrowing...");

        object = 
javax.rmi.PortableRemoteObject.narrow(object, narrowTo);

      } else logger.debug("don't need to narrow.");

      logger.debug("Home interface found successfully");

      return object;

    } finally {

      initialContext.close();

    }



  }



  private static com.massolit.service.ejb.MassolitCatalogServiceHome

      massolitCatalogServiceHome = null;



  private static String hostname;

  /**

   * Gets an instance of 
<code>com.massolit.service.MassolitCatalogService</code>

&nbsp; &nbsp;*/

&nbsp; public final com.massolit.service.ejb.MassolitCatalogService

&nbsp; &nbsp; &nbsp; getMassolitCatalogService&#40;String toConnect&#41; &#123;

&nbsp; &nbsp; this.hostname = toConnect;

&nbsp; &nbsp; logger.debug&#40;"Getting home interface from host 
"+toConnect&#41;;

&nbsp; &nbsp; try &#123;



&nbsp; &nbsp; &nbsp; if &#40;massolitCatalogServiceHome == null&#41; &#123;

&nbsp; &nbsp; &nbsp; &nbsp; massolitCatalogServiceHome = 
&#40;com.massolit.service.ejb.

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
MassolitCatalogServiceHome&#41; lookupHome&#40;null,

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
com.massolit.service.ejb.MassolitCatalogServiceHome.JNDI_NAME,

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;com.massolit.service.ejb.

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp;MassolitCatalogServiceHome.class&#41;;

&nbsp; &nbsp; &nbsp; &#125;

&nbsp; &nbsp; &nbsp; logger.debug&#40;"Creating service..."&#41;;&nbsp; &nbsp; 
&nbsp; 

&nbsp; &nbsp; &nbsp; MassolitCatalogService toRet = 
massolitCatalogServiceHome.create&#40;&#41;;





&nbsp; &nbsp; &nbsp; logger.info&#40;"Service successfully initialized."&#41;;

&nbsp; &nbsp; &nbsp; return toRet;



&nbsp; &nbsp; &#125; catch &#40;Exception ex&#41; &#123;

&nbsp; &nbsp; &nbsp; throw new javax.ejb.EJBException&#40;ex&#41;;

&nbsp; &nbsp; &#125;



&nbsp; &#125;



&#125;





webapp uses spring-enabled ServiceLocator generated by AndroMDA. 
hibernate.version=2.1.8
_________________________________________________________
Reply to the post : http://galaxy.andromda.org/forum/viewtopic.php?p=2344#2344
Posting to http://forum.andromda.org/ is preferred over posting to the mailing 
list!


-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP, 
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
Andromda-user mailing list
Andromda-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/andromda-user

Reply via email to