You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2009/07/08 19:19:48 UTC

svn commit: r792235 - in /geronimo/server/trunk/plugins/openejb: geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ openejb/src/main/plan/

Author: djencks
Date: Wed Jul  8 17:19:48 2009
New Revision: 792235

URL: http://svn.apache.org/viewvc?rev=792235&view=rev
Log:
GERONIMO-4599 use xbean naming in openejb

Added:
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java   (with props)
Modified:
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
    geronimo/server/trunk/plugins/openejb/openejb/src/main/plan/plan.xml

Added: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java?rev=792235&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java (added)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java Wed Jul  8 17:19:48 2009
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.openejb;
+
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.naming.Binding;
+import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.ParamAttribute;
+import org.apache.openejb.SystemException;
+import org.apache.openejb.core.JndiFactory;
+import org.apache.xbean.naming.context.ContextAccess;
+import org.apache.xbean.naming.context.WritableContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@GBean
+public class DeepBindableContext extends WritableContext {
+
+    public DeepBindableContext(@ParamAttribute(name="nameInNamespace") String nameInNamespace,
+                               @ParamAttribute(name="cacheReferences") boolean cacheReferences,
+                               @ParamAttribute(name="supportReferenceable") boolean supportReferenceable,
+                               @ParamAttribute(name="checkDereferenceDifferent") boolean checkDereferenceDifferent,
+                               @ParamAttribute(name="assumeDereferenceBound") boolean assumeDereferenceBound) throws NamingException {
+         super(nameInNamespace, Collections.<String, Object>emptyMap(), ContextAccess.MODIFIABLE, cacheReferences, supportReferenceable, checkDereferenceDifferent, assumeDereferenceBound);
+     }
+
+     void addDeepBinding(String name, Object value) throws NamingException {
+         addDeepBinding(new CompositeName(name), value, false, true);
+     }
+
+    public JndiFactory newJndiFactory() throws NamingException {
+        return new XBeanJndiFactory();
+    }
+    
+    class XBeanJndiFactory implements JndiFactory {
+        private final Context rootContext;
+
+        XBeanJndiFactory() throws NamingException {
+            rootContext = new ContextWrapper((Context) new InitialContext().lookup(""));
+        }
+
+        public Context createComponentContext(Map<String, Object> bindings) throws SystemException {
+            boolean hasEnv = false;
+            for (String name : bindings.keySet()) {
+                if (name.startsWith("java:comp/env")) {
+                    hasEnv = true;
+                    break;
+                }
+            }
+            if (!hasEnv) bindings.put("java:comp/env/dummy", "dummy");
+
+            WritableContext context = null;
+            try {
+                context = new WritableContext("", bindings);
+            } catch (NamingException e) {
+                throw new IllegalStateException(e);
+            }
+            return context;
+        }
+
+        public Context createRootContext() {
+            return rootContext;
+        }
+
+
+
+    }
+
+    class ContextWrapper implements Context {
+        private final Context rootContext;
+
+        ContextWrapper(Context rootContext) {
+            this.rootContext = rootContext;
+        }
+
+        public Object lookup(Name name) throws NamingException {
+            return rootContext.lookup(name);
+        }
+
+        public Object lookup(String name) throws NamingException {
+            return rootContext.lookup(name);
+        }
+
+        public void bind(Name name, Object value) throws NamingException {
+            bind(name.toString(), value);
+        }
+
+        public void bind(String name, Object value) throws NamingException {
+            if (name.startsWith("java:openejb/")) {
+                name = name.substring("java:openejb/".length());
+            } else if (name.startsWith("openejb/")) {
+                name = name.substring("openejb/".length());
+            }
+            addDeepBinding(name, value);
+        }
+
+        public void rebind(Name name, Object o) throws NamingException {
+            rootContext.rebind(name, o);
+        }
+
+        public void rebind(String s, Object o) throws NamingException {
+            rootContext.rebind(s, o);
+        }
+
+        public void unbind(Name name) throws NamingException {
+            rootContext.unbind(name);
+        }
+
+        public void unbind(String s) throws NamingException {
+            rootContext.unbind(s);
+        }
+
+        public void rename(Name name, Name name1) throws NamingException {
+            rootContext.rename(name, name1);
+        }
+
+        public void rename(String s, String s1) throws NamingException {
+            rootContext.rename(s, s1);
+        }
+
+        public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
+            return rootContext.list(name);
+        }
+
+        public NamingEnumeration<NameClassPair> list(String s) throws NamingException {
+            return rootContext.list(s);
+        }
+
+        public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
+            return rootContext.listBindings(name);
+        }
+
+        public NamingEnumeration<Binding> listBindings(String s) throws NamingException {
+            return rootContext.listBindings(s);
+        }
+
+        public void destroySubcontext(Name name) throws NamingException {
+            rootContext.destroySubcontext(name);
+        }
+
+        public void destroySubcontext(String s) throws NamingException {
+            rootContext.destroySubcontext(s);
+        }
+
+        public Context createSubcontext(Name name) throws NamingException {
+            return rootContext.createSubcontext(name);
+        }
+
+        public Context createSubcontext(String s) throws NamingException {
+            return rootContext.createSubcontext(s);
+        }
+
+        public Object lookupLink(Name name) throws NamingException {
+            return rootContext.lookupLink(name);
+        }
+
+        public Object lookupLink(String s) throws NamingException {
+            return rootContext.lookupLink(s);
+        }
+
+        public NameParser getNameParser(Name name) throws NamingException {
+            return rootContext.getNameParser(name);
+        }
+
+        public NameParser getNameParser(String s) throws NamingException {
+            return rootContext.getNameParser(s);
+        }
+
+        public Name composeName(Name name, Name name1) throws NamingException {
+            return rootContext.composeName(name, name1);
+        }
+
+        public String composeName(String s, String s1) throws NamingException {
+            return rootContext.composeName(s, s1);
+        }
+
+        public Object addToEnvironment(String s, Object o) throws NamingException {
+            return rootContext.addToEnvironment(s, o);
+        }
+
+        public Object removeFromEnvironment(String s) throws NamingException {
+            return rootContext.removeFromEnvironment(s);
+        }
+
+        public Hashtable<?, ?> getEnvironment() throws NamingException {
+            return rootContext.getEnvironment();
+        }
+
+        public void close() throws NamingException {
+            rootContext.close();
+        }
+
+        public String getNameInNamespace() throws NamingException {
+            return rootContext.getNameInNamespace();
+        }
+    }
+}

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java?rev=792235&r1=792234&r2=792235&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java (original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java Wed Jul  8 17:19:48 2009
@@ -32,16 +32,18 @@
 import javax.resource.spi.ResourceAdapter;
 import javax.transaction.TransactionManager;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.geronimo.connector.ResourceAdapterWrapper;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
-import org.apache.geronimo.gbean.GBeanInfo;
-import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.ReferenceCollection;
 import org.apache.geronimo.gbean.ReferenceCollectionEvent;
 import org.apache.geronimo.gbean.ReferenceCollectionListener;
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.ParamAttribute;
+import org.apache.geronimo.gbean.annotation.ParamReference;
+import org.apache.geronimo.gbean.annotation.ParamSpecial;
+import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.persistence.PersistenceUnitGBean;
@@ -66,17 +68,21 @@
 import org.apache.openejb.config.EjbModule;
 import org.apache.openejb.core.ServerFederation;
 import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.resource.XAResourceWrapper;
 import org.apache.openejb.resource.GeronimoTransactionManagerFactory.GeronimoXAResourceWrapper;
+import org.apache.openejb.resource.XAResourceWrapper;
 import org.apache.openejb.spi.ApplicationServer;
 import org.apache.openejb.spi.ContainerSystem;
 import org.apache.openejb.spi.SecurityService;
 import org.apache.openejb.util.proxy.Jdk13ProxyFactory;
 import org.omg.CORBA.ORB;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @version $Rev$ $Date$
  */
+
+@GBean
 public class OpenEjbSystemGBean implements OpenEjbSystem {
     private static final Logger log = LoggerFactory.getLogger(OpenEjbSystemGBean.class);
     private final ConfigurationFactory configurationFactory;
@@ -91,9 +97,19 @@
     private Properties properties; 
     
     public OpenEjbSystemGBean(TransactionManager transactionManager) throws Exception {
-        this(transactionManager, null, null, null, OpenEjbSystemGBean.class.getClassLoader(), new Properties());
+        this(transactionManager, null, null, new DeepBindableContext("java:openejb", false, true, true, false), null, OpenEjbSystemGBean.class.getClassLoader(), new Properties());
     }
-    public OpenEjbSystemGBean(TransactionManager transactionManager, Collection<ResourceAdapterWrapper> resourceAdapters, Collection<PersistenceUnitGBean> persistenceUnitGBeans, Kernel kernel, ClassLoader classLoader, Properties properties) throws Exception {
+
+    public OpenEjbSystemGBean(@ParamReference(name = "TransactionManager", namingType = NameFactory.JTA_RESOURCE) TransactionManager transactionManager,
+                              @ParamReference(name = "ResourceAdapterWrappers") Collection<ResourceAdapterWrapper> resourceAdapters,
+                              @ParamReference(name = "PersistenceUnitGBeans") Collection<PersistenceUnitGBean> persistenceUnitGBeans,
+                              @ParamReference(name = "OpenEjbContext")DeepBindableContext openejbContext,
+                              @ParamSpecial(type = SpecialAttributeType.kernel) Kernel kernel,
+                              @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader classLoader,
+                              @ParamAttribute(name = "properties") Properties properties) throws Exception {
+        if (transactionManager == null) {
+            throw new NullPointerException("transactionManager is null");
+        }
         this.kernel = kernel;
         this.classLoader = classLoader;
         this.properties = properties;
@@ -107,14 +123,10 @@
         setDefaultProperty("openejb.jndiname.format", "{ejbName}{interfaceType.annotationName}");
         setDefaultProperty("openejb.jndiname.failoncollision", "false");
 
-        System.setProperty("openejb.naming", "xbean");
-        if (transactionManager == null) {
-            throw new NullPointerException("transactionManager is null");
-        }
-
+//        System.setProperty("openejb.naming", "xbean");
         boolean offline = true;
         configurationFactory = new ConfigurationFactory(offline);
-        assembler = new Assembler();
+        assembler = new Assembler(openejbContext.newJndiFactory());
 
         // install application server
         ApplicationServer applicationServer = new ServerFederation();
@@ -429,28 +441,4 @@
         }
     }
 
-    public static final GBeanInfo GBEAN_INFO;
-
-    static {
-        GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(OpenEjbSystemGBean.class);
-        infoBuilder.addReference("TransactionManager", TransactionManager.class);
-        infoBuilder.addReference("ResourceAdapterWrappers", ResourceAdapterWrapper.class);
-        infoBuilder.addReference("PersistenceUnitGBeans", PersistenceUnitGBean.class);
-        infoBuilder.addAttribute("kernel", Kernel.class, false);
-        infoBuilder.addAttribute("classLoader", ClassLoader.class, false);
-        infoBuilder.addAttribute("properties", Properties.class, true, true);
-        infoBuilder.setConstructor(new String[] {
-                "TransactionManager",
-                "ResourceAdapterWrappers",
-                "PersistenceUnitGBeans",
-                "kernel",
-                "classLoader",
-                "properties"
-        });
-        GBEAN_INFO = infoBuilder.getBeanInfo();
-    }
-
-    public static GBeanInfo getGBeanInfo() {
-        return GBEAN_INFO;
-    }
 }

Modified: geronimo/server/trunk/plugins/openejb/openejb/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/openejb/src/main/plan/plan.xml?rev=792235&r1=792234&r2=792235&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/openejb/src/main/plan/plan.xml (original)
+++ geronimo/server/trunk/plugins/openejb/openejb/src/main/plan/plan.xml Wed Jul  8 17:19:48 2009
@@ -25,6 +25,14 @@
             openejb.strict.interface.declaration=true
         </attribute>
     </gbean>
+
+    <gbean name="OpenEjbContext" class="org.apache.geronimo.openejb.DeepBindableContext">
+        <attribute name="nameInNamespace">openejb</attribute>
+        <attribute name="cacheReferences">false</attribute>
+        <attribute name="supportReferenceable">true</attribute>
+        <attribute name="checkDereferenceDifferent">true</attribute>
+        <attribute name="assumeDereferenceBound">false</attribute>
+    </gbean> 
     
     <gbean name="OpenEjbSystem" class="org.apache.geronimo.openejb.OpenEjbSystemGBean">
         <reference name="TransactionManager">
@@ -32,6 +40,9 @@
         </reference>
         <reference name="ResourceAdapterWrappers"/>
         <reference name="PersistenceUnitGBeans"/>
+        <reference name="OpenEjbContext">
+            <name>OpenEjbContext</name>
+        </reference>
     </gbean>
 
     <gbean name="ExtendedEntityManagerRegistry" class="org.apache.geronimo.openejb.EntityManagerRegistryImpl">