1 10 11 package org.mule.impl.container; 12 13 import java.io.Reader ; 14 import java.util.Map ; 15 16 import javax.naming.Context ; 17 import javax.naming.InitialContext ; 18 import javax.naming.Name ; 19 import javax.naming.NamingException ; 20 21 import org.apache.commons.lang.ObjectUtils; 22 import org.mule.config.i18n.Message; 23 import org.mule.config.i18n.Messages; 24 import org.mule.umo.lifecycle.InitialisationException; 25 import org.mule.umo.manager.ContainerException; 26 import org.mule.umo.manager.ObjectNotFoundException; 27 28 33 public class JndiContainerContext extends AbstractContainerContext 34 { 35 protected volatile Context context; 36 private volatile Map environment; 37 38 public JndiContainerContext() 39 { 40 super("jndi"); 41 } 42 43 protected JndiContainerContext(String name) 44 { 45 super(name); 46 } 47 48 public Map getEnvironment() 49 { 50 return environment; 51 } 52 53 public void setEnvironment(Map environment) 54 { 55 this.environment = environment; 56 } 57 58 public Context getContext() 59 { 60 return context; 61 } 62 63 public void setContext(InitialContext context) 64 { 65 this.context = context; 66 } 67 68 public Object getComponent(Object key) throws ObjectNotFoundException 69 { 70 try 71 { 72 if (key == null) 73 { 74 throw new ObjectNotFoundException("null"); 75 } 76 if (key instanceof Name ) 77 { 78 return context.lookup((Name )key); 79 } 80 else if (key instanceof Class ) 81 { 82 return context.lookup(((Class )key).getName()); 83 } 84 else 85 { 86 return context.lookup(key.toString()); 87 } 88 } 89 catch (NamingException e) 90 { 91 throw new ObjectNotFoundException(ObjectUtils.toString(key, "null"), e); 92 } 93 } 94 95 public void configure(Reader configuration) throws ContainerException 96 { 97 throw new UnsupportedOperationException ("configure(Reader)"); 98 } 99 100 public void initialise() throws InitialisationException 101 { 102 try 103 { 104 if (context == null) 105 { 106 context = JndiContextHelper.initialise(getEnvironment()); 107 } 108 } 109 catch (NamingException e) 110 { 111 throw new InitialisationException(new Message(Messages.FAILED_TO_CREATE_X, "Jndi context"), e, 112 this); 113 } 114 } 115 } 116 | Popular Tags |