geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r125889 - in geronimo/trunk/modules: assembly/src/plan client/src/java/org/apache/geronimo/client connector-builder/src/java/org/apache/geronimo/connector/deployment jetty/src/java/org/apache/geronimo/jetty kernel/src/java/org/apache/geronimo/kernel naming-builder/src/java/org/apache/geronimo/naming/deployment naming-builder/src/schema naming/src/java/org/apache/geronimo/naming/java naming/src/java/org/apache/geronimo/naming/reference naming/src/test/org/apache/geronimo/naming/java
Date Fri, 21 Jan 2005 04:39:30 GMT
Author: dain
Date: Thu Jan 20 20:39:28 2005
New Revision: 125889

URL: http://svn.apache.org/viewcvs?view=rev&rev=125889
Log:
Added kernel and class loader aware references to naming.  These reference will have the kernel
and/or class loader injected on startup.
Added SimpleReference which has a faster getContent() if the Context implementation supports
it. Otherwise, it supports the normal slow refernce code.
Started to add support for accessing gbean referenced via JNDI.

Added:
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/ClassLoaderAwareReference.java
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/GBeanProxyReference.java
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/KernelAwareReference.java
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/KernelReference.java
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/ResourceReference.java
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/SimpleAwareReference.java
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/SimpleReference.java
Removed:
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/GBeanGetResourceRefAddr.java
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/GBeanRefAddr.java
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/RefAddrContentObjectFactory.java
Modified:
   geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml
   geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java
   geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientPlugin.java
   geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/StaticJndiContextPlugin.java
   geronimo/trunk/modules/connector-builder/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
   geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
   geronimo/trunk/modules/naming-builder/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java
   geronimo/trunk/modules/naming-builder/src/schema/geronimo-naming.xsd
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java
   geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java
   geronimo/trunk/modules/naming/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java

Modified: geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml?view=diff&rev=125889&p1=geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml&r1=125888&p2=geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml&r2=125889
==============================================================================
--- geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml	(original)
+++ geronimo/trunk/modules/assembly/src/plan/j2ee-client-plan.xml	Thu Jan 20 20:39:28 2005
@@ -71,11 +71,6 @@
         <uri>geronimo/jars/geronimo-j2ee-${geronimo_version}.jar</uri>
     </dependency>
 
-<!--    <gbean name="geronimo.client:type=JNDIContext" class="org.openejb.client.AppClientJNDIContext">-->
-<!--        <attribute name="host" type="java.lang.String">localhost</attribute>-->
-<!--        <attribute name="port" type="int">4201</attribute>-->
-<!--    </gbean>-->
-
     <!--client connector support-->
     <gbean namePart="DefaultThreadPool" class="org.apache.geronimo.pool.ThreadPool">
         <attribute name="keepAliveTime" type="long">5000</attribute>

