1 10 11 package org.mule.impl.container; 12 13 import org.mule.config.i18n.Message; 14 import org.mule.config.i18n.Messages; 15 import org.mule.umo.manager.ObjectNotFoundException; 16 import org.mule.util.ClassUtils; 17 18 import javax.ejb.EJBHome ; 19 import javax.naming.NamingException ; 20 21 import java.lang.reflect.Method ; 22 23 30 public class EjbContainerContext extends RmiContainerContext 31 { 32 public EjbContainerContext() 33 { 34 super("ejb"); 35 } 36 37 protected EjbContainerContext(String name) 38 { 39 super(name); 40 } 41 42 public Object getComponent(Object key) throws ObjectNotFoundException 43 { 44 Object homeObject = null; 45 if (key == null) 46 { 47 throw new ObjectNotFoundException("null"); 48 } 49 try 50 { 51 homeObject = context.lookup(key.toString()); 52 } 53 catch (NamingException e) 54 { 55 throw new ObjectNotFoundException(key.toString(), e); 56 } 57 58 if (homeObject == null) 59 { 60 throw new ObjectNotFoundException(key.toString()); 61 } 62 else if (homeObject instanceof EJBHome ) 63 { 64 65 Method method = ClassUtils.getMethod("create", null, homeObject.getClass()); 66 if (method == null) 67 { 68 throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException (new Message( 69 Messages.EJB_OBJECT_X_MISSING_CREATE, key).toString())); 70 } 71 try 72 { 73 return method.invoke(homeObject, ClassUtils.NO_ARGS); 74 } 75 catch (Exception e) 76 { 77 throw new ObjectNotFoundException(key.toString(), e); 78 } 79 } 80 else 81 { 82 throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException (new Message( 83 Messages.EJB_KEY_REF_X_NOT_VALID, key).toString())); 84 } 85 } 86 } 87 | Popular Tags |