1 25 package org.objectweb.easybeans.tests.common.helper; 26 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 30 35 public final class EJBHelper { 36 37 40 private EJBHelper() { 41 } 42 43 46 public static final String ITF_REMOTE = "@Remote"; 47 48 51 public static final String ITF_LOCAL = "@Local"; 52 53 61 @SuppressWarnings ("unchecked") 62 public static synchronized <E> E getBeanRemoteInstance(final Class beanClass, final Class <E> beanInterface) throws Exception { 63 System.setProperty(Context.INITIAL_CONTEXT_FACTORY, 64 "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory"); 65 66 Context initialContext = new InitialContext (); 67 E clBean = (E) initialContext.lookup(beanClass.getName() + "_" + beanInterface.getName() + ITF_REMOTE); 68 return clBean; 69 } 70 71 79 @SuppressWarnings ("unchecked") 80 public static synchronized <E> E getBeanLocalInstance(final Class beanClass, final Class <E> beanInterface) throws Exception { 81 System.setProperty(Context.INITIAL_CONTEXT_FACTORY, 82 "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory"); 83 84 Context initialContext = new InitialContext (); 85 E clBean = (E) initialContext.lookup(beanClass.getName() + "_" + beanInterface.getName() + ITF_LOCAL); 86 return clBean; 87 } 88 89 96 @SuppressWarnings ("unchecked") 97 public static synchronized <E> E getBeanByMappedName(final String mappedName) throws Exception { 98 System.setProperty(Context.INITIAL_CONTEXT_FACTORY, 99 "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory"); 100 101 Context initialContext = new InitialContext (); 102 E clBean = (E) initialContext.lookup(mappedName); 103 return clBean; 104 } 105 106 } 107 | Popular Tags |