[jboss-cvs] JBossAS SVN: r60231 - in branches/Branch_4_2: naming/src/main/org and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Feb 3 03:00:43 EST 2007


Author: scott.stark at jboss.org
Date: 2007-02-03 03:00:43 -0500 (Sat, 03 Feb 2007)
New Revision: 60231

Added:
   branches/Branch_4_2/naming/src/main/org/jboss/
   branches/Branch_4_2/naming/src/main/org/jboss/naming/
   branches/Branch_4_2/naming/src/main/org/jboss/naming/BridgeNamingContextFactory.java
   branches/Branch_4_2/naming/src/main/org/jboss/naming/ENCFactory.java
   branches/Branch_4_2/naming/src/main/org/jboss/naming/NamingContextFactory.java
   branches/Branch_4_2/naming/src/main/org/jboss/naming/NonSerializableFactory.java
   branches/Branch_4_2/naming/src/main/org/jboss/naming/Util.java
   branches/Branch_4_2/naming/src/main/org/jnp/server/NamingBean.java
   branches/Branch_4_2/naming/src/main/org/jnp/server/NamingBeanImpl.java
   branches/Branch_4_2/server/src/etc/conf/default/xmdesc/NamingBean-xmbean.xml
Removed:
   branches/Branch_4_2/server/src/main/org/jboss/naming/BridgeNamingContextFactory.java
   branches/Branch_4_2/server/src/main/org/jboss/naming/ENCFactory.java
   branches/Branch_4_2/server/src/main/org/jboss/naming/NamingContextFactory.java
   branches/Branch_4_2/server/src/main/org/jboss/naming/NonSerializableFactory.java
   branches/Branch_4_2/server/src/main/org/jboss/naming/Util.java
Modified:
   branches/Branch_4_2/naming/build.xml
   branches/Branch_4_2/naming/src/main/org/jnp/server/Main.java
   branches/Branch_4_2/naming/src/main/org/jnp/server/MainMBean.java
   branches/Branch_4_2/server/src/etc/conf/default/jboss-service.xml
   branches/Branch_4_2/server/src/etc/conf/default/xmdesc/NamingService-xmbean.xml
   branches/Branch_4_2/server/src/main/org/jboss/naming/NamingService.java
Log:
JBAS-2865, move the basic jndi components to the naming project

Modified: branches/Branch_4_2/naming/build.xml
===================================================================
--- branches/Branch_4_2/naming/build.xml	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/naming/build.xml	2007-02-03 08:00:43 UTC (rev 60231)
@@ -239,6 +239,7 @@
       manifest="${build.etc}/default.mf">
       <fileset dir="${build.classes}">
         <!-- include server classes & interfaces -->
+        <include name="org/jboss/naming/**"/>
         <include name="org/jnp/server/**"/>
         <include name="org/jnp/interfaces/**"/>
       </fileset>

Copied: branches/Branch_4_2/naming/src/main/org/jboss/naming/BridgeNamingContextFactory.java (from rev 60026, branches/Branch_4_2/server/src/main/org/jboss/naming/BridgeNamingContextFactory.java)
===================================================================
--- branches/Branch_4_2/naming/src/main/org/jboss/naming/BridgeNamingContextFactory.java	                        (rev 0)
+++ branches/Branch_4_2/naming/src/main/org/jboss/naming/BridgeNamingContextFactory.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.naming;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Hashtable;
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jnp.interfaces.NamingContextFactory;
+
+/** A naming provider InitialContextFactory implementation that combines
+ two Naming services to allow for delegation of lookups from one to the
+ other. The default naming service is specified via the standard
+ Context.PROVIDER_URL property while the secondary service is specified
+ using an org.jboss.naming.provider.url2 property. An example of where
+ this would be used is to bridge between the local JNDI service and the
+ HAJNDI service. Lookups into the local JNDI service that fail would then
+ try the HAJNDI service.
+
+ @see javax.naming.spi.InitialContextFactory
+ 
+ @author Scott.Stark at jboss.org
+ @version $Revision$
+ */
+public class BridgeNamingContextFactory extends NamingContextFactory
+{
+   // InitialContextFactory implementation --------------------------
+   public Context getInitialContext(Hashtable env)
+      throws NamingException
+   {
+      Context primaryCtx = super.getInitialContext(env);
+      Context bridgeCtx = primaryCtx;
+      Object providerURL2 = env.get("org.jboss.naming.provider.url2");
+      if( providerURL2 != null )
+      {
+         // A second provider url was given, create a secondary naming context
+         Hashtable env2 = (Hashtable) env.clone();
+         env2.put(Context.PROVIDER_URL, providerURL2);
+         Context secondaryCtx = super.getInitialContext(env2);
+         InvocationHandler h = new BridgeContext(primaryCtx, secondaryCtx);
+         Class[] interfaces = {Context.class};
+         ClassLoader loader = Thread.currentThread().getContextClassLoader();
+         bridgeCtx = (Context) Proxy.newProxyInstance(loader, interfaces, h);
+      }
+      return bridgeCtx;
+   }
+
+   /** This class is the Context interface handler and performs the
+       failed lookup delegation from the primary to secondary naming
+       Context.
+   */
+   static class BridgeContext implements InvocationHandler
+   {
+      private Context primaryCtx;
+      private Context secondaryCtx;
+
+      BridgeContext(Context primaryCtx, Context secondaryCtx)
+      {
+         this.primaryCtx = primaryCtx;
+         this.secondaryCtx = secondaryCtx;
+      }
+
+      public Object invoke(Object proxy, Method method, Object[] args)
+            throws Throwable
+      {
+         Object value = null;
+         // First try the primary context
+         try
+         {
+            value = method.invoke(primaryCtx, args);
+         }
+         catch(InvocationTargetException e)
+         {
+            Throwable t = e.getTargetException();
+            // Try the secondary if this is a failed lookup
+            if( t instanceof NameNotFoundException && method.getName().equals("lookup") )
+            {
+               try
+               {
+                  value = method.invoke(secondaryCtx, args);
+               }
+               catch (InvocationTargetException e1)
+               {
+                  throw e1.getTargetException();
+               }
+            }
+            else
+            {
+               throw t;
+            }
+         }
+         return value;
+      }
+   }
+}

