1 10 11 package org.mule.providers; 12 13 import org.mule.config.i18n.Message; 14 import org.mule.config.i18n.Messages; 15 import org.mule.umo.lifecycle.InitialisationException; 16 17 import javax.naming.Context ; 18 import javax.naming.InitialContext ; 19 import javax.naming.NamingException ; 20 21 import java.util.Hashtable ; 22 import java.util.Map ; 23 24 31 32 public abstract class AbstractJndiConnector extends AbstractServiceEnabledConnector 33 { 34 protected String jndiInitialFactory; 35 36 protected String jndiUrlPkgPrefixes; 37 38 protected String jndiProviderUrl; 39 40 protected Context jndiContext; 41 42 protected Map jndiProviderProperties = null; 43 44 protected void initJndiContext() throws InitialisationException 45 { 46 if (null == jndiContext) 47 { 48 Hashtable props = new Hashtable (); 49 50 if (null != jndiInitialFactory) 51 { 52 props.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialFactory); 53 } 54 55 if (jndiProviderUrl != null) 56 { 57 props.put(Context.PROVIDER_URL, jndiProviderUrl); 58 } 59 60 if (jndiUrlPkgPrefixes != null) 61 { 62 props.put(Context.URL_PKG_PREFIXES, jndiUrlPkgPrefixes); 63 } 64 65 if (jndiProviderProperties != null) 66 { 67 props.putAll(jndiProviderProperties); 68 } 69 try 70 { 71 jndiContext = new InitialContext (props); 72 } 73 catch (NamingException e) 74 { 75 throw new InitialisationException(e, this); 76 } 77 } 78 } 79 80 public Context getJndiContext(String jndiProviderUrl) throws InitialisationException 81 { 82 try 83 { 84 setJndiProviderUrl(jndiProviderUrl); 85 86 initJndiContext(); 87 } 88 catch (Exception e) 89 { 90 throw new InitialisationException(new Message(Messages.FAILED_TO_CREATE_X, 91 "AbstractJndiConnector"), e, this); 92 } 93 94 return jndiContext; 95 } 96 97 public Context getJndiContext() 98 { 99 100 return jndiContext; 101 } 102 103 public void setJndiContext(Context jndiContext) 104 { 105 this.jndiContext = jndiContext; 106 } 107 108 public void setJndiInitialFactory(String jndiInitialFactory) 109 { 110 this.jndiInitialFactory = jndiInitialFactory; 111 } 112 113 public String getJndiInitialFactory() 114 { 115 return jndiInitialFactory; 116 } 117 118 public void setJndiUrlPkgPrefixes(String jndiUrlPkgPrefixes) 119 { 120 this.jndiUrlPkgPrefixes = jndiUrlPkgPrefixes; 121 } 122 123 public String getJndiUrlPkgPrefixes() 124 { 125 return jndiUrlPkgPrefixes; 126 } 127 128 public String getJndiProviderUrl() 129 { 130 return jndiProviderUrl; 131 } 132 133 public void setJndiProviderUrl(String jndiProviderUrl) 134 { 135 this.jndiProviderUrl = jndiProviderUrl; 136 } 137 138 public Map getJndiProviderProperties() 139 { 140 return jndiProviderProperties; 141 } 142 143 public void setJndiProviderProperties(Map jndiProviderProperties) 144 { 145 this.jndiProviderProperties = jndiProviderProperties; 146 } 147 } 148 | Popular Tags |