[jboss-cvs] JBossAS SVN: r58437 - trunk/ejb3/src/main/org/jboss/injection

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 16 01:11:48 EST 2006


Author: scott.stark at jboss.org
Date: 2006-11-16 01:11:41 -0500 (Thu, 16 Nov 2006)
New Revision: 58437

Modified:
   trunk/ejb3/src/main/org/jboss/injection/ResourceHandler.java
Log:
Use the mappedName as the string value of the env-entry style of @Resource so that these can be fully specified via the annotation.

Modified: trunk/ejb3/src/main/org/jboss/injection/ResourceHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/injection/ResourceHandler.java	2006-11-16 04:25:49 UTC (rev 58436)
+++ trunk/ejb3/src/main/org/jboss/injection/ResourceHandler.java	2006-11-16 06:11:41 UTC (rev 58437)
@@ -28,6 +28,7 @@
 import org.jboss.metamodel.descriptor.MessageDestinationRef;
 import org.jboss.metamodel.descriptor.ResourceEnvRef;
 import org.jboss.metamodel.descriptor.ResourceRef;
+import org.jboss.reflect.plugins.ValueConvertor;
 
 import javax.annotation.Resource;
 import javax.annotation.Resources;
@@ -166,10 +167,26 @@
          throw new RuntimeException("You did not specify a @Resource.mappedName() for name: "
                +ref.name()+", class: " + clazz.getName() + " and there is no binding for that enc name in XML");
       }
-      container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@Resource"));
+
+      if (ref.type() == URL.class)
+      {
+         // Create a URL from the mappedName
+         try
+         {
+            URL url = new URL(ref.mappedName().trim());
+            container.getEncInjectors().put(encName, new ValueEncInjector(encName, url, "@Resource"));
+         }
+         catch (MalformedURLException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+      else
+      {
+         container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@Resource"));
+      }
    }
 
-
    public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
    {
       Resource ref = method.getAnnotation(Resource.class);
@@ -227,6 +244,21 @@
          {
             injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
          }
+         else if (ref.mappedName() != null && ref.mappedName().length() > 0)
+         {
+            // Use the mappedName as the string value
+            String s = ref.mappedName().trim();
+            try
+            {
+               Object value = ValueConvertor.convertValue(type, s);
+               container.getEncInjectors().put(encName, new ValueEncInjector(encName, value, "@Resource"));
+               injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
+            }
+            catch(Throwable t)
+            {
+               throw new RuntimeException("Failed to convert: "+ref.mappedName()+" to type:"+type, t);
+            }
+         }
       }
       else
       {
@@ -290,12 +322,26 @@
               || type.isPrimitive()
               )
       {
-
          // don't add an injector if no XML <env-entry is present as there will be no value to inject
          if (container.getEncInjectors().containsKey(encName))
          {
             injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
          }
+         else if (ref.mappedName() != null && ref.mappedName().length() > 0)
+         {
+            // Use the mappedName as the string value
+            String s = ref.mappedName().trim();
+            try
+            {
+               Object value = ValueConvertor.convertValue(type, s);
+               container.getEncInjectors().put(encName, new ValueEncInjector(encName, value, "@Resource"));
+               injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
+            }
+            catch(Throwable t)
+            {
+               throw new RuntimeException("Failed to convert: "+ref.mappedName()+" to type:"+type, t);
+            }
+         }
          else
          {
             log.warn("Not injecting " + field.getName() + ", no matching enc injector " + encName + " found");




More information about the jboss-cvs-commits mailing list