EJBLocalHome getEjbLocalHome(beanname)
switch beanname
case ...
   ejbname = ...
   return ctx.lookup(ejbname)
 
  

解决方案 »

  1.   

    public EJBLocalHome getLocalHome(String localHome) {
            EJBLocalHome home = null;
            Context ctx = new InitialContext();
            try {
                switch(localHome)
                case ..
                home = (EJBLocalHome) ctx.lookup(localHome);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            return home;
        }
      

  2.   

    这里的EJBLocalHome 是超类的类型吗?
    这样,我怎么调用子类里的方法?
      

  3.   

    把操作封装成Event或是Action,用来区分,然后再分派到不同的Session Bean处理。
      

  4.   

    首先要感谢 inprise_lyj(只愛一點點) 。到了这一步你还不知道什么用。真不知道ejb你是怎么学的。
      

  5.   

    你这个方法我早就知道,不过,不是我要的。这样,如果,我增加一个业务逻辑的Bean
    就意味这,我就要改一下这个方法。我想要的是,dispatcher与后面的业务逻辑的bean无关。
    可能,我的j2ee学的还不是很好。这个方案,我以前用com+,实现了的。我现在想把这个机构迁移到ejb上。请大家帮忙啊,谢谢
      

  6.   

    可以在那个组织业务逻辑的EJB中调用资源环境啊,比如<env-entry>、ejb-ref啊!
      

  7.   

    你不如写个JAVABEAN专门控制你要雕哪个JNDI名和BEAN名呢。
      

  8.   

    public class ServiceLocator
    {  private static ServiceLocator serviceLocator = null;
      private  static Hashtable dataSourceCache = null;
      private static Hashtable ejgHomeCache = null;
      public  static String DATASOURCENAME=JNDINames.DATASOURCENAME;  static
      {
        serviceLocator = new ServiceLocator();
      }  private ServiceLocator()
      {
        dataSourceCache = new Hashtable();
        ejgHomeCache = new Hashtable();  }  public static ServiceLocator getInstance()
      {
        return serviceLocator;
      }  public Connection getConnection(String jdbcName) throws
          ServiceLocatorException
      {
        Connection conn = null;    try {      if (dataSourceCache.containsKey(jdbcName)) {
           DataSource oldDs = (DataSource) dataSourceCache.get(jdbcName);
           conn=  oldDs.getConnection();
           return conn;
         }
         else {
            javax.naming.InitialContext ictx = new javax.naming.InitialContext();
            DataSource newDs = (DataSource) ictx.lookup(jdbcName);
            dataSourceCache.put(jdbcName, newDs);
            conn= newDs.getConnection();
            return conn;
          }
        }
        catch (SQLException e1) {
          throw new ServiceLocatorException("SQL error has occurred in get connection"+e1);
        }
        catch (NamingException e2) {
          throw new ServiceLocatorException(" JDNI naming has occurred" +e2);
        }
        catch (Exception e3) {
          throw new ServiceLocatorException("exception has occurred in  get connection"+e3);
        }  }  public EJBHome getEJBHome(String jndiName, Class className) throws
          ServiceLocatorException
      {
         EJBHome ejbHome = null;
        try {
         if (dataSourceCache.containsKey(jndiName)) {
            ejbHome = (EJBHome) dataSourceCache.get(jndiName);
           return ejbHome;
          }
         else {
            javax.naming.InitialContext ictx = new javax.naming.InitialContext();
            Object jndiRef = ictx.lookup(jndiName);
            ejbHome = (EJBHome) PortableRemoteObject.narrow(jndiRef,
                className);
            dataSourceCache.put(jndiName, ejbHome);
            return ejbHome;
         }
        }
        catch (NamingException e2) {
          throw new ServiceLocatorException(" JDNI naming has occurred" +e2);
        }
        catch (Exception e3) {
          throw new ServiceLocatorException("exception has occurred in  get connection"+e3);
        }
      }}