geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r984123 - in /geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src: main/java/org/apache/geronimo/naming/deployment/ test/resources/annotation/
Date Tue, 10 Aug 2010 17:06:01 GMT
Author: gawor
Date: Tue Aug 10 17:06:00 2010
New Revision: 984123

URL: http://svn.apache.org/viewvc?rev=984123&view=rev
Log:
GERONIMO-5518: Support injection of primitive types using @Resource annotation

Modified:
    geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
    geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
    geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/test/resources/annotation/env-entry-expected.xml

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java?rev=984123&r1=984122&r2=984123&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
Tue Aug 10 17:06:00 2010
@@ -378,8 +378,8 @@ public abstract class AbstractNamingBuil
     }
 
     //duplicated in ResourceAnnotationHelper
-    private static Class<?> deprimitivize(Class<?> fieldType) {
-        return fieldType = fieldType.isPrimitive()? primitives.get(fieldType): fieldType;
+    public static Class<?> deprimitivize(Class<?> fieldType) {
+        return fieldType = fieldType.isPrimitive() ? primitives.get(fieldType): fieldType;
     }
 
     private static final Map<Class<?>, Class<?>> primitives = new HashMap<Class<?>,
Class<?>>();

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java?rev=984123&r1=984122&r2=984123&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
Tue Aug 10 17:06:00 2010
@@ -19,10 +19,13 @@ package org.apache.geronimo.naming.deplo
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.annotation.Resource;
 import javax.xml.namespace.QName;
@@ -216,24 +219,26 @@ public class EnvironmentEntryBuilder ext
 
         public static final EnvEntryRefProcessor INSTANCE = new EnvEntryRefProcessor();
 
+        private static final Set<String> knownEnvironmentEntries = new HashSet<String>(Arrays.asList(
+                "boolean", "java.lang.Boolean",
+                "char", "java.lang.Character",
+                "byte", "java.lang.Byte",
+                "short", "java.lang.Short",
+                "int", "java.lang.Integer",
+                "long", "java.lang.Long",
+                "float", "java.lang.Float",
+                "double", "java.lang.Double",
+                "java.lang.String",
+                "java.lang.Class"
+        ));
+                
         private EnvEntryRefProcessor() {
         }
-
+        
         public boolean processResource(JndiConsumer annotatedApp, Resource annotation, Class
cls, Method method, Field field) {
             String resourceName = getResourceName(annotation, method, field);
             Class resourceType = getResourceTypeClass(annotation, method, field);
-            if (resourceType.equals(String.class) ||
-                    resourceType.equals(Character.class) ||
-                    resourceType.equals(Integer.class) ||
-                    resourceType.equals(Boolean.class) ||
-                    resourceType.equals(Double.class) ||
-                    resourceType.equals(Byte.class) ||
-                    resourceType.equals(Short.class) ||
-                    resourceType.equals(Long.class) ||
-                    resourceType.equals(Float.class) ||
-                    resourceType.equals(Class.class) ||
-                    resourceType.isEnum()) {
-
+            if (knownEnvironmentEntries.contains(resourceType.getName()) || resourceType.isEnum())
{
                 log.debug("addResource(): <env-entry> found");
 
                 boolean exists = false;
@@ -267,7 +272,7 @@ public class EnvironmentEntryBuilder ext
 
                         if (!resourceType.equals(Object.class)) {
                             // env-entry-type
-                            envEntry.setEnvEntryType(resourceType.getCanonicalName());
+                            envEntry.setEnvEntryType(deprimitivize(resourceType).getCanonicalName());
                         }
                         if (method != null || field != null) {
                             // injectionTarget

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/test/resources/annotation/env-entry-expected.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/test/resources/annotation/env-entry-expected.xml?rev=984123&r1=984122&r2=984123&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/test/resources/annotation/env-entry-expected.xml
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/test/resources/annotation/env-entry-expected.xml
Tue Aug 10 17:06:00 2010
@@ -46,13 +46,13 @@
         </injection-target>
         <lookup-name>java:app/foo</lookup-name>
     </env-entry>
-    <!--<env-entry>-->
-        <!--<env-entry-name>Resource3</env-entry-name>-->
-        <!--<env-entry-type>java.lang.Boolean</env-entry-type>-->
-        <!--<mapped-name>mappedName3</mapped-name>-->
-        <!--<injection-target>-->
-            <!--<injection-target-class>org.apache.geronimo.naming.deployment.annotation.ResourceAnnotationExample</injection-target-class>-->
-            <!--<injection-target-name>annotatedField1</injection-target-name>-->
-        <!--</injection-target>-->
-    <!--</env-entry>-->
+    <env-entry>
+        <env-entry-name>Resource3</env-entry-name>
+        <env-entry-type>java.lang.Boolean</env-entry-type>
+        <mapped-name>mappedName3</mapped-name>
+        <injection-target>
+            <injection-target-class>org.apache.geronimo.naming.deployment.annotation.ResourceAnnotationExample</injection-target-class>
+            <injection-target-name>annotatedField1</injection-target-name>
+        </injection-target>
+    </env-entry>
 </web-app>



Mime
View raw message