tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r984485 - in /openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/assembler/classic/ main/java/org/apache/openejb/core/ivm/naming/ test/java/org/apache/openejb/config/
Date Wed, 11 Aug 2010 17:29:26 GMT
Author: gawor
Date: Wed Aug 11 17:29:25 2010
New Revision: 984485

URL: http://svn.apache.org/viewvc?rev=984485&view=rev
Log:
OPENEJB-1324: Additional fixes and tests for supporting Enum and Class types as env-entry
types

Added:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/ClassReference.java
  (with props)
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/InjectionTest.java
  (with props)
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java?rev=984485&r1=984484&r2=984485&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
Wed Aug 11 17:29:25 2010
@@ -23,6 +23,7 @@ import org.apache.openejb.spi.ContainerS
 import org.apache.openejb.core.CoreUserTransaction;
 import org.apache.openejb.core.TransactionSynchronizationRegistryWrapper;
 import org.apache.openejb.core.JndiFactory;
+import org.apache.openejb.core.ivm.naming.ClassReference;
 import org.apache.openejb.core.ivm.naming.CrossClassLoaderJndiReference;
 import org.apache.openejb.core.ivm.naming.IntraVmJndiReference;
 import org.apache.openejb.core.ivm.naming.JaxWsServiceReference;
@@ -203,6 +204,10 @@ public class JndiEncBuilder {
                     obj = new Character(sb.charAt(0));
                 } else if (type == URL.class) {
                     obj = new URL(entry.value);
+                } else if (type == Class.class) {
+                    obj = new ClassReference(entry.value.trim());
+                } else if (type.isEnum()) {
+                    obj = Enum.valueOf(type, entry.value.trim());
                 } else {
                     throw new IllegalArgumentException("Invalid env-ref-type " + type);
                 }

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/ClassReference.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/ClassReference.java?rev=984485&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/ClassReference.java
(added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/ClassReference.java
Wed Aug 11 17:29:25 2010
@@ -0,0 +1,38 @@
+/**
+ *
+ * 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.openejb.core.ivm.naming;
+
+import javax.naming.NamingException;
+
+public class ClassReference extends Reference {
+
+    private final String className;
+
+    public ClassReference(String className) {
+        this.className = className;
+    }
+
+    public Object getObject() throws NamingException {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            return classLoader.loadClass(className);
+        } catch (ClassNotFoundException e) {
+            throw new NamingException("Erorr loading class: " + className);
+        }
+    }
+}

Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/ClassReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/ClassReference.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/ClassReference.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/InjectionTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/InjectionTest.java?rev=984485&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/InjectionTest.java
(added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/InjectionTest.java
Wed Aug 11 17:29:25 2010
@@ -0,0 +1,217 @@
+/**
+ *
+ * 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.openejb.config;
+
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.Resource;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.ProxyFactoryInfo;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.core.ivm.naming.InitContextFactory;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.EnvEntry;
+import org.apache.openejb.jee.StatelessBean;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class InjectionTest extends TestCase {
+
+    public void testEnvEntryInjections() throws Exception {       
+        InitialContext ctx = new InitialContext();
+
+        Object object = ctx.lookup("WidgetBeanLocal");
+
+        assertTrue("instanceof widget", object instanceof Widget);
+
+        Widget widget = (Widget) object;
+
+        assertEquals("2", widget.getString());
+        assertEquals(3.0D, widget.getDouble());
+        assertEquals(new Long(4), widget.getLong());
+        assertEquals(new Float(5f), widget.getFloat());
+        assertEquals(new Integer(6), widget.getInteger());
+        assertEquals(new Short((short)7), widget.getShort());
+        assertEquals(Boolean.FALSE, widget.getBoolean());
+        assertEquals(new Character('9'), widget.getCharacter());
+        assertEquals(Widget.class, widget.getMyClass());
+        assertEquals(TimeUnit.HOURS, widget.getTimeUnit());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
+
+        ConfigurationFactory config = new ConfigurationFactory();
+        Assembler assembler = new Assembler();
+
+        assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
+        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+        // containers
+        StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
+        statelessContainerInfo.properties.setProperty("TimeOut", "10");
+        statelessContainerInfo.properties.setProperty("MaxSize", "0");
+        statelessContainerInfo.properties.setProperty("StrictPooling", "false");
+        assembler.createContainer(statelessContainerInfo);
+
+        // Setup the descriptor information
+
+        StatelessBean bean = new StatelessBean(WidgetBean.class);
+        bean.addBusinessLocal(Widget.class.getName());
+        bean.addBusinessRemote(RemoteWidget.class.getName());
+
+        EjbJar ejbJar = new EjbJar();
+        ejbJar.addEnterpriseBean(bean);
+        
+        bean.getEnvEntry().add(new EnvEntry(name("myString"), "java.lang.String", "2"));
+        bean.getEnvEntry().add(new EnvEntry(name("myDouble"), "java.lang.Double", "3.0"));
+        bean.getEnvEntry().add(new EnvEntry(name("myLong"), "java.lang.Long", "4"));
+        bean.getEnvEntry().add(new EnvEntry(name("myFloat"), "java.lang.Float", "5"));
+        bean.getEnvEntry().add(new EnvEntry(name("myInteger"), "java.lang.Integer", "6"));
+        bean.getEnvEntry().add(new EnvEntry(name("myShort"), "java.lang.Short", "7"));
+        bean.getEnvEntry().add(new EnvEntry(name("myBoolean"), "java.lang.Boolean", "false"));
+        bean.getEnvEntry().add(new EnvEntry(name("myByte"), "java.lang.Byte", "8"));
+        bean.getEnvEntry().add(new EnvEntry(name("myCharacter"), "java.lang.Character", "9"));
+        bean.getEnvEntry().add(new EnvEntry(name("myClass"), "java.lang.Class", Widget.class.getName()));
+        bean.getEnvEntry().add(new EnvEntry(name("myTimeUnit"), TimeUnit.class.getName(),
"HOURS"));
+
+        assembler.createApplication(config.configureApplication(ejbJar));
+    }
+
+    private String name(String name) {
+      return "java:comp/env/" + WidgetBean.class.getName() + "/" + name;
+    }
+    
+    public static interface Widget {
+        String getString();
+        Double getDouble();
+        Long getLong();
+        Float getFloat();
+        Short getShort();
+        Integer getInteger();
+        Boolean getBoolean();
+        Character getCharacter();
+        Byte getByte();
+        Class getMyClass();
+        TimeUnit getTimeUnit();
+    }
+
+    public static interface RemoteWidget extends Widget {
+    }
+
+    @Stateless
+    public static class WidgetBean implements Widget, RemoteWidget {
+
+        @Resource
+        private String myString = "1";
+
+        @Resource
+        private Double myDouble = 1.0D;
+
+        @Resource
+        private Long myLong = 1L;
+
+        @Resource
+        private Float myFloat = 1.0F;
+
+        @Resource
+        private Integer myInteger = 1;
+
+        @Resource
+        private Short myShort = (short) 1;
+
+        @Resource
+        private Boolean myBoolean = true;
+
+        @Resource
+        private Byte myByte = (byte) 1;
+
+        @Resource
+        private Character myCharacter = '1';
+        
+        @Resource 
+        private Class myClass = Object.class;
+        
+        @Resource
+        private TimeUnit myTimeUnit = TimeUnit.DAYS;
+
+        public WidgetBean() {           
+        }
+
+        @Resource
+        public void setSessionContext(SessionContext sessionContext) {
+        }
+
+        public Boolean getBoolean() {
+            return myBoolean;
+        }
+
+        public Byte getByte() {
+            return myByte;
+        }
+
+        public Character getCharacter() {
+            return myCharacter;
+        }
+
+        public Double getDouble() {
+            return myDouble;
+        }
+
+        public Float getFloat() {
+            return myFloat;
+        }
+
+        public Integer getInteger() {
+            return myInteger;
+        }
+
+        public Long getLong() {
+            return myLong;
+        }
+
+        public Class getMyClass() {
+            return myClass;
+        }
+
+        public Short getShort() {
+            return myShort;
+        }
+
+        public String getString() {
+            return myString;
+        }
+
+        public TimeUnit getTimeUnit() {
+            return myTimeUnit;
+        }
+
+    }
+}

Propchange: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/InjectionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/InjectionTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/InjectionTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message