Modified: geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java?view=diff&rev=125889&p1=geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java&r1=125888&p2=geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java&r2=125889
==============================================================================
--- geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java
(original)
+++ geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java
Thu Jan 20 20:39:28 2005
@@ -71,7 +71,7 @@
         TransactionContext oldTransactionContext = transactionContextManager.getContext();
         TransactionContext currentTransactionContext = null;
         try {
-            jndiContext.startClient(appClientModuleName);
+            jndiContext.startClient(appClientModuleName, null, classLoader);
             currentTransactionContext = transactionContextManager.newUnspecifiedTransactionContext();
             mainMethod.invoke(null, new Object[]{args});
 

Modified: geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientPlugin.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientPlugin.java?view=diff&rev=125889&p1=geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientPlugin.java&r1=125888&p2=geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientPlugin.java&r2=125889
==============================================================================
--- geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientPlugin.java
(original)
+++ geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientPlugin.java
Thu Jan 20 20:39:28 2005
@@ -18,11 +18,13 @@
 
 import javax.management.ObjectName;
 
+import org.apache.geronimo.kernel.Kernel;
+
 /**
  * @version $Revision$ $Date$
  */
 public interface AppClientPlugin {
-    public void startClient(ObjectName appClientModuleName) throws Exception;
+    public void startClient(ObjectName appClientModuleName, Kernel kernel, ClassLoader classLoader)
throws Exception;
 
     public void stopClient(ObjectName appClientModuleName) throws Exception;
 

Modified: geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/StaticJndiContextPlugin.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/StaticJndiContextPlugin.java?view=diff&rev=125889&p1=geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/StaticJndiContextPlugin.java&r1=125888&p2=geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/StaticJndiContextPlugin.java&r2=125889
==============================================================================
--- geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/StaticJndiContextPlugin.java
(original)
+++ geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/StaticJndiContextPlugin.java
Thu Jan 20 20:39:28 2005
@@ -23,6 +23,7 @@
 import org.apache.geronimo.naming.java.RootContext;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.kernel.Kernel;
 
 /**
  * @version $Rev$ $Date$
@@ -34,7 +35,9 @@
         this.context = context;
     }
 
-    public void startClient(ObjectName appClientModuleName) throws Exception {
+    public void startClient(ObjectName appClientModuleName, Kernel kernel, ClassLoader classLoader)
throws Exception {
+        context.setKernel(kernel);
+        context.setClassLoader(classLoader);
         RootContext.setComponentContext(context);
         System.setProperty("java.naming.factory.initial", "com.sun.jndi.rmi.registry.RegistryContextFactory");
         System.setProperty("java.naming.factory.url.pkgs", "org.apache.geronimo.naming");

Modified: geronimo/trunk/modules/connector-builder/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/connector-builder/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java?view=diff&rev=125889&p1=geronimo/trunk/modules/connector-builder/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java&r1=125888&p2=geronimo/trunk/modules/connector-builder/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java&r2=125889
==============================================================================
--- geronimo/trunk/modules/connector-builder/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
(original)
+++ geronimo/trunk/modules/connector-builder/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
Thu Jan 20 20:39:28 2005
@@ -74,8 +74,7 @@
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.repository.Repository;
-import org.apache.geronimo.naming.reference.GBeanGetResourceRefAddr;
-import org.apache.geronimo.naming.reference.RefAddrContentObjectFactory;
+import org.apache.geronimo.naming.reference.ResourceReference;
 import org.apache.geronimo.naming.deployment.ENCConfigBuilder;
 import org.apache.geronimo.schema.SchemaConversionUtils;
 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType;
@@ -775,15 +774,11 @@
 
     //ResourceReferenceBuilder implementation
     public Reference createResourceRef(String containerId, Class iface) throws DeploymentException
{
-        Reference ref = new Reference(null, RefAddrContentObjectFactory.class.getName(),
null);
-        ref.add(new GBeanGetResourceRefAddr(null, containerId, iface));
-        return ref;
+        return new ResourceReference(containerId, iface);
     }
 
     public Reference createAdminObjectRef(String containerId, Class iface) throws DeploymentException
{
-        Reference ref = new Reference(null, RefAddrContentObjectFactory.class.getName(),
null);
-        ref.add(new GBeanGetResourceRefAddr(null, containerId, iface));
-        return ref;
+        return new ResourceReference(containerId, iface);
     }
 
     public ObjectName locateResourceName(ObjectName query) throws DeploymentException {

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java?view=diff&rev=125889&p1=geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java&r1=125888&p2=geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java&r2=125889
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
Thu Jan 20 20:39:28 2005
@@ -56,7 +56,7 @@
 import org.apache.geronimo.transaction.TrackedConnectionAssociator;
 import org.apache.geronimo.transaction.context.TransactionContextManager;
 import org.apache.geronimo.security.deploy.Security;
-
+import org.apache.geronimo.kernel.Kernel;
 
 /**
  * Wrapper for a WebApplicationContext that sets up its J2EE environment.
@@ -124,7 +124,8 @@
 
                                   TransactionContextManager transactionContextManager,
                                   TrackedConnectionAssociator trackedConnectionAssociator,
-                                  JettyContainer jettyContainer) throws Exception, IllegalAccessException,
InstantiationException, ClassNotFoundException {
+                                  JettyContainer jettyContainer,
+                                  Kernel kernel) throws Exception, IllegalAccessException,
InstantiationException, ClassNotFoundException {
 
         assert uri != null;
         assert componentContext != null;
@@ -171,6 +172,10 @@
         setTagLibMap(tagLibMap);
         setSessionTimeoutSeconds(sessionTimeoutSeconds);
 
+        if (componentContext != null) {
+            componentContext.setKernel(kernel);
+            componentContext.setClassLoader(classLoader);
+        }
 
         int index = 0;
         BeforeAfter interceptor = new InstanceContextBeforeAfter(null, index++, unshareableResources,
applicationManagedSecurityResources, trackedConnectionAssociator);
@@ -363,7 +368,7 @@
 
 
     public static final GBeanInfo GBEAN_INFO;
-
+                                                              
     static {
         GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder("Jetty WebApplication Context",
JettyWebAppContext.class);
         //from jetty's webapp context
@@ -410,6 +415,8 @@
         infoBuilder.addAttribute("excludedPermissions", PermissionCollection.class, true);
         infoBuilder.addAttribute("rolePermissions", Map.class, true);
 
+        infoBuilder.addAttribute("kernel", Kernel.class, false);
+
         infoBuilder.setConstructor(new String[]{
             "uri",
             "componentContext",
@@ -445,7 +452,9 @@
 
             "TransactionContextManager",
             "TrackedConnectionAssociator",
-            "JettyContainer"
+            "JettyContainer",
+
+            "kernel"
         });
 
         GBEAN_INFO = infoBuilder.getBeanInfo();

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java?view=diff&rev=125889&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java&r1=125888&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java&r2=125889
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java	Thu Jan
20 20:39:28 2005
@@ -211,6 +211,12 @@
         return kernelName;
     }
 
+    public static Set getKernelNames() {
+        synchronized(kernels) {
+            return Collections.unmodifiableSet(kernels.keySet());
+        }
+    }
+    
     /**
      * Get a particular kernel indexed by a name
      *

Modified: geronimo/trunk/modules/naming-builder/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming-builder/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java?view=diff&rev=125889&p1=geronimo/trunk/modules/naming-builder/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java&r1=125888&p2=geronimo/trunk/modules/naming-builder/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java&r2=125889
==============================================================================
--- geronimo/trunk/modules/naming-builder/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java
(original)
+++ geronimo/trunk/modules/naming-builder/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java
Thu Jan 20 20:39:28 2005
@@ -64,7 +64,6 @@
  * @version $Rev$ $Date$
  */
 public class ENCConfigBuilder {
-
     public static ObjectName getGBeanId(String j2eeType, GerGbeanLocatorType gerGbeanLocator,
J2eeContext j2eeContext, Set localGBeans, Kernel kernel) throws DeploymentException {
         ObjectName containerId = null;
         if (gerGbeanLocator.isSetGbeanLink()) {
@@ -128,14 +127,15 @@
         return containerId;
     }
 
-    public static void addEnvEntries(EnvEntryType[] envEntries, ComponentContextBuilder builder)
throws DeploymentException {
+
+    public static void addEnvEntries(EnvEntryType[] envEntries, ComponentContextBuilder builder,
ClassLoader classLoader) throws DeploymentException {
         for (int i = 0; i < envEntries.length; i++) {
             EnvEntryType envEntry = envEntries[i];
             String name = getStringValue(envEntry.getEnvEntryName());
             String type = getStringValue(envEntry.getEnvEntryType());
             String text = getStringValue(envEntry.getEnvEntryValue());
             try {
-                builder.addEnvEntry(name, type, text);
+                builder.addEnvEntry(name, type, text, classLoader);
             } catch (NumberFormatException e) {
                 throw new DeploymentException("Invalid env-entry value for name: " + name,
e);
             } catch (NamingException e) {
@@ -570,7 +570,7 @@
             }
         }
 
-        addEnvEntries(envEntries, builder);
+        addEnvEntries(envEntries, builder, cl);
 
         // ejb-ref
         addEJBRefs(earContext, uri, ejbRefs, mapEjbRefs(gerEjbRefs), cl, builder);

Modified: geronimo/trunk/modules/naming-builder/src/schema/geronimo-naming.xsd
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming-builder/src/schema/geronimo-naming.xsd?view=diff&rev=125889&p1=geronimo/trunk/modules/naming-builder/src/schema/geronimo-naming.xsd&r1=125888&p2=geronimo/trunk/modules/naming-builder/src/schema/geronimo-naming.xsd&r2=125889
==============================================================================
--- geronimo/trunk/modules/naming-builder/src/schema/geronimo-naming.xsd	(original)
+++ geronimo/trunk/modules/naming-builder/src/schema/geronimo-naming.xsd	Thu Jan 20 20:39:28
2005
@@ -53,6 +53,7 @@
             </xsd:documentation>
         </xsd:annotation>
         <xsd:sequence>
+            <xsd:element name="gbean-ref" type="gernaming:gbean-refType" minOccurs="0"
maxOccurs="unbounded"/>
             <xsd:element name="ejb-ref" type="gernaming:ejb-refType" minOccurs="0" maxOccurs="unbounded"/>
             <xsd:element name="ejb-local-ref" type="gernaming:ejb-local-refType" minOccurs="0"
maxOccurs="unbounded"/>
             <!-- leave web services out until I know what they do -->
@@ -102,6 +103,18 @@
                 <xsd:element name="resource-link" type="xsd:string"/>
                 <xsd:element name="target-name" type="xsd:string"/>
                 <xsd:element name="url" type="xsd:string"/>
+            </xsd:choice>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:complexType name="gbean-refType">
+        <xsd:sequence>
+            <xsd:element name="ref-name" type="xsd:string"/>
+            <xsd:element name="ref-type" type="xsd:string"/>
+            <xsd:element name="proxy-type" type="xsd:string" minOccurs="0"/>
+            <xsd:choice minOccurs="0" maxOccurs="unbounded">
+                <xsd:group ref="gernaming:objectNameGroup"/>
+                <xsd:element name="target-name" type="xsd:string"/>
             </xsd:choice>
         </xsd:sequence>
     </xsd:complexType>

Modified: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java?view=diff&rev=125889&p1=geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java&r1=125888&p2=geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java&r2=125889
==============================================================================
--- geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java
(original)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java
Thu Jan 20 20:39:28 2005
@@ -17,9 +17,15 @@
 
 package org.apache.geronimo.naming.java;
 
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
 import javax.naming.NamingException;
 import javax.transaction.UserTransaction;
 
+import org.apache.geronimo.kernel.ClassLoading;
+import org.apache.geronimo.naming.reference.GBeanProxyReference;
+import org.apache.geronimo.naming.reference.KernelReference;
+
 /**
  * TODO consider removing this class. The only purpose is to slightly hide the internalBind
method.
  *
@@ -50,7 +56,6 @@
         context.internalBind("UserTransaction", userTransaction);
     }
 
-
     public void bind(String name, Object value) throws NamingException {
         if (context.isFrozen()) {
             throw new IllegalStateException("Context has been frozen");
@@ -58,15 +63,18 @@
         context.internalBind(ENV + name, value);
     }
 
-
-    public void addEnvEntry(String name, String type, String text) throws NamingException,
NumberFormatException {
+    public void addEnvEntry(String name, String type, String text, ClassLoader classLoader)
throws NamingException, NumberFormatException {
         if (context.isFrozen()) {
             throw new IllegalStateException("Context has been frozen");
         }
 
         Object value;
         if (text == null) {
-            value = null;
+            if ("org.apache.geronimo.kernel.Kernel".equals(type)) {
+                value = new KernelReference();
+            } else {
+                value = null;
+            }
         } else if ("java.lang.String".equals(type)) {
             value = text;
         } else if ("java.lang.Character".equals(type)) {
@@ -86,9 +94,25 @@
         } else if ("java.lang.Double".equals(type)) {
             value = Double.valueOf(text);
         } else {
-            throw new IllegalArgumentException("Invalid class for env-entry " + name + ",
" + type);
+            Class clazz = null;
+            try {
+                clazz = ClassLoading.loadClass(type, classLoader);
+            } catch (ClassNotFoundException e) {
+                throw new IllegalArgumentException("Could not load class for env-entry "
+ name + ", " + type);
+            }
+            ObjectName objectName = null;
+            try {
+                objectName = ObjectName.getInstance(text);
+            } catch (MalformedObjectNameException e) {
+                throw new IllegalArgumentException("If env-entry type is not String, Character,
Byte, Short, Integer, Long, " +
+                        "Boolean, Double, or Float, the text value must be a valid ObjectName
for use in a GBeanProxy:" +
+                        " name= " + name +
+                        ", value=" + type +
+                        ", text=" + text);
+            }
+            value = new GBeanProxyReference(objectName, clazz);
+
         }
         context.internalBind(ENV + name, value);
     }
-
 }

Modified: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java?view=diff&rev=125889&p1=geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java&r1=125888&p2=geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java&r2=125889
==============================================================================
--- geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java
(original)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java
Thu Jan 20 20:39:28 2005
@@ -39,6 +39,11 @@
 import javax.naming.Reference;
 import javax.naming.spi.NamingManager;
 
+import org.apache.geronimo.naming.reference.SimpleReference;
+import org.apache.geronimo.naming.reference.KernelAwareReference;
+import org.apache.geronimo.naming.reference.ClassLoaderAwareReference;
+import org.apache.geronimo.kernel.Kernel;
+
 /**
  * A read-only Context in the java: namespace.
  * <p>
@@ -59,7 +64,7 @@
  *
  * @version $Rev$ $Date$
  */
-public class ReadOnlyContext implements Context,Serializable {
+public class ReadOnlyContext implements Context, Serializable {
     protected final Hashtable env;        // environment for this context
     protected final Map bindings;         // bindings at my level
     protected final Map treeBindings;     // all bindings under me
@@ -138,7 +143,7 @@
             Map subBindings = readOnlyContext.internalBind(remainder, value);
             for (Iterator iterator = subBindings.entrySet().iterator(); iterator.hasNext();)
{
                 Map.Entry entry = (Map.Entry) iterator.next();
-                String subName = segment + "/" + (String)entry.getKey();
+                String subName = segment + "/" + entry.getKey();
                 Object bound = entry.getValue();
                 treeBindings.put(subName, bound);
                 newBindings.put(subName, bound);
@@ -151,6 +156,24 @@
         return new ReadOnlyContext();
     }
 
+    public void setKernel(Kernel kernel) {
+        for (Iterator iterator = treeBindings.values().iterator(); iterator.hasNext();) {
+            Object o = iterator.next();
+            if (o instanceof KernelAwareReference) {
+                ((KernelAwareReference) o).setKernel(kernel);
+            }
+        }
+    }
+
+    public void setClassLoader(ClassLoader classLoader) {
+        for (Iterator iterator = treeBindings.values().iterator(); iterator.hasNext();) {
+            Object o = iterator.next();
+            if (o instanceof ClassLoaderAwareReference) {
+                ((ClassLoaderAwareReference) o).setClassLoader(classLoader);
+            }
+        }
+    }
+
     public Object addToEnvironment(String propName, Object propVal) throws NamingException
{
         return env.put(propName, propVal);
     }
@@ -194,6 +217,13 @@
                     }
                     return obj;
                 }
+            }
+        }
+        if (result instanceof SimpleReference) {
+            try {
+                result = ((SimpleReference) result).getContent();
+            } catch (Exception e) {
+                throw (NamingException)new NamingException("could not look up : " + name).initCause(e);
             }
         }
         if (result instanceof LinkRef) {

Added: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/ClassLoaderAwareReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/ClassLoaderAwareReference.java?view=auto&rev=125889
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/ClassLoaderAwareReference.java
Thu Jan 20 20:39:28 2005
@@ -0,0 +1,24 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.naming.reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface ClassLoaderAwareReference {
+    void setClassLoader(ClassLoader classLoader);
+}

Deleted: /geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/GBeanGetResourceRefAddr.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/GBeanGetResourceRefAddr.java?view=auto&rev=125888
==============================================================================

Added: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/GBeanProxyReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/GBeanProxyReference.java?view=auto&rev=125889
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/GBeanProxyReference.java
Thu Jan 20 20:39:28 2005
@@ -0,0 +1,46 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.naming.reference;
+
+import javax.management.ObjectName;
+
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.proxy.ProxyManager;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GBeanProxyReference extends SimpleAwareReference {
+    private final ObjectName target;
+    private final Class type;
+
+    public GBeanProxyReference(ObjectName target, Class type) {
+        this.target = target;
+        this.type = type;
+    }
+
+    public String getClassName() {
+        return type.getName();
+    }
+
+    public Object getContent() throws IllegalStateException {
+        Kernel kernel = getKernel();
+        // todo HACK: this is a very bad idea
+        ProxyManager proxyManager = kernel.getProxyManager();
+        return proxyManager.createProxy(target, type);
+    }
+}

Deleted: /geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/GBeanRefAddr.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/GBeanRefAddr.java?view=auto&rev=125888
==============================================================================

Added: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/KernelAwareReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/KernelAwareReference.java?view=auto&rev=125889
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/KernelAwareReference.java
Thu Jan 20 20:39:28 2005
@@ -0,0 +1,26 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.naming.reference;
+
+import org.apache.geronimo.kernel.Kernel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface KernelAwareReference {
+    void setKernel(Kernel kernel);
+}

Added: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/KernelReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/KernelReference.java?view=auto&rev=125889
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/KernelReference.java
Thu Jan 20 20:39:28 2005
@@ -0,0 +1,35 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.naming.reference;
+
+import javax.management.ObjectName;
+
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.proxy.ProxyManager;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class KernelReference extends SimpleAwareReference {
+    public String getClassName() {
+        return Kernel.class.getName();
+    }
+
+    public Object getContent() throws IllegalStateException {
+        return getKernel();
+    }
+}

Deleted: /geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/RefAddrContentObjectFactory.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/RefAddrContentObjectFactory.java?view=auto&rev=125888
==============================================================================

Added: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/ResourceReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/ResourceReference.java?view=auto&rev=125889
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/ResourceReference.java
Thu Jan 20 20:39:28 2005
@@ -0,0 +1,66 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.naming.reference;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.geronimo.kernel.Kernel;
+
+/**
+ * @version $Rev: 56169 $ $Date: 2004-10-31 16:05:29 -0800 (Sun, 31 Oct 2004) $
+ */
+public class ResourceReference extends SimpleAwareReference {
+    private final String containerId;
+    private final Class iface;
+
+    public ResourceReference(String containerId, Class iface) {
+        this.containerId = containerId;
+        this.iface = iface;
+    }
+
+    public String getClassName() {
+        return iface.getName();
+    }
+
+    public Object getContent() {
+        Kernel kernel = getKernel();
+
+        ObjectName target = null;
+        try {
+            target = ObjectName.getInstance(containerId);
+        } catch (MalformedObjectNameException e) {
+            throw (IllegalArgumentException) new IllegalArgumentException("Invalid object
name in jmxRefAddr: " + containerId).initCause(e);
+        }
+
+        Object proxy = null;
+        try {
+            proxy = kernel.invoke(target, "$getResource");
+        } catch (Exception e) {
+            throw (IllegalStateException) new IllegalStateException("Could not get proxy").initCause(e);
+        }
+        if (proxy == null) {
+            throw new IllegalStateException("Proxy not returned. Target " + containerId +
" not started");
+        }
+        if (!iface.isAssignableFrom(proxy.getClass())) {
+            throw new ClassCastException("Proxy does not implement expected interface " +
iface);
+        }
+        return proxy;
+
+    }
+}

Added: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/SimpleAwareReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/SimpleAwareReference.java?view=auto&rev=125889
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/SimpleAwareReference.java
Thu Jan 20 20:39:28 2005
@@ -0,0 +1,51 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.naming.reference;
+
+import javax.naming.RefAddr;
+
+import org.apache.geronimo.kernel.Kernel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class SimpleAwareReference extends SimpleReference implements KernelAwareReference,
ClassLoaderAwareReference {
+    private transient Kernel kernel;
+    private transient ClassLoader classLoader;
+
+    public final Kernel getKernel() throws IllegalStateException {
+        if (kernel == null) {
+            throw new IllegalStateException("Kernel has not been set");
+        }
+        return kernel;
+    }
+
+    public final void setKernel(Kernel kernel) {
+        this.kernel = kernel;
+    }
+
+    public ClassLoader getClassLoader() {
+        if (classLoader == null) {
+            throw new IllegalStateException("ClassLoader has not been set");
+        }
+        return classLoader;
+    }
+
+    public void setClassLoader(ClassLoader classLoader) {
+        this.classLoader = classLoader;
+    }
+}

Added: geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/SimpleReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/SimpleReference.java?view=auto&rev=125889
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/naming/src/java/org/apache/geronimo/naming/reference/SimpleReference.java
Thu Jan 20 20:39:28 2005
@@ -0,0 +1,140 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.naming.reference;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.NoSuchElementException;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class SimpleReference extends Reference {
+    private static final Enumeration EMPTY_ENUMERATION = new Enumeration() {
+        public boolean hasMoreElements() {
+            return false;
+        }
+
+        public Object nextElement() {
+            return new NoSuchElementException();
+        }
+    };
+
+    public SimpleReference() {
+        super(null);
+    }
+
+    /**
+     * Gets the actual referenced Object.
+     * @return the referenced object
+     */
+    public abstract Object getContent();
+
+    /**
+     * We will atleast return an Object.  Subclasses may want to provide a more specific
class.
+     * @return "java.lang.Object"
+     */
+    public String getClassName() {
+        return "java.lang.Object";
+    }
+
+    /**
+     * If the JNDI context does not understand simple references, this method will be called
+     * to obtain the class name of a factory.  This factory in turn understands the simple
+     * reference.  This style is much slower because JNDI will use reflection to load and
+     * create this class.
+     * @return
+     */
+    public final String getFactoryClassName() {
+        return SimpleObjectFactory.class.getName();
+    }
+
+    //
+    // Disabled methods that we no longer need
+    //
+    public final String getFactoryClassLocation() {
+        return null;
+    }
+
+    public final RefAddr get(String addrType) {
+        return null;
+    }
+
+    public final RefAddr get(int posn) {
+        throw new ArrayIndexOutOfBoundsException(posn);
+    }
+
+    public final Enumeration getAll() {
+        return EMPTY_ENUMERATION;
+    }
+
+    public final int size() {
+        return 0;
+    }
+
+    public final void add(RefAddr addr) {
+        throw new UnsupportedOperationException("SimpleReference has no addresses so none
can be added");
+    }
+
+    public final void add(int posn, RefAddr addr) {
+        throw new UnsupportedOperationException("SimpleReference has no addresses so none
can be added");
+    }
+
+    public final Object remove(int posn) {
+        throw new ArrayIndexOutOfBoundsException(posn);
+    }
+
+    public final void clear() {
+    }
+
+    //
+    // Reset the java.lang.Object methods back to default implementations
+    //
+    public boolean equals(Object obj) {
+        return this == obj;
+    }
+
+    public int hashCode() {
+        return System.identityHashCode(this);
+    }
+
+    public String toString() {
+        return getClass().getName() + "@" + Integer.toHexString(hashCode());
+    }
+
+    public Object clone() {
+        throw new UnsupportedOperationException("SimpleReference can not be cloned");
+    }
+
+    /**
+     * Simply calls getContent() on the SimpleReference
+     */
+    public static final class SimpleObjectFactory implements ObjectFactory {
+        public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable
environment) throws Exception {
+            if (obj instanceof SimpleReference) {
+                SimpleReference reference = (SimpleReference) obj;
+                return reference.getContent();
+            }
+            return null;
+        }
+    }
+}

Modified: geronimo/trunk/modules/naming/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/naming/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java?view=diff&rev=125889&p1=geronimo/trunk/modules/naming/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java&r1=125888&p2=geronimo/trunk/modules/naming/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java&r2=125889
==============================================================================
--- geronimo/trunk/modules/naming/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java
(original)
+++ geronimo/trunk/modules/naming/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java
Thu Jan 20 20:39:28 2005
@@ -45,7 +45,7 @@
         ReadOnlyContext context = builder.getContext();
         assertTrue(context.isFrozen());
         try {
-            builder.addEnvEntry(null, null, null);
+            builder.addEnvEntry(null, null, null, null);
             fail();
         } catch (IllegalStateException e) {
             // ok
@@ -72,15 +72,15 @@
         Float floatVal = new Float(123.456);
         Double doubleVal = new Double(12345.6789);
         Boolean booleanVal = Boolean.TRUE;
-        builder.addEnvEntry("string", String.class.getName(), stringVal);
-        builder.addEnvEntry("char", Character.class.getName(), charVal.toString());
-        builder.addEnvEntry("byte", Byte.class.getName(), byteVal.toString());
-        builder.addEnvEntry("short", Short.class.getName(), shortVal.toString());
-        builder.addEnvEntry("int", Integer.class.getName(), intVal.toString());
-        builder.addEnvEntry("long", Long.class.getName(), longVal.toString());
-        builder.addEnvEntry("float", Float.class.getName(), floatVal.toString());
-        builder.addEnvEntry("double", Double.class.getName(), doubleVal.toString());
-        builder.addEnvEntry("boolean", Boolean.class.getName(), booleanVal.toString());
+        builder.addEnvEntry("string", String.class.getName(), stringVal, null);
+        builder.addEnvEntry("char", Character.class.getName(), charVal.toString(), null);
+        builder.addEnvEntry("byte", Byte.class.getName(), byteVal.toString(), null);
+        builder.addEnvEntry("short", Short.class.getName(), shortVal.toString(), null);
+        builder.addEnvEntry("int", Integer.class.getName(), intVal.toString(), null);
+        builder.addEnvEntry("long", Long.class.getName(), longVal.toString(), null);
+        builder.addEnvEntry("float", Float.class.getName(), floatVal.toString(), null);
+        builder.addEnvEntry("double", Double.class.getName(), doubleVal.toString(), null);
+        builder.addEnvEntry("boolean", Boolean.class.getName(), booleanVal.toString(), null);
 
         ReadOnlyContext context = builder.getContext();
         Set actual = new HashSet();

Mime
View raw message