User: stark
Date: 01/01/16 19:29:17
Modified: src/main/org/jboss/naming ExternalContext.java
ExternalContextMBean.java
Log:
Add InitialContext property to allow for setting of the IntialContext class.
Should be one of: javax.naming.InitialContext,
javax.naming.directory.InitialDirContext,
javax.naming.ldap.InitialLdapContext
Revision Changes Path
1.2 +46 -2 jboss/src/main/org/jboss/naming/ExternalContext.java
Index: ExternalContext.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/naming/ExternalContext.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExternalContext.java 2001/01/14 01:28:37 1.1
+++ ExternalContext.java 2001/01/17 03:29:17 1.2
@@ -8,7 +8,9 @@
import java.io.InputStream;
import java.io.IOException;
+import java.lang.reflect.Constructor;
import java.net.URL;
+import java.util.Hashtable;
import java.util.Properties;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -19,6 +21,7 @@
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
+import javax.naming.ldap.Control;
import org.jnp.server.Main;
@@ -31,7 +34,7 @@
@see org.jboss.naming.NonSerializableFactory
@author [EMAIL PROTECTED]
-@version $Revision: 1.1 $
+@version $Revision: 1.2 $
*/
public class ExternalContext extends ServiceMBeanSupport implements
ExternalContextMBean
{
@@ -39,6 +42,7 @@
// Attributes ----------------------------------------------------
private String jndiName;
+ private Class contextClass = javax.naming.InitialContext.class;
private Properties contextProps;
// Static --------------------------------------------------------
@@ -67,6 +71,32 @@
this.jndiName = jndiName;
}
+ /** Get the class name of the InitialContext implementation to
+ use. Should be one of:
+ javax.naming.InitialContext
+ javax.naming.directory.InitialDirContext
+ javax.naming.ldap.InitialLdapContext
+ @return the classname of the InitialContext to use
+ */
+ public String getInitialContext()
+ {
+ return contextClass.getName();
+ }
+
+ /** Set the class name of the InitialContext implementation to
+ use. Should be one of:
+ javax.naming.InitialContext
+ javax.naming.directory.InitialDirContext
+ javax.naming.ldap.InitialLdapContext
+ The default is javax.naming.InitialContex.
+ @param contextClass, the classname of the InitialContext to use
+ */
+ public void setInitialContext(String className) throws ClassNotFoundException
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ contextClass = loader.loadClass(className);
+ }
+
public void setProperties(String contextPropsURL) throws IOException
{
InputStream is = null;
@@ -118,8 +148,22 @@
public void startService()
throws Exception
{
+ Class[] types = {Hashtable.class};
+ Class[] ldapTypes = {Hashtable.class, Control[].class};
+ Context ctx = null;
+ try
+ {
+ Constructor ctor = contextClass.getConstructor(types);
+ Object[] args = {contextProps};
+ ctx = (Context) ctor.newInstance(args);
+ }
+ catch(NoSuchMethodException e)
+ { // Try the ldap constructor
+ Constructor ctor = contextClass.getConstructor(ldapTypes);
+ Object[] args = {contextProps, null};
+ ctx = (Context) ctor.newInstance(args);
+ }
Context rootCtx = (Context) new InitialContext();
- InitialContext ctx = new InitialContext(contextProps);
log.debug("ctx="+ctx+", env="+ctx.getEnvironment());
// Get the parent context into which we are to bind
Name fullName = rootCtx.getNameParser("").parse(jndiName);
1.2 +21 -2 jboss/src/main/org/jboss/naming/ExternalContextMBean.java
Index: ExternalContextMBean.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/naming/ExternalContextMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExternalContextMBean.java 2001/01/14 01:28:37 1.1
+++ ExternalContextMBean.java 2001/01/17 03:29:17 1.2
@@ -13,7 +13,7 @@
*
*
@author [EMAIL PROTECTED]
-@version $Revision: 1.1 $
+@version $Revision: 1.2 $
*/
public interface ExternalContextMBean extends org.jboss.util.ServiceMBean
{
@@ -22,12 +22,31 @@
// Public --------------------------------------------------------
- /** Set the jndi name under which the external context is bound.
+ /** Get the jndi name under which the external context is bound.
*/
public String getJndiName();
/** Set the jndi name under which the external context is bound.
*/
public void setJndiName(String jndiName);
+
+ /** Get the class name of the InitialContext implementation to
+ use. Should be one of:
+ javax.naming.InitialContext
+ javax.naming.directory.InitialDirContext
+ javax.naming.ldap.InitialLdapContext
+ @return the classname of the InitialContext to use
+ */
+ public String getInitialContext();
+
+ /** Set the class name of the InitialContext implementation to
+ use. Should be one of:
+ javax.naming.InitialContext
+ javax.naming.directory.InitialDirContext
+ javax.naming.ldap.InitialLdapContext
+ The default is javax.naming.InitialContex.
+ @param contextClass, the classname of the InitialContext to use
+ */
+ public void setInitialContext(String contextClass) throws
ClassNotFoundException;
/** Set the jndi.properties information for the external InitialContext.
This is either a URL string or a classpath resource name. Examples: