[jboss-cvs] JBossAS SVN: r69032 - in trunk: ejb3/src/main/org/jboss/injection and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 16 09:47:21 EST 2008


Author: heiko.braun at jboss.com
Date: 2008-01-16 09:47:21 -0500 (Wed, 16 Jan 2008)
New Revision: 69032

Modified:
   trunk/build/build-thirdparty.xml
   trunk/ejb3/src/main/org/jboss/injection/WebServiceRefHandler.java
Log:
Fix JBAS-5139: Support injection-target properties within service-ref declarations

Modified: trunk/build/build-thirdparty.xml
===================================================================
--- trunk/build/build-thirdparty.xml	2008-01-16 14:43:43 UTC (rev 69031)
+++ trunk/build/build-thirdparty.xml	2008-01-16 14:47:21 UTC (rev 69032)
@@ -102,7 +102,7 @@
     <componentref name="jboss/jbosssx-client" version="2.0.2.Beta4"/>
     <componentref name="jboss/jbossts" version="4.3.0.BETA2"/>
     <componentref name="jboss/jboss-vfs" version="2.0.0.Beta6"/>
-    <componentref name="jboss/jbossws-native50" version="2.0.2.GA"/>
+    <componentref name="jboss/jbossws-native50" version="snapshot"/>
     <componentref name="jboss/jbossxb" version="2.0.0.CR5"/>
     <componentref name="jboss/jms-integration-tests" version="1.0.1.GA"/>
     <componentref name="jboss/messaging" version="1.4.0.SP3a"/>

Modified: trunk/ejb3/src/main/org/jboss/injection/WebServiceRefHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/injection/WebServiceRefHandler.java	2008-01-16 14:43:43 UTC (rev 69031)
+++ trunk/ejb3/src/main/org/jboss/injection/WebServiceRefHandler.java	2008-01-16 14:47:21 UTC (rev 69032)
@@ -28,6 +28,7 @@
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Iterator;
 
 import javax.naming.Context;
 import javax.xml.ws.WebServiceRef;
@@ -35,9 +36,7 @@
 
 import org.jboss.logging.Logger;
 import org.jboss.metadata.javaee.jboss.JBossServiceReferenceMetaData;
-import org.jboss.metadata.javaee.spec.RemoteEnvironment;
-import org.jboss.metadata.javaee.spec.ServiceReferenceMetaData;
-import org.jboss.metadata.javaee.spec.ServiceReferencesMetaData;
+import org.jboss.metadata.javaee.spec.*;
 
 /**
  * Handle @WebServiceRef annotations
@@ -98,42 +97,125 @@
 
    public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
    {
-      WebServiceRef wsref = method.getAnnotation(WebServiceRef.class);
-      if (wsref == null) return;
+      String serviceRefName = null;
 
+      // injector first
+      ServiceReferenceMetaData tmp = getServiceRefForInjectionTarget(method);
+      if(tmp!=null)
+      {
+         serviceRefName = tmp.getServiceRefName();
+      }
+      else
+      {
+         // annotation second
+         WebServiceRef wsref = method.getAnnotation(WebServiceRef.class);
+         if(wsref!=null)
+         {
+            serviceRefName = wsref.name();
+
+            if (serviceRefName.equals(""))
+               serviceRefName = InjectionUtil.getEncName(method).substring(4);
+         }
+      }
+
+      if(null==serviceRefName)
+         return;
+
       if (!method.getName().startsWith("set"))
          throw new RuntimeException("@WebServiceRef can only be used with a set method: " + method);
 
-      String name = wsref.name();
-      if (name.equals(""))
-         name = InjectionUtil.getEncName(method).substring(4);
+      if (serviceRefName.equals(""))
+         serviceRefName = InjectionUtil.getEncName(method).substring(4);
       
-      String encName = "env/" + name;
+      String encName = "env/" + serviceRefName;
       Context encCtx = container.getEnc();
-      if (!container.getEncInjectors().containsKey(name))
+      if (!container.getEncInjectors().containsKey(serviceRefName))
       {
-         ServiceReferenceMetaData sref = getServiceRef(name);
-         container.getEncInjectors().put(name, new ServiceRefInjector(encName, method, sref));
+         ServiceReferenceMetaData sref = getServiceRef(serviceRefName);
+         container.getEncInjectors().put(serviceRefName, new ServiceRefInjector(encName, method, sref));
       }
 
       injectors.put(method, new JndiMethodInjector(method, encName, encCtx));
    }
 
+   private ServiceReferenceMetaData getServiceRefForInjectionTarget(Method method)
+   {
+      ServiceReferenceMetaData match = null;
+
+      Iterator<String> iterator = srefMap.keySet().iterator();
+      while(iterator.hasNext())
+      {
+         ServiceReferenceMetaData sref = srefMap.get(iterator.next());
+         for(ResourceInjectionTargetMetaData injectionTuple : sref.getInjectionTargets())
+         {
+            if(method.getDeclaringClass().getName().equals(injectionTuple.getInjectionTargetClass())
+              && method.getName().equals(injectionTuple.getInjectionTargetName()))
+            {
+               match = sref;
+               break;
+            }
+         }
+      }
+      return match;
+   }
+
+   private ServiceReferenceMetaData getServiceRefForInjectionTarget(Field field)
+   {
+      ServiceReferenceMetaData match = null;
+
+      Iterator<String> iterator = srefMap.keySet().iterator();
+      while(iterator.hasNext())
+      {
+         ServiceReferenceMetaData sref = srefMap.get(iterator.next());
+         for(ResourceInjectionTargetMetaData injectionTuple : sref.getInjectionTargets())
+         {
+            if(field.getDeclaringClass().getName().equals(injectionTuple.getInjectionTargetClass())
+              && field.getName().equals(injectionTuple.getInjectionTargetName()))
+            {
+               match = sref;
+               break;
+            }
+         }
+      }
+      return match;
+   }
+
    public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
    {
-      WebServiceRef wsref = field.getAnnotation(WebServiceRef.class);
-      if (wsref == null) return;
+      String serviceRefName = null;
 
-      String name = wsref.name();
-      if (name.equals(""))
-         name = InjectionUtil.getEncName(field).substring(4);
+      // injector first
+      ServiceReferenceMetaData tmp = getServiceRefForInjectionTarget(field);
+      if(tmp!=null)
+      {
+         serviceRefName = tmp.getServiceRefName();
+      }
+      else
+      {
+         // annotation second
+         WebServiceRef wsref = field.getAnnotation(WebServiceRef.class);
+         if(wsref!=null)
+         {
+            serviceRefName = wsref.name();
 
-      String encName = "env/" + name;
+            if (serviceRefName.equals(""))
+               serviceRefName = InjectionUtil.getEncName(field).substring(4);
+         }
+      }
+
+      if(null==serviceRefName)
+         return;
+
+
+      if (serviceRefName.equals(""))
+         serviceRefName = InjectionUtil.getEncName(field).substring(4);
+
+      String encName = "env/" + serviceRefName;
       Context encCtx = container.getEnc();
-      if (!container.getEncInjectors().containsKey(name))
+      if (!container.getEncInjectors().containsKey(serviceRefName))
       {
-         ServiceReferenceMetaData sref = getServiceRef(name);
-         container.getEncInjectors().put(name, new ServiceRefInjector(encName, field, sref));
+         ServiceReferenceMetaData sref = getServiceRef(serviceRefName);
+         container.getEncInjectors().put(serviceRefName, new ServiceRefInjector(encName, field, sref));
       }
 
       injectors.put(field, new JndiFieldInjector(field, encName, encCtx));




More information about the jboss-cvs-commits mailing list