Added: branches/Branch_4_2/naming/src/main/org/jboss/naming/ENCFactory.java
===================================================================
--- branches/Branch_4_2/naming/src/main/org/jboss/naming/ENCFactory.java	                        (rev 0)
+++ branches/Branch_4_2/naming/src/main/org/jboss/naming/ENCFactory.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.naming;
+
+import java.util.Hashtable;
+import java.util.WeakHashMap;
+import java.security.PrivilegedAction;
+import java.security.AccessController;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.spi.ObjectFactory;
+
+import org.jnp.server.NamingServer;
+import org.jnp.interfaces.NamingContext;
+
+/**
+ *   Implementation of "java:comp" namespace factory. The context is associated
+ *   with the thread class loader.
+ *     
+ *   @author <a href="mailto:rickard.oberg at telkel.com">Rickard Oberg</a>
+ *   @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
+ *   @version $Revision: 57209 $
+ */
+public class ENCFactory
+   implements ObjectFactory
+{
+   // Constants -----------------------------------------------------
+    
+   // Attributes ----------------------------------------------------
+   private static WeakHashMap encs = new WeakHashMap();
+   private static ClassLoader topLoader;
+
+   // Static --------------------------------------------------------
+   public static void setTopClassLoader(ClassLoader topLoader)
+   {
+      ENCFactory.topLoader = topLoader;
+   }
+   public static ClassLoader getTopClassLoader()
+   {
+      return ENCFactory.topLoader;
+   }
+
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // ObjectFactory implementation ----------------------------------
+   public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+      Hashtable environment)
+      throws Exception
+   {
+      // Get naming for this component
+      ClassLoader ctxClassLoader = GetTCLAction.getContextClassLoader();
+      synchronized (encs)
+      {
+         Context compCtx = (Context) encs.get(ctxClassLoader);
+
+         /* If this is the first time we see ctxClassLoader first check to see
+          if a parent ClassLoader has created an ENC namespace.
+         */
+         if (compCtx == null)
+         {
+            ClassLoader loader = ctxClassLoader;
+            GetParentAction action = new GetParentAction(ctxClassLoader);
+            while( loader != null && loader != topLoader && compCtx == null )
+            {
+               compCtx = (Context) encs.get(loader);
+               loader = action.getParent();
+            }
+            // If we did not find an ENC create it
+            if( compCtx == null )
+            {
+               NamingServer srv = new NamingServer();
+               compCtx = new NamingContext(environment, null, srv);
+               encs.put(ctxClassLoader, compCtx);
+            }
+         }
+         return compCtx;
+      }
+   }
+
+   private static class GetTCLAction implements PrivilegedAction
+   {
+      static PrivilegedAction ACTION = new GetTCLAction();
+      public Object run()
+      {
+         ClassLoader loader = Thread.currentThread().getContextClassLoader();
+         return loader;
+      }
+      static ClassLoader getContextClassLoader()
+      {
+         ClassLoader loader = (ClassLoader) AccessController.doPrivileged(ACTION);
+         return loader;
+      }
+   }
+
+   private static class GetParentAction implements PrivilegedAction
+   {
+      ClassLoader loader;
+      GetParentAction(ClassLoader loader)
+      {
+         this.loader = loader;
+      }
+      public Object run()
+      {
+         ClassLoader parent = null;
+         if( loader != null )
+         {
+            parent = loader.getParent();
+            loader = parent;
+         }
+         return parent;
+      }
+      ClassLoader getParent()
+      {
+         ClassLoader parent = (ClassLoader) AccessController.doPrivileged(this);
+         return parent;
+      }
+   }
+}


Property changes on: branches/Branch_4_2/naming/src/main/org/jboss/naming/ENCFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id,Revision
Name: svn:eol-style
   + native

Copied: branches/Branch_4_2/naming/src/main/org/jboss/naming/NamingContextFactory.java (from rev 60026, branches/Branch_4_2/server/src/main/org/jboss/naming/NamingContextFactory.java)
===================================================================
--- branches/Branch_4_2/naming/src/main/org/jboss/naming/NamingContextFactory.java	                        (rev 0)
+++ branches/Branch_4_2/naming/src/main/org/jboss/naming/NamingContextFactory.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.naming;
+
+import java.util.Hashtable;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+/** A variation of the org.jnp.interfaces.NamingContextFactory
+ * InitialContextFactory implementation that maintains the last envrionment
+ * used to create an InitialContext in a thread local variable for
+ * access within the scope of the InitialContext. This can be used by
+ * the EJB handles to save the context that should be used to perform the
+ * looks when the handle is restored.
+ *
+ * @see org.jnp.interfaces.NamingContextFactory
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class NamingContextFactory extends org.jnp.interfaces.NamingContextFactory
+{
+   public static final ThreadLocal lastInitialContextEnv = new ThreadLocal();
+
+   // InitialContextFactory implementation --------------------------
+   public Context getInitialContext(Hashtable env)
+         throws NamingException
+   {
+      lastInitialContextEnv.set(env);
+      return super.getInitialContext(env);
+   }
+}

Copied: branches/Branch_4_2/naming/src/main/org/jboss/naming/NonSerializableFactory.java (from rev 60026, branches/Branch_4_2/server/src/main/org/jboss/naming/NonSerializableFactory.java)
===================================================================
--- branches/Branch_4_2/naming/src/main/org/jboss/naming/NonSerializableFactory.java	                        (rev 0)
+++ branches/Branch_4_2/naming/src/main/org/jboss/naming/NonSerializableFactory.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.naming;
+
+/**
+ at author <a href="mailto:Scott.Stark at jboss.org">Scott Stark</a>.
+ at version $Revision$
+*/
+public class NonSerializableFactory extends org.jboss.util.naming.NonSerializableFactory
+{
+}

Copied: branches/Branch_4_2/naming/src/main/org/jboss/naming/Util.java (from rev 60026, branches/Branch_4_2/server/src/main/org/jboss/naming/Util.java)
===================================================================
--- branches/Branch_4_2/naming/src/main/org/jboss/naming/Util.java	                        (rev 0)
+++ branches/Branch_4_2/naming/src/main/org/jboss/naming/Util.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.naming;
+
+/** A static utility class for common JNDI operations.
+ *
+ * @author Scott.Stark at jboss.org
+ * @author adrian at jboss.com
+ * @version $Revision$
+ */
+public class Util extends org.jboss.util.naming.Util
+{
+}
\ No newline at end of file

Modified: branches/Branch_4_2/naming/src/main/org/jnp/server/Main.java
===================================================================
--- branches/Branch_4_2/naming/src/main/org/jnp/server/Main.java	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/naming/src/main/org/jnp/server/Main.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -43,7 +43,6 @@
 import org.jboss.util.threadpool.BasicThreadPool;
 import org.jboss.util.threadpool.ThreadPool;
 import org.jnp.interfaces.Naming;
-import org.jnp.interfaces.NamingContext;
 
 /** 
  * A main() entry point for running the jnp naming service implementation as
@@ -59,7 +58,7 @@
    
    // Attributes ----------------------------------------------------
    /** The Naming interface server implementation */
-   protected Naming theServer;
+   protected NamingBean theServer;
    protected MarshalledObject serverStub;
    protected boolean isStubExported;
    /** The jnp server socket through which the NamingServer stub is vended */
@@ -131,10 +130,14 @@
    }
 
    // Public --------------------------------------------------------
-   public Naming getServer()
+   public NamingBean getNamingInfo()
    {
       return theServer;
    }
+   public void setNamingInfo(NamingBean info)
+   {
+      this.theServer = info;
+   }
 
    public ThreadPool getLookupPool()
    {
@@ -240,6 +243,15 @@
       clientSocketFactory = (RMIClientSocketFactory) clazz.newInstance();
    }
    
+   public RMIClientSocketFactory getClientSocketFactoryBean()
+   {
+      return clientSocketFactory;
+   }
+   public void setClientSocketFactoryBean(RMIClientSocketFactory factory)
+   {
+      this.clientSocketFactory = factory;
+   }
+
    public String getServerSocketFactory()
    {
       return serverSocketFactoryName;
@@ -253,6 +265,19 @@
       serverSocketFactory = (RMIServerSocketFactory) clazz.newInstance();
    }
 
+   public RMIServerSocketFactory getServerSocketFactoryBean()
+   {
+      return serverSocketFactory;
+   }
+   public void setServerSocketFactoryBean(RMIServerSocketFactory factory)
+   {
+      this.serverSocketFactory = factory;
+   }
+
+   public String getJNPServerSocketFactory()
+   {
+      return jnpServerSocketFactoryName;
+   }
    public void setJNPServerSocketFactory(String factoryClassName)
       throws ClassNotFoundException, InstantiationException, IllegalAccessException
    {
@@ -262,32 +287,23 @@
       jnpServerSocketFactory = (ServerSocketFactory) clazz.newInstance();
    }
 
+   public ServerSocketFactory getJNPServerSocketFactoryBean()
+   {
+      return jnpServerSocketFactory;
+   }
+   public void setJNPServerSocketFactoryBean(ServerSocketFactory factory)
+   {
+      this.jnpServerSocketFactory = factory;
+   }
+
+   public Naming getNamingInstance()
+   {
+      return theServer.getNamingInstance();
+   }
+
    public void start()
       throws Exception
    {
-      // Create the local naming service instance if it does not exist
-      if( theServer == null )
-      {
-         // See if we should try to reuse the current local server
-         if( UseGlobalService == true )
-            theServer = NamingContext.localServer;
-         // If not, or there is no server create one
-         if( theServer == null )
-            theServer = new NamingServer();
-         else
-         {
-            // We need to wrap the server to allow exporting it
-            NamingServerWrapper wrapper = new NamingServerWrapper(theServer);
-            theServer = wrapper;
-         }
-         log.debug("Using NamingServer: "+theServer);
-         if( InstallGlobalService == true )
-         {
-            // Set local server reference
-            NamingContext.setLocal(theServer);
-            log.debug("Installed global NamingServer: "+theServer);
-         }
-      }
 
       // Initialize the custom socket factories with any bind address
       initCustomSocketFactories();
@@ -295,7 +311,7 @@
         the port is >= 0 and an external proxy has not been installed.
         A value < 0 indicates no socket based access
       */
-      if( this.serverStub == null && this.port >= 0 )
+      if( this.serverStub == null && port >= 0 )
       {
          initJnpInvoker();
       }
@@ -318,7 +334,7 @@
             s.close();
          }
          if( isStubExported == true )
-            UnicastRemoteObject.unexportObject(theServer, false);
+            UnicastRemoteObject.unexportObject(theServer.getNamingInstance(), false);
       }
       catch (Exception e)
       {
@@ -332,10 +348,11 @@
    protected void initJnpInvoker() throws IOException
    {
       log.debug("Creating NamingServer stub, theServer="+theServer
-         +",rmiPort="+rmiPort+",clientSocketFactory="+clientSocketFactory
+         +",rmiPort="+rmiPort
+         +",clientSocketFactory="+clientSocketFactory
          +",serverSocketFactory="+serverSocketFactory);
-      Remote stub = UnicastRemoteObject.exportObject(theServer, rmiPort,
-         clientSocketFactory, serverSocketFactory);
+      Remote stub = UnicastRemoteObject.exportObject(getNamingInstance(),
+            rmiPort, clientSocketFactory, serverSocketFactory);
       log.debug("NamingServer stub: "+stub);
       serverStub = new MarshalledObject(stub);      
    }

Modified: branches/Branch_4_2/naming/src/main/org/jnp/server/MainMBean.java
===================================================================
--- branches/Branch_4_2/naming/src/main/org/jnp/server/MainMBean.java	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/naming/src/main/org/jnp/server/MainMBean.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -22,7 +22,11 @@
 package org.jnp.server;
 
 import java.net.UnknownHostException;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
 
+import javax.net.ServerSocketFactory;
+
 /** 
  * The Mbean interface for the jnp provider server.
  * 
@@ -30,7 +34,7 @@
  * @author Scott.Stark at jboss.org
  * @version $Revision$
  */
-public interface MainMBean
+public interface MainMBean extends NamingBean
 {
    // Attributes  ---------------------------------------------------
    
@@ -73,13 +77,22 @@
    void setClientSocketFactory(String factoryClassName)
       throws ClassNotFoundException, InstantiationException, IllegalAccessException;
    String getClientSocketFactory();
-   
+   /** The RMIClientSocketFactory bean */
+   public RMIClientSocketFactory getClientSocketFactoryBean();
+   public void setClientSocketFactoryBean(RMIClientSocketFactory factory);
+
    /** The RMIServerSocketFactory implementation class */
    void setServerSocketFactory(String factoryClassName)
       throws ClassNotFoundException, InstantiationException, IllegalAccessException;
    String getServerSocketFactory();
+   /** The RMIServerSocketFactory bean */
+   public RMIServerSocketFactory getServerSocketFactoryBean();
+   public void setServerSocketFactoryBean(RMIServerSocketFactory factory);
 
    /** The JNPServerSocketFactory implementation class */
+   ServerSocketFactory getJNPServerSocketFactoryBean();
+   void setJNPServerSocketFactoryBean(ServerSocketFactory factory);
+   public String getJNPServerSocketFactory();
    void setJNPServerSocketFactory(String factoryClassName) 
       throws ClassNotFoundException, InstantiationException, IllegalAccessException;
 

Added: branches/Branch_4_2/naming/src/main/org/jnp/server/NamingBean.java
===================================================================
--- branches/Branch_4_2/naming/src/main/org/jnp/server/NamingBean.java	                        (rev 0)
+++ branches/Branch_4_2/naming/src/main/org/jnp/server/NamingBean.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jnp.server;
+
+import org.jnp.interfaces.Naming;
+
+/**
+ * Interface for the Main naming pojo.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public interface NamingBean
+{
+   public Naming getNamingInstance();
+}


Property changes on: branches/Branch_4_2/naming/src/main/org/jnp/server/NamingBean.java
___________________________________________________________________
Name: svn:keywords
   + Id,Revision
Name: svn:eol-style
   + native

Added: branches/Branch_4_2/naming/src/main/org/jnp/server/NamingBeanImpl.java
===================================================================
--- branches/Branch_4_2/naming/src/main/org/jnp/server/NamingBeanImpl.java	                        (rev 0)
+++ branches/Branch_4_2/naming/src/main/org/jnp/server/NamingBeanImpl.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jnp.server;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+
+import org.jboss.logging.Logger;
+import org.jboss.naming.ENCFactory;
+import org.jnp.interfaces.Naming;
+import org.jnp.interfaces.NamingContext;
+
+/**
+ * A naming pojo that wraps the Naming server implementation. This is
+ * a refactoring of the legacy org.jnp.server.Main into a 
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class NamingBeanImpl
+   implements NamingBean
+{
+   private static Logger log = Logger.getLogger(NamingBeanImpl.class);
+   // Attributes ----------------------------------------------------
+   /** The Naming interface server implementation */
+   protected Naming theServer;
+   /** A flag indicating if theServer will be set as the NamingContext.setLocal value */
+   protected boolean InstallGlobalService = true;
+   /** A flag indicating if theServer will try to use the NamingContext.setLocal value */
+   protected boolean UseGlobalService = true;
+
+   // Static --------------------------------------------------------
+   public static void main(String[] args)
+      throws Exception
+   {
+      new Main().start();
+   }
+ 
+   // Constructors --------------------------------------------------
+   public NamingBeanImpl()
+   {
+   }
+
+   // Public --------------------------------------------------------
+   public Naming getNamingInstance()
+   {
+      return theServer;
+   }
+
+   public boolean getInstallGlobalService()
+   {
+      return InstallGlobalService;
+   }
+   public void setInstallGlobalService(boolean flag)
+   {
+      this.InstallGlobalService = flag;
+   }
+   public boolean getUseGlobalService()
+   {
+      return UseGlobalService;
+   }
+   public void setUseGlobalService(boolean flag)
+   {
+      this.UseGlobalService = flag;
+   }
+
+   public void start()
+      throws Exception
+   {
+      // Create the local naming service instance if it does not exist
+      if( theServer == null )
+      {
+         // See if we should try to reuse the current local server
+         if( UseGlobalService == true )
+            theServer = NamingContext.localServer;
+         // If not, or there is no server create one
+         if( theServer == null )
+            theServer = new NamingServer();
+         else
+         {
+            // We need to wrap the server to allow exporting it
+            NamingServerWrapper wrapper = new NamingServerWrapper(theServer);
+            theServer = wrapper;
+         }
+         log.debug("Using NamingServer: "+theServer);
+         if( InstallGlobalService == true )
+         {
+            // Set local server reference
+            NamingContext.setLocal(theServer);
+            log.debug("Installed global NamingServer: "+theServer);
+         }
+      }
+
+      /* Create a default InitialContext and dump out its env to show what properties
+      were used in its creation. If we find a Context.PROVIDER_URL property
+      issue a warning as this means JNDI lookups are going through RMI.
+      */
+      InitialContext iniCtx = new InitialContext();
+      Hashtable env = iniCtx.getEnvironment();
+      log.debug("InitialContext Environment: ");
+      Object providerURL = null;
+      for (Enumeration keys = env.keys(); keys.hasMoreElements(); )
+      {
+         Object key = keys.nextElement();
+         Object value = env.get(key);
+         String type = value == null ? "" : value.getClass().getName();
+         log.debug("key="+key+", value("+type+")="+value);
+         if( key.equals(Context.PROVIDER_URL) )
+            providerURL = value;
+      }
+      // Warn if there was a Context.PROVIDER_URL
+      if( providerURL != null )
+         log.warn("Context.PROVIDER_URL in server jndi.properties, url="+providerURL);
+   
+      /* Bind an ObjectFactory to "java:comp" so that "java:comp/env" lookups
+         produce a unique context for each thread contexxt ClassLoader that
+         performs the lookup.
+      */
+      ClassLoader topLoader = Thread.currentThread().getContextClassLoader();
+      ENCFactory.setTopClassLoader(topLoader);
+      RefAddr refAddr = new StringRefAddr("nns", "ENC");
+      Reference envRef = new Reference("javax.namingMain.Context", refAddr, ENCFactory.class.getName(), null);
+      Context ctx = (Context)iniCtx.lookup("java:");
+      ctx.rebind("comp", envRef);
+      ctx.close();
+      iniCtx.close();
+
+   }
+
+   public void stop()
+   {
+   }
+
+}


Property changes on: branches/Branch_4_2/naming/src/main/org/jnp/server/NamingBeanImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id,Revision
Name: svn:eol-style
   + native

Modified: branches/Branch_4_2/server/src/etc/conf/default/jboss-service.xml
===================================================================
--- branches/Branch_4_2/server/src/etc/conf/default/jboss-service.xml	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/server/src/etc/conf/default/jboss-service.xml	2007-02-03 08:00:43 UTC (rev 60231)
@@ -221,31 +221,46 @@
    <!-- JNDI                                                                 -->
    <!-- ==================================================================== -->
 
+   <!-- A simple mbean wrapper around the jndi Naming object. This
+   only handles an in memory instance. The NamingService uses this
+   as the JNDI store and exposes it remotely.
+   -->
+   <mbean code="org.jnp.server.NamingBeanImpl"
+      name="jboss:service=NamingBeanImpl"
+      xmbean-dd="resource:xmdesc/NamingBean-xmbean.xml">
+   </mbean>
+   
    <mbean code="org.jboss.naming.NamingService"
       name="jboss:service=Naming"
       xmbean-dd="resource:xmdesc/NamingService-xmbean.xml">
       <!-- The call by value mode. true if all lookups are unmarshalled using
-      the caller's TCL, false if in VM lookups return the value by reference.
+         the caller's TCL, false if in VM lookups return the value by reference.
       -->
       <attribute name="CallByValue">false</attribute>
       <!-- The listening port for the bootstrap JNP service. Set this to -1
-        to run the NamingService without the JNP invoker listening port.
+         to run the NamingService without the JNP invoker listening port.
       -->
       <attribute name="Port">1099</attribute>
       <!-- The bootstrap JNP server bind address. This also sets the default
-      RMI service bind address. Empty == all addresses
-       -->
+         RMI service bind address. Empty == all addresses
+      -->
       <attribute name="BindAddress">${jboss.bind.address}</attribute>
       <!-- The port of the RMI naming service, 0 == anonymous -->
       <attribute name="RmiPort">1098</attribute>
       <!-- The RMI service bind address. Empty == all addresses
-       -->
+      -->
       <attribute name="RmiBindAddress">${jboss.bind.address}</attribute>
       <!-- The thread pool service used to control the bootstrap lookups -->
       <depends optional-attribute-name="LookupPool"
          proxy-type="attribute">jboss.system:service=ThreadPool</depends>
+      <!-- An example of using the unifed invoker as the transport.
+         <depends optional-attribute-name="InvokerProxyFactory"
+         proxy-type="attribute">jboss:service=proxyFactory,type=unified,target=Naming</depends>
+      -->
+      <depends optional-attribute-name="Naming"
+         proxy-type="attribute">jboss:service=NamingBeanImpl</depends>
    </mbean>
-
+   
    <mbean code="org.jboss.naming.JNDIView"
    	name="jboss:service=JNDIView"
    	xmbean-dd="resource:xmdesc/JNDIView-xmbean.xml">

Added: branches/Branch_4_2/server/src/etc/conf/default/xmdesc/NamingBean-xmbean.xml
===================================================================
--- branches/Branch_4_2/server/src/etc/conf/default/xmdesc/NamingBean-xmbean.xml	                        (rev 0)
+++ branches/Branch_4_2/server/src/etc/conf/default/xmdesc/NamingBean-xmbean.xml	2007-02-03 08:00:43 UTC (rev 60231)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mbean PUBLIC
+   "-//JBoss//DTD JBOSS XMBEAN 1.1//EN"
+   "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_1.dtd">
+
+<!-- The JNDI Naming XMBean
+   $Id: NamingService-xmbean.xml 57220 2006-09-26 23:13:40Z scott.stark at jboss.org $
+-->
+<mbean>
+   <description>The JNDI pojo bean</description>
+
+   <class>org.jnp.server.NamingBeanImpl</class>
+   
+   <constructor>
+       <description>The default constructor</description>
+       <name>NamingBeanImpl</name>
+   </constructor>
+   
+   <attribute access="read-only" getMethod="getNamingInstance">
+       <description>The NamingInstance</description>
+       <name>NamingInstance</name>
+       <type>org.jnp.interfaces.Naming</type>
+   </attribute>
+   
+   <!-- Operations -->
+   <operation>
+       <description>The start lifecycle op</description>
+       <name>start</name>
+       <return-type>void</return-type>
+   </operation>
+   <operation>
+       <description>The stop lifecycle op</description>
+       <name>stop</name>
+       <return-type>void</return-type>
+   </operation>
+   
+</mbean>


Property changes on: branches/Branch_4_2/server/src/etc/conf/default/xmdesc/NamingBean-xmbean.xml
___________________________________________________________________
Name: svn:keywords
   + Id,Revision
Name: svn:eol-style
   + native

Modified: branches/Branch_4_2/server/src/etc/conf/default/xmdesc/NamingService-xmbean.xml
===================================================================
--- branches/Branch_4_2/server/src/etc/conf/default/xmdesc/NamingService-xmbean.xml	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/server/src/etc/conf/default/xmdesc/NamingService-xmbean.xml	2007-02-03 08:00:43 UTC (rev 60231)
@@ -41,6 +41,16 @@
       <name>MethodMap</name>
       <type>java.util.Map</type>
    </attribute>
+   <attribute access="read-write" getMethod="getNaming" setMethod="setNaming">
+      <description>Underlying Naming bean instance</description>
+      <name>Naming</name>
+      <type>org.jnp.server.NamingBean</type>
+   </attribute>
+   <attribute access="read-only" getMethod="getNamingInstance">
+      <description>Underlying Naming bean instance</description>
+      <name>NamingInstance</name>
+      <type>org.jnp.interfaces.Naming</type>
+   </attribute>   
    <attribute access="read-write" getMethod="getCallByValue" setMethod="setCallByValue">
       <description>The call by value mode. true if all lookups are unmarshalled using
       the caller's TCL, false if in VM lookups return the value by reference.</description>
@@ -65,10 +75,16 @@
    </attribute>
    <attribute access="read-write" getMethod="getJNPServerSocketFactory"
       setMethod="setJNPServerSocketFactory">
-      <description>The bootstrap socket javax.net.ServerSocketFactory</description>
+      <description>The bootstrap socket javax.net.ServerSocketFactory class name</description>
       <name>JNPServerSocketFactory</name>
       <type>java.lang.String</type>
    </attribute>
+   <attribute access="read-write" getMethod="getJNPServerSocketFactoryBean"
+      setMethod="setJNPServerSocketFactoryBean">
+      <description>The bootstrap socket javax.net.ServerSocketFactory</description>
+      <name>JNPServerSocketFactoryBean</name>
+      <type>javax.net.ServerSocketFactory</type>
+   </attribute>
 
    <attribute access="read-write" getMethod="getRmiPort" setMethod="setRmiPort">
       <description>The port of the RMI naming service, 0 == anonymous. This
@@ -82,15 +98,25 @@
       <type>java.lang.String</type>
    </attribute>
    <attribute access="read-write" getMethod="getClientSocketFactory" setMethod="setClientSocketFactory">
-      <description>The RMI service java.rmi.server.RMIClientSocketFactory</description>
+      <description>The RMI service java.rmi.server.RMIClientSocketFactory class name</description>
       <name>ClientSocketFactory</name>
       <type>java.lang.String</type>
    </attribute>
+   <attribute access="read-write" getMethod="getClientSocketFactoryBean" setMethod="setClientSocketFactoryBean">
+      <description>The RMI service java.rmi.server.RMIServerSocketFactory instance</description>
+      <name>ClientSocketFactoryBean</name>
+      <type>java.rmi.server.RMIClientSocketFactory</type>
+   </attribute>
    <attribute access="read-write" getMethod="getServerSocketFactory" setMethod="setServerSocketFactory">
-      <description>The RMI service java.rmi.server.RMIServerSocketFactory</description>
+      <description>The RMI service java.rmi.server.RMIServerSocketFactory class name</description>
       <name>ServerSocketFactory</name>
       <type>java.lang.String</type>
    </attribute>
+   <attribute access="read-write" getMethod="getServerSocketFactoryBean" setMethod="setServerSocketFactoryBean">
+      <description>The RMI service java.rmi.server.RMIServerSocketFactory instance</description>
+      <name>ServerSocketFactory</name>
+      <type>java.rmi.server.RMIServerSocketFactory</type>
+   </attribute>
 
    <attribute access="read-write" getMethod="getInstallGlobalService"
       setMethod="setInstallGlobalService">

Deleted: branches/Branch_4_2/server/src/main/org/jboss/naming/BridgeNamingContextFactory.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/naming/BridgeNamingContextFactory.java	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/server/src/main/org/jboss/naming/BridgeNamingContextFactory.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -1,119 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.naming;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Hashtable;
-import javax.naming.Context;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.jnp.interfaces.NamingContextFactory;
-
-/** A naming provider InitialContextFactory implementation that combines
- two Naming services to allow for delegation of lookups from one to the
- other. The default naming service is specified via the standard
- Context.PROVIDER_URL property while the secondary service is specified
- using an org.jboss.naming.provider.url2 property. An example of where
- this would be used is to bridge between the local JNDI service and the
- HAJNDI service. Lookups into the local JNDI service that fail would then
- try the HAJNDI service.
-
- @see javax.naming.spi.InitialContextFactory
- 
- @author Scott.Stark at jboss.org
- @version $Revision$
- */
-public class BridgeNamingContextFactory extends NamingContextFactory
-{
-   // InitialContextFactory implementation --------------------------
-   public Context getInitialContext(Hashtable env)
-      throws NamingException
-   {
-      Context primaryCtx = super.getInitialContext(env);
-      Context bridgeCtx = primaryCtx;
-      Object providerURL2 = env.get("org.jboss.naming.provider.url2");
-      if( providerURL2 != null )
-      {
-         // A second provider url was given, create a secondary naming context
-         Hashtable env2 = (Hashtable) env.clone();
-         env2.put(Context.PROVIDER_URL, providerURL2);
-         Context secondaryCtx = super.getInitialContext(env2);
-         InvocationHandler h = new BridgeContext(primaryCtx, secondaryCtx);
-         Class[] interfaces = {Context.class};
-         ClassLoader loader = Thread.currentThread().getContextClassLoader();
-         bridgeCtx = (Context) Proxy.newProxyInstance(loader, interfaces, h);
-      }
-      return bridgeCtx;
-   }
-
-   /** This class is the Context interface handler and performs the
-       failed lookup delegation from the primary to secondary naming
-       Context.
-   */
-   static class BridgeContext implements InvocationHandler
-   {
-      private Context primaryCtx;
-      private Context secondaryCtx;
-
-      BridgeContext(Context primaryCtx, Context secondaryCtx)
-      {
-         this.primaryCtx = primaryCtx;
-         this.secondaryCtx = secondaryCtx;
-      }
-
-      public Object invoke(Object proxy, Method method, Object[] args)
-            throws Throwable
-      {
-         Object value = null;
-         // First try the primary context
-         try
-         {
-            value = method.invoke(primaryCtx, args);
-         }
-         catch(InvocationTargetException e)
-         {
-            Throwable t = e.getTargetException();
-            // Try the secondary if this is a failed lookup
-            if( t instanceof NameNotFoundException && method.getName().equals("lookup") )
-            {
-               try
-               {
-                  value = method.invoke(secondaryCtx, args);
-               }
-               catch (InvocationTargetException e1)
-               {
-                  throw e1.getTargetException();
-               }
-            }
-            else
-            {
-               throw t;
-            }
-         }
-         return value;
-      }
-   }
-}

Deleted: branches/Branch_4_2/server/src/main/org/jboss/naming/ENCFactory.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/naming/ENCFactory.java	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/server/src/main/org/jboss/naming/ENCFactory.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -1,140 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.naming;
-
-import java.util.Hashtable;
-import java.util.WeakHashMap;
-import java.security.PrivilegedAction;
-import java.security.AccessController;
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.spi.ObjectFactory;
-
-import org.jnp.server.NamingServer;
-import org.jnp.interfaces.NamingContext;
-
-/**
- *   Implementation of "java:comp" namespace factory. The context is associated
- *   with the thread class loader.
- *     
- *   @author <a href="mailto:rickard.oberg at telkel.com">Rickard Oberg</a>
- *   @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
- *   @version $Revision$
- */
-public class ENCFactory
-   implements ObjectFactory
-{
-   // Constants -----------------------------------------------------
-    
-   // Attributes ----------------------------------------------------
-   private static WeakHashMap encs = new WeakHashMap();
-   private static ClassLoader topLoader;
-
-   // Static --------------------------------------------------------
-   public static void setTopClassLoader(ClassLoader topLoader)
-   {
-      ENCFactory.topLoader = topLoader;
-   }
-   public static ClassLoader getTopClassLoader()
-   {
-      return ENCFactory.topLoader;
-   }
-
-
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   // ObjectFactory implementation ----------------------------------
-   public Object getObjectInstance(Object obj, Name name, Context nameCtx,
-      Hashtable environment)
-      throws Exception
-   {
-      // Get naming for this component
-      ClassLoader ctxClassLoader = GetTCLAction.getContextClassLoader();
-      synchronized (encs)
-      {
-         Context compCtx = (Context) encs.get(ctxClassLoader);
-
-         /* If this is the first time we see ctxClassLoader first check to see
-          if a parent ClassLoader has created an ENC namespace.
-         */
-         if (compCtx == null)
-         {
-            ClassLoader loader = ctxClassLoader;
-            GetParentAction action = new GetParentAction(ctxClassLoader);
-            while( loader != null && loader != topLoader && compCtx == null )
-            {
-               compCtx = (Context) encs.get(loader);
-               loader = action.getParent();
-            }
-            // If we did not find an ENC create it
-            if( compCtx == null )
-            {
-               NamingServer srv = new NamingServer();
-               compCtx = new NamingContext(environment, null, srv);
-               encs.put(ctxClassLoader, compCtx);
-            }
-         }
-         return compCtx;
-      }
-   }
-
-   private static class GetTCLAction implements PrivilegedAction
-   {
-      static PrivilegedAction ACTION = new GetTCLAction();
-      public Object run()
-      {
-         ClassLoader loader = Thread.currentThread().getContextClassLoader();
-         return loader;
-      }
-      static ClassLoader getContextClassLoader()
-      {
-         ClassLoader loader = (ClassLoader) AccessController.doPrivileged(ACTION);
-         return loader;
-      }
-   }
-
-   private static class GetParentAction implements PrivilegedAction
-   {
-      ClassLoader loader;
-      GetParentAction(ClassLoader loader)
-      {
-         this.loader = loader;
-      }
-      public Object run()
-      {
-         ClassLoader parent = null;
-         if( loader != null )
-         {
-            parent = loader.getParent();
-            loader = parent;
-         }
-         return parent;
-      }
-      ClassLoader getParent()
-      {
-         ClassLoader parent = (ClassLoader) AccessController.doPrivileged(this);
-         return parent;
-      }
-   }
-}

Deleted: branches/Branch_4_2/server/src/main/org/jboss/naming/NamingContextFactory.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/naming/NamingContextFactory.java	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/server/src/main/org/jboss/naming/NamingContextFactory.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -1,51 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.naming;
-
-import java.util.Hashtable;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-/** A variation of the org.jnp.interfaces.NamingContextFactory
- * InitialContextFactory implementation that maintains the last envrionment
- * used to create an InitialContext in a thread local variable for
- * access within the scope of the InitialContext. This can be used by
- * the EJB handles to save the context that should be used to perform the
- * looks when the handle is restored.
- *
- * @see org.jnp.interfaces.NamingContextFactory
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class NamingContextFactory extends org.jnp.interfaces.NamingContextFactory
-{
-   public static final ThreadLocal lastInitialContextEnv = new ThreadLocal();
-
-   // InitialContextFactory implementation --------------------------
-   public Context getInitialContext(Hashtable env)
-         throws NamingException
-   {
-      lastInitialContextEnv.set(env);
-      return super.getInitialContext(env);
-   }
-}

Modified: branches/Branch_4_2/server/src/main/org/jboss/naming/NamingService.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/naming/NamingService.java	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/server/src/main/org/jboss/naming/NamingService.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -26,6 +26,8 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.UndeclaredThrowableException;
 import java.net.UnknownHostException;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -37,6 +39,7 @@
 import javax.naming.RefAddr;
 import javax.naming.Reference;
 import javax.naming.StringRefAddr;
+import javax.net.ServerSocketFactory;
 
 import org.jboss.invocation.Invocation;
 import org.jboss.invocation.MarshalledInvocation;
@@ -47,6 +50,7 @@
 import org.jnp.interfaces.Naming;
 import org.jnp.interfaces.MarshalledValuePair;
 import org.jnp.server.Main;
+import org.jnp.server.NamingBean;
 
 /**
  * A JBoss service that starts the jnp JNDI server.
@@ -63,8 +67,10 @@
    extends ServiceMBeanSupport
    implements NamingServiceMBean
 {
-   /** The actual naming service impl from the legacy jndi service */
-   private Main naming;
+   /** The actual namingMain service impl bean */
+   private NamingBean namingBean;
+   /** */
+   private Main namingMain = new Main();
    /** The hash mappings of the Naming interface methods */
    private Map marshalledInvocationMapping = new HashMap();
    /** An optional proxy factory for externalizing the Naming proxy transport */
@@ -72,9 +78,23 @@
 
    public NamingService()
    {
-      naming = new Main(this.getClass().getName());
    }
 
+   public NamingBean getNaming()
+   {
+      return namingBean;
+   }
+   public void setNaming(NamingBean bean)
+   {
+      this.namingBean = bean;
+      this.namingMain.setNamingInfo(bean);
+   }
+
+   public Naming getNamingInstance()
+   {
+      return namingBean.getNamingInstance();
+   }
+
    /** Set the thread pool used for the bootstrap lookups
     *
     * @jmx:managed-attribute
@@ -84,7 +104,7 @@
    public void setLookupPool(BasicThreadPoolMBean poolMBean)
    {
       ThreadPool lookupPool = poolMBean.getInstance();
-      naming.setLookupPool(lookupPool);
+      namingMain.setLookupPool(lookupPool);
    }
 
    /** Get the call by value flag for jndi lookups.
@@ -111,97 +131,124 @@
 
    public void setPort(int port)
    {
-      naming.setPort(port);
+      namingMain.setPort(port);
    }
 
    public int getPort()
    {
-      return naming.getPort();
+      return namingMain.getPort();
    }
 
    public void setRmiPort(int port)
    {
-      naming.setRmiPort(port);
+      namingMain.setRmiPort(port);
    }
 
    public int getRmiPort()
    {
-      return naming.getRmiPort();
+      return namingMain.getRmiPort();
    }
 
    public String getBindAddress()
    {
-      return naming.getBindAddress();
+      return namingMain.getBindAddress();
    }
 
    public void setBindAddress(String host) throws UnknownHostException
    {
-      naming.setBindAddress(host);
+      namingMain.setBindAddress(host);
    }
 
    public String getRmiBindAddress()
    {
-      return naming.getRmiBindAddress();
+      return namingMain.getRmiBindAddress();
    }
 
    public void setRmiBindAddress(String host) throws UnknownHostException
    {
-      naming.setRmiBindAddress(host);
+      namingMain.setRmiBindAddress(host);
    }
 
    public int getBacklog()
    {
-      return naming.getBacklog();
+      return namingMain.getBacklog();
    }
 
    public void setBacklog(int backlog)
    {
-      naming.setBacklog(backlog);
+      namingMain.setBacklog(backlog);
    }
 
    public boolean getInstallGlobalService()
    {
-      return naming.getInstallGlobalService();
+      return namingMain.getInstallGlobalService();
    }
    public void setInstallGlobalService(boolean flag)
    {
-      naming.setInstallGlobalService(flag);
+      namingMain.setInstallGlobalService(flag);
    }
    public boolean getUseGlobalService()
    {
-      return naming.getUseGlobalService();
+      return namingMain.getUseGlobalService();
    }
    public void setUseGlobalService(boolean flag)
    {
-      naming.setUseGlobalService(flag);
+      namingMain.setUseGlobalService(flag);
    }
    public String getClientSocketFactory()
    {
-      return naming.getClientSocketFactory();
+      return namingMain.getClientSocketFactory();
    }
-
    public void setClientSocketFactory(String factoryClassName)
       throws ClassNotFoundException, InstantiationException, IllegalAccessException
    {
-      naming.setClientSocketFactory(factoryClassName);
+      namingMain.setClientSocketFactory(factoryClassName);
    }
 
+   public RMIClientSocketFactory getClientSocketFactoryBean()
+   {
+      return namingMain.getClientSocketFactoryBean();
+   }
+   public void setClientSocketFactoryBean(RMIClientSocketFactory factory)
+   {
+      namingMain.setClientSocketFactoryBean(factory);
+   }
+
    public String getServerSocketFactory()
    {
-      return naming.getServerSocketFactory();
+      return namingMain.getServerSocketFactory();
    }
-
    public void setServerSocketFactory(String factoryClassName)
       throws ClassNotFoundException, InstantiationException, IllegalAccessException
    {
-      naming.setServerSocketFactory(factoryClassName);
+      namingMain.setServerSocketFactory(factoryClassName);
    }
+   public RMIServerSocketFactory getServerSocketFactoryBean()
+   {
+      return namingMain.getServerSocketFactoryBean();
+   }
+   public void setServerSocketFactoryBean(RMIServerSocketFactory factory)
+   {
+      namingMain.setServerSocketFactoryBean(factory);      
+   }
 
+   public String getJNPServerSocketFactory()
+   {
+      return namingMain.getJNPServerSocketFactory();
+   }
    public void setJNPServerSocketFactory(String factoryClassName)
       throws ClassNotFoundException, InstantiationException, IllegalAccessException
    {
-      naming.setJNPServerSocketFactory(factoryClassName);
+      namingMain.setJNPServerSocketFactory(factoryClassName);
    }
+   public ServerSocketFactory getJNPServerSocketFactoryBean()
+   {
+      return namingMain.getJNPServerSocketFactoryBean();
+   }
+   public void setJNPServerSocketFactoryBean(ServerSocketFactory factory)
+   {
+      namingMain.setJNPServerSocketFactoryBean(factory);
+   }
 
    public void setInvokerProxyFactory(JRMPProxyFactoryMBean proxyFactory)
    {
@@ -239,44 +286,9 @@
          System.setProperty(key, value);
       }
       if( proxyFactory != null )
-         naming.setNamingProxy(proxyFactory.getProxy());
-      naming.start();
+         namingMain.setNamingProxy(proxyFactory.getProxy());
+      namingMain.start();
 
-      /* Create a default InitialContext and dump out its env to show what properties
-         were used in its creation. If we find a Context.PROVIDER_URL property
-         issue a warning as this means JNDI lookups are going through RMI.
-      */
-      InitialContext iniCtx = new InitialContext();
-      Hashtable env = iniCtx.getEnvironment();
-      log.debug("InitialContext Environment: ");
-      Object providerURL = null;
-      for (Enumeration keys = env.keys(); keys.hasMoreElements(); )
-      {
-         Object key = keys.nextElement();
-         Object value = env.get(key);
-         String type = value == null ? "" : value.getClass().getName();
-         log.debug("key="+key+", value("+type+")="+value);
-         if( key.equals(Context.PROVIDER_URL) )
-            providerURL = value;
-      }
-      // Warn if there was a Context.PROVIDER_URL
-      if( providerURL != null )
-         log.warn("Context.PROVIDER_URL in server jndi.properties, url="+providerURL);
-
-      /* Bind an ObjectFactory to "java:comp" so that "java:comp/env" lookups
-         produce a unique context for each thread contexxt ClassLoader that
-         performs the lookup.
-      */
-      ClassLoader topLoader = Thread.currentThread().getContextClassLoader();
-      ENCFactory.setTopClassLoader(topLoader);
-      RefAddr refAddr = new StringRefAddr("nns", "ENC");
-      Reference envRef = new Reference("javax.naming.Context", refAddr, ENCFactory.class.getName(), null);
-      Context ctx = (Context)iniCtx.lookup("java:");
-      ctx.rebind("comp", envRef);
-      log.debug("Listening on port "+naming.getPort());
-      ctx.close();
-      iniCtx.close();
-
       // Build the Naming interface method map
       HashMap tmpMap = new HashMap(13);
       Method[] methods = Naming.class.getMethods();
@@ -292,7 +304,7 @@
    protected void stopService()
       throws Exception
    {
-      naming.stop();
+      namingMain.stop();
       log.debug("JNP server stopped");
    }
 
@@ -307,7 +319,7 @@
     */
    protected Main getNamingServer()
    {
-      return naming;
+      return namingMain;
    } // end of main()
 
 
@@ -345,7 +357,7 @@
     */
    public Object invoke(Invocation invocation) throws Exception
    {
-      Naming theServer = naming.getServer();
+      Naming theServer = namingMain.getNamingInstance();
       // Set the method hash to Method mapping
       if (invocation instanceof MarshalledInvocation)
       {

Deleted: branches/Branch_4_2/server/src/main/org/jboss/naming/NonSerializableFactory.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/naming/NonSerializableFactory.java	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/server/src/main/org/jboss/naming/NonSerializableFactory.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -1,30 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.naming;
-
-/**
- at author <a href="mailto:Scott.Stark at jboss.org">Scott Stark</a>.
- at version $Revision$
-*/
-public class NonSerializableFactory extends org.jboss.util.naming.NonSerializableFactory
-{
-}

Deleted: branches/Branch_4_2/server/src/main/org/jboss/naming/Util.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/naming/Util.java	2007-02-03 02:32:59 UTC (rev 60230)
+++ branches/Branch_4_2/server/src/main/org/jboss/naming/Util.java	2007-02-03 08:00:43 UTC (rev 60231)
@@ -1,32 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.naming;
-
-/** A static utility class for common JNDI operations.
- *
- * @author Scott.Stark at jboss.org
- * @author adrian at jboss.com
- * @version $Revision$
- */
-public class Util extends org.jboss.util.naming.Util
-{
-}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list