geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r513941 - in /geronimo/server/trunk/modules: geronimo-j2ee-builder/ geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/ geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/
Date Fri, 02 Mar 2007 20:42:59 GMT
Author: djencks
Date: Fri Mar  2 12:42:57 2007
New Revision: 513941

URL: http://svn.apache.org/viewvc?view=rev&rev=513941
Log:
GERONIMO-2848 @WebServiceRef support

Added:
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/WebServiceRefAnnotationHelper.java   (with props)
Modified:
    geronimo/server/trunk/modules/geronimo-j2ee-builder/pom.xml
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/EJBAnnotationHelper.java
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/ResourceAnnotationHelper.java
    geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/SwitchingServiceRefBuilder.java

Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/pom.xml?view=diff&rev=513941&r1=513940&r2=513941
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/pom.xml (original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/pom.xml Fri Mar  2 12:42:57 2007
@@ -67,6 +67,11 @@
             <artifactId>asm</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.axis2</groupId>
+            <artifactId>axis2-jaxws-api</artifactId>
+        </dependency>
+
     </dependencies>
 
     <build>

Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/EJBAnnotationHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/EJBAnnotationHelper.java?view=diff&rev=513941&r1=513940&r2=513941
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/EJBAnnotationHelper.java (original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/EJBAnnotationHelper.java Fri Mar  2 12:42:57 2007
@@ -51,22 +51,22 @@
  * <strong>@EJB</strong> and <strong>@EJBs</strong> annotations to deployment descriptor tags. The
  * EJBAnnotationHelper class can be used as part of the deployment of a module into the Geronimo
  * server. It performs the following major functions:
- * <p/>
+ *
  * <ol>
  * <li>Translates annotations into corresponding deployment descriptor elements (so that the
  * actual deployment descriptor in the module can be updated or even created if necessary)
  * </ol>
- * <p/>
+ *
  * <p><strong>Note(s):</strong>
  * <ul>
  * <li>The user is responsible for invoking change to metadata-complete
  * <li>This helper class will validate any changes it makes to the deployment descriptor. An
  * exception will be thrown if it fails to parse
  * </ul>
- * <p/>
+ *
  * <p><strong>Remaining ToDo(s):</strong>
  * <ul>
- * <li>None
+ *      <li>Usage of mappedName
  * </ul>
  *
  * @version $Rev$ $Date$
@@ -84,7 +84,7 @@
 
 
     /**
-     * Determine if there are any @EJB, @EJBs annotations present
+     * Determine if there are any annotations present
      *
      * @return true or false
      */
@@ -96,7 +96,7 @@
 
 
     /**
-     * Process the @EJB, @EJBs annotations
+     * Process the annotations
      *
      * @return Updated deployment descriptor
      * @throws Exception if parsing or validation error
@@ -110,21 +110,20 @@
 
 
     /**
-     * Process @EJB annotations
+     * Process annotations
      *
      * @param annotatedApp
      * @param classFinder
      * @throws Exception
      */
     private static void processEJB(AnnotatedApp annotatedApp, ClassFinder classFinder) throws Exception {
-        log.debug("processEJB(): Entry");
+        log.debug("processEJB(): Entry: AnnotatedApp: " + annotatedApp.toString());
 
-        // Save the EJB lists
         List<Class> classesWithEJB = classFinder.findAnnotatedClasses(EJB.class);
         List<Method> methodsWithEJB = classFinder.findAnnotatedMethods(EJB.class);
         List<Field> fieldsWithEJB = classFinder.findAnnotatedFields(EJB.class);
 
-        // Class-level EJB
+        // Class-level annotation
         for (Class cls : classesWithEJB) {
             EJB ejb = (EJB) cls.getAnnotation(EJB.class);
             if (ejb != null) {
@@ -132,7 +131,7 @@
             }
         }
 
-        // Method-level EJB
+        // Method-level annotation
         for (Method method : methodsWithEJB) {
             EJB ejb = (EJB) method.getAnnotation(EJB.class);
             if (ejb != null) {
@@ -140,7 +139,7 @@
             }
         }
 
-        // Field-level EJB
+        // Field-level annotation
         for (Field field : fieldsWithEJB) {
             EJB ejb = (EJB) field.getAnnotation(EJB.class);
             if (ejb != null) {
@@ -156,7 +155,7 @@
 
 
     /**
-     * Process @EJBs annotations
+     * Process multiple annotations
      *
      * @param annotatedApp
      * @param classFinder
@@ -165,10 +164,9 @@
     private static void processEJBs(AnnotatedApp annotatedApp, ClassFinder classFinder) throws Exception {
         log.debug("processEJBs(): Entry");
 
-        // Save the EJBs list
         List<Class> classesWithEJBs = classFinder.findAnnotatedClasses(EJBs.class);
 
-        // Class-level EJBs
+        // Class-level annotation(s)
         List<EJB> ejbList = new ArrayList<EJB>();
         for (Class cls : classesWithEJBs) {
             EJBs ejbs = (EJBs) cls.getAnnotation(EJBs.class);
@@ -253,7 +251,7 @@
             log.debug("addEJB(): <ejb-local-ref> found");
 
             String localRefName = annotation.name();
-            if (localRefName.trim().equals("")) {
+            if (localRefName.equals("")) {
                 if (method != null) {
                     localRefName = method.getDeclaringClass().getName() + "/" + method.getName().substring(3);  // method should start with "set"
                 } else if (field != null) {
@@ -272,6 +270,8 @@
             if (!exists) {
                 try {
 
+                    log.debug("addEJB(): Does not exist in DD: " + localRefName);
+
                     // Doesn't exist in deployment descriptor -- add new
                     EjbLocalRefType ejbLocalRef = annotatedApp.addNewEjbLocalRef();
 
@@ -290,7 +290,7 @@
 
                     // local
                     String localAnnotation = interfce.getName();
-                    if (!localAnnotation.trim().equals("")) {
+                    if (!localAnnotation.equals("")) {
                         LocalType local = ejbLocalRef.addNewLocal();
                         local.setStringValue(localAnnotation);
                         ejbLocalRef.setLocal(local);
@@ -298,7 +298,7 @@
 
                     // ejb-link
                     String beanName = annotation.beanName();
-                    if (!beanName.trim().equals("")) {
+                    if (!beanName.equals("")) {
                         EjbLinkType ejbLink = ejbLocalRef.addNewEjbLink();
                         ejbLink.setStringValue(beanName);
                         ejbLocalRef.setEjbLink(ejbLink);
@@ -306,7 +306,7 @@
 
                     // mappedName
                     String mappdedNameAnnotation = annotation.mappedName();
-                    if (!mappdedNameAnnotation.trim().equals("")) {
+                    if (!mappdedNameAnnotation.equals("")) {
                         XsdStringType mappedName = ejbLocalRef.addNewMappedName();
                         mappedName.setStringValue(mappdedNameAnnotation);
                         ejbLocalRef.setMappedName(mappedName);
@@ -314,7 +314,7 @@
 
                     // description
                     String descriptionAnnotation = annotation.description();
-                    if (!descriptionAnnotation.trim().equals("")) {
+                    if (!descriptionAnnotation.equals("")) {
                         DescriptionType description = ejbLocalRef.addNewDescription();
                         description.setStringValue(descriptionAnnotation);
                     }
@@ -351,7 +351,7 @@
             log.debug("addEJB(): <ejb-ref> found");
 
             String remoteRefName = annotation.name();
-            if (remoteRefName.trim().equals("")) {
+            if (remoteRefName.equals("")) {
                 if (method != null) {
                     remoteRefName = method.getDeclaringClass().getName() + "/" + method.getName().substring(3); // method should start with "set"
                 } else if (field != null) {
@@ -370,6 +370,8 @@
             if (!exists) {
                 try {
 
+                    log.debug("addEJB(): Does not exist in DD: " + remoteRefName);
+
                     // Doesn't exist in deployment descriptor -- add new
                     EjbRefType ejbRef = annotatedApp.addNewEjbRef();
 
@@ -388,7 +390,7 @@
 
                     // remote
                     String remoteAnnotation = interfce.getName();
-                    if (!remoteAnnotation.trim().equals("")) {
+                    if (!remoteAnnotation.equals("")) {
                         RemoteType remote = ejbRef.addNewRemote();
                         remote.setStringValue(remoteAnnotation);
                         ejbRef.setRemote(remote);
@@ -396,7 +398,7 @@
 
                     // ejb-link
                     String beanName = annotation.beanName();
-                    if (!beanName.trim().equals("")) {
+                    if (!beanName.equals("")) {
                         EjbLinkType ejbLink = ejbRef.addNewEjbLink();
                         ejbLink.setStringValue(beanName);
                         ejbRef.setEjbLink(ejbLink);
@@ -404,7 +406,7 @@
 
                     // mappedName
                     String mappdedNameAnnotation = annotation.mappedName();
-                    if (!mappdedNameAnnotation.trim().equals("")) {
+                    if (!mappdedNameAnnotation.equals("")) {
                         XsdStringType mappedName = ejbRef.addNewMappedName();
                         mappedName.setStringValue(mappdedNameAnnotation);
                         ejbRef.setMappedName(mappedName);
@@ -412,7 +414,7 @@
 
                     // description
                     String descriptionAnnotation = annotation.description();
-                    if (!descriptionAnnotation.trim().equals("")) {
+                    if (!descriptionAnnotation.equals("")) {
                         DescriptionType description = ejbRef.addNewDescription();
                         description.setStringValue(descriptionAnnotation);
                     }
@@ -448,7 +450,7 @@
             log.debug("addEJB(): <UNKNOWN> found");
 
             String remoteRefName = annotation.name();
-            if (remoteRefName.trim().equals("")) {
+            if (remoteRefName.equals("")) {
                 if (method != null) {
                     remoteRefName = method.getDeclaringClass().getName() + "/" + method.getName().substring(3); // method should start with "set"
                 } else if (field != null) {
@@ -466,7 +468,10 @@
             }
             if (!exists) {
                 try {
-                    // Doesn't exist in deployment descriptor -- add to as an <ejb-ref> to the
+
+                    log.debug("addEJB(): Does not exist in DD: " + remoteRefName);
+
+                    // Doesn't exist in deployment descriptor -- add as an <ejb-ref> to the
                     // ambiguous list so that it can be resolved later
                     EjbRefType ejbRef = EjbRefType.Factory.newInstance();
                     annotatedApp.getAmbiguousEjbRefs().add(ejbRef);
@@ -486,7 +491,7 @@
 
                     // remote
                     String remoteAnnotation = interfce.getName();
-                    if (!remoteAnnotation.trim().equals("")) {
+                    if (!remoteAnnotation.equals("")) {
                         RemoteType remote = ejbRef.addNewRemote();
                         remote.setStringValue(remoteAnnotation);
                         ejbRef.setRemote(remote);
@@ -494,7 +499,7 @@
 
                     // ejb-link
                     String beanName = annotation.beanName();
-                    if (!beanName.trim().equals("")) {
+                    if (!beanName.equals("")) {
                         EjbLinkType ejbLink = ejbRef.addNewEjbLink();
                         ejbLink.setStringValue(beanName);
                         ejbRef.setEjbLink(ejbLink);
@@ -502,7 +507,7 @@
 
                     // mappedName
                     String mappdedNameAnnotation = annotation.mappedName();
-                    if (!mappdedNameAnnotation.trim().equals("")) {
+                    if (!mappdedNameAnnotation.equals("")) {
                         XsdStringType mappedName = ejbRef.addNewMappedName();
                         mappedName.setStringValue(mappdedNameAnnotation);
                         ejbRef.setMappedName(mappedName);
@@ -510,7 +515,7 @@
 
                     // description
                     String descriptionAnnotation = annotation.description();
-                    if (!descriptionAnnotation.trim().equals("")) {
+                    if (!descriptionAnnotation.equals("")) {
                         DescriptionType description = ejbRef.addNewDescription();
                         description.setStringValue(descriptionAnnotation);
                     }

Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/ResourceAnnotationHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/ResourceAnnotationHelper.java?view=diff&rev=513941&r1=513940&r2=513941
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/ResourceAnnotationHelper.java (original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/ResourceAnnotationHelper.java Fri Mar  2 12:42:57 2007
@@ -53,22 +53,22 @@
  * <strong>@Resource</strong> and <strong>@Resources</strong> annotations to deployment descriptor
  * tags. The ResourceAnnotationHelper class can be used as part of the deployment of a module into
  * the Geronimo server. It performs the following major functions:
- * <p/>
+ *
  * <ol>
- * <li>Translates annotations into corresponding deployment descriptor elements (so that the
- * actual deployment descriptor in the module can be updated or even created if necessary)
+ *      <li>Translates annotations into corresponding deployment descriptor elements (so that the
+ *      actual deployment descriptor in the module can be updated or even created if necessary)
  * </ol>
- * <p/>
+ *
  * <p><strong>Note(s):</strong>
  * <ul>
- * <li>The user is responsible for invoking change to metadata-complete
- * <li>This helper class will validate any changes it makes to the deployment descriptor. An
- * exception will be thrown if it fails to parse
+ *      <li>The user is responsible for invoking change to metadata-complete
+ *      <li>This helper class will validate any changes it makes to the deployment descriptor. An
+ *      exception will be thrown if it fails to parse
  * </ul>
- * <p/>
+ *
  * <p><strong>Remaining ToDo(s):</strong>
  * <ul>
- * <li>None
+ *      <li>Usage of mappedName
  * </ul>
  *
  * @version $Rev$ $Date$
@@ -85,7 +85,7 @@
 
 
     /**
-     * Determine if there are any Resource annotations present
+     * Determine if there are any annotations present
      *
      * @return true or false
      */
@@ -96,7 +96,7 @@
     }
 
     /**
-     * Process the Resource set of annotations
+     * Process the annotations
      *
      * @return Updated deployment descriptor
      * @throws Exception if parsing or validation error
@@ -110,24 +110,20 @@
 
 
     /**
-     * Process @Resource annotations
+     * Process annotations
      *
-     * @return
+     * @param annotatedApp
+     * @param classFinder
      * @throws Exception
      */
     private static void processResource(AnnotatedApp annotatedApp, ClassFinder classFinder) throws Exception {
         log.debug("processResource(): Entry: AnnotatedApp: " + annotatedApp.toString());
 
-        //-----------------------------
-        // Save the Resource lists
-        //-----------------------------
         List<Class> classeswithResource = classFinder.findAnnotatedClasses(Resource.class);
         List<Method> methodswithResource = classFinder.findAnnotatedMethods(Resource.class);
         List<Field> fieldswithResource = classFinder.findAnnotatedFields(Resource.class);
 
-        //--------------------------
-        // Class-level Resource
-        //--------------------------
+        // Class-level annotation
         for (Class cls : classeswithResource) {
             Resource resource = (Resource) cls.getAnnotation(Resource.class);
             if (resource != null) {
@@ -135,9 +131,7 @@
             }
         }
 
-        //---------------------------
-        // Method-level Resource
-        //---------------------------
+        // Method-level annotation
         for (Method method : methodswithResource) {
             Resource resource = (Resource) method.getAnnotation(Resource.class);
             if (resource != null) {
@@ -145,9 +139,7 @@
             }
         }
 
-        //--------------------------
-        // Field-level Resource
-        //--------------------------
+        // Field-level annotation
         for (Field field : fieldswithResource) {
             Resource resource = (Resource) field.getAnnotation(Resource.class);
             if (resource != null) {
@@ -155,9 +147,7 @@
             }
         }
 
-        //--------------------------------------------------------------
         // Validate deployment descriptor to ensure it's still okay
-        //--------------------------------------------------------------
         validateDD(annotatedApp);
 
         log.debug("processResource(): Exit: AnnotatedApp: " + annotatedApp.toString());
@@ -165,29 +155,28 @@
 
 
     /**
-     * Process @Resources annotations
+     * Process multiple annotations
+     *
+     * @param annotatedApp
+     * @param classFinder
+     * @exception Exception
      */
     private static void processResources(AnnotatedApp annotatedApp, ClassFinder classFinder) throws Exception {
         log.debug("processResources(): Entry");
 
-        //-----------------------------
-        // Save the Resources list
-        //-----------------------------
         List<Class> classeswithResources = classFinder.findAnnotatedClasses(Resources.class);
 
-        //---------------------------
-        // Class-level Resources
-        //---------------------------
-        List<Resource> ResourceList = new ArrayList<Resource>();
+        // Class-level annotation(s)
+        List<Resource> resourceList = new ArrayList<Resource>();
         for (Class cls : classeswithResources) {
             Resources resources = (Resources) cls.getAnnotation(Resources.class);
             if (resources != null) {
-                ResourceList.addAll(Arrays.asList(resources.value()));
+                resourceList.addAll(Arrays.asList(resources.value()));
             }
-            for (Resource resource : ResourceList) {
+            for (Resource resource : resourceList) {
                 addResource(annotatedApp, resource, cls, null, null);
             }
-            ResourceList.clear();
+            resourceList.clear();
         }
 
         log.debug("processResources(): Exit");
@@ -201,7 +190,7 @@
      * <p/>
      * <ol>
      * <li><env-entry> -- Used to declare an application's environment entry
-     * <li><service-ref> -- Declares a reference to a Web service
+     * <li><service-ref> -- Declares a reference to a Web Service
      * <li><resource-ref> -- Contains a declaration of a Deployment Component's reference to an
      * external resource
      * <li><message-destination-ref> -- Contains a declaration of Deployment Component's
@@ -232,11 +221,12 @@
 
         //------------------------------------------------------------------------------------------
         // Resource name:
-        // -- When annotation is applied on a class:    name must be provided (cannot be inferred)
-        // -- When annotation is applied on a method:   name is JavaBeans property name qualified by
-        //                                              the class (or as provided on the annotation)
-        // -- When annotation is applied on a field:    name is the field name qualified by the class
-        //                                              (or as provided on the annotation)
+        // -- When annotation is applied on a class:    Name must be provided (cannot be inferred)
+        // -- When annotation is applied on a method:   Name is JavaBeans property name qualified
+        //                                              by the class (or as provided on the
+        //                                              annotation)
+        // -- When annotation is applied on a field:    Name is the field name qualified by the
+        //                                              class (or as provided on the annotation)
         //------------------------------------------------------------------------------------------
         String resourceName = annotation.name();
         if (resourceName.equals("")) {
@@ -252,11 +242,11 @@
 
         //------------------------------------------------------------------------------------------
         // Resource type:
-        // -- When annotation is applied on a class:    type must be provided (cannot be inferred)
-        // -- When annotation is applied on a method:   type is the JavaBeans property type (or as
+        // -- When annotation is applied on a class:    Type must be provided (cannot be inferred)
+        // -- When annotation is applied on a method:   Type is the JavaBeans property type (or as
         //                                              provided on the annotation)
-        // -- When annotation is applied on a field:    type is the field type (or as provided on the
-        //                                              annotation)
+        // -- When annotation is applied on a field:    Type is the field type (or as provided on
+        //                                              the annotation)
         //------------------------------------------------------------------------------------------
         String resourceType = annotation.type().getCanonicalName();
         if (resourceType.equals("") || resourceType.equals(Object.class.getName())) {
@@ -313,7 +303,7 @@
             boolean exists = false;
             EnvEntryType[] envEntries = annotatedApp.getEnvEntryArray();
             for (EnvEntryType envEntry : envEntries) {
-                if (envEntry.getEnvEntryName().getStringValue().equals(resourceName)) {
+                if (envEntry.getEnvEntryName().getStringValue().trim().equals(resourceName)) {
                     exists = true;
                     break;
                 }
@@ -321,6 +311,8 @@
             if (!exists) {
                 try {
 
+                    log.debug("addResource(): Does not exist in DD: " + resourceName);
+
                     // Doesn't exist in deployment descriptor -- add new
                     EnvEntryType envEntry = annotatedApp.addNewEnvEntry();
 
@@ -352,7 +344,7 @@
 
                     // description
                     String descriptionAnnotation = annotation.description();
-                    if (descriptionAnnotation != null && descriptionAnnotation.length() > 0) {
+                    if ( !descriptionAnnotation.equals("") ) {
                         DescriptionType description = envEntry.addNewDescription();
                         description.setStringValue(descriptionAnnotation);
                     }
@@ -374,7 +366,7 @@
             boolean exists = false;
             ServiceRefType[] serviceRefs = annotatedApp.getServiceRefArray();
             for (ServiceRefType serviceRef : serviceRefs) {
-                if (serviceRef.getServiceRefName().getStringValue().equals(resourceName)) {
+                if (serviceRef.getServiceRefName().getStringValue().trim().equals(resourceName)) {
                     exists = true;
                     break;
                 }
@@ -382,6 +374,8 @@
             if (!exists) {
                 try {
 
+                    log.debug("addResource(): Does not exist in DD: " + resourceName);
+
                     // Doesn't exist in deployment descriptor -- add new
                     ServiceRefType serviceRef = annotatedApp.addNewServiceRef();
 
@@ -397,6 +391,7 @@
                         // service-ref-type
                         FullyQualifiedClassType qualifiedClass = serviceRef.addNewServiceInterface();
                         qualifiedClass.setStringValue(resourceType);
+                        serviceRef.setServiceInterface(qualifiedClass);
                     } else if (!injectionJavaType.equals("")) {
                         // injectionTarget
                         InjectionTargetType injectionTarget = serviceRef.addNewInjectionTarget();
@@ -409,16 +404,16 @@
 
                     // description
                     String descriptionAnnotation = annotation.description();
-                    if (descriptionAnnotation.length() > 0) {
+                    if (!descriptionAnnotation.equals("")) {
                         DescriptionType description = serviceRef.addNewDescription();
                         description.setStringValue(descriptionAnnotation);
                     }
 
                     // WSDL document location
                     String documentAnnotation = annotation.mappedName();
-                    if (documentAnnotation.length() > 0) {
-                        XsdAnyURIType wsdlFile = XsdAnyURIType.Factory.newInstance();
-                        wsdlFile.setStringValue(annotation.mappedName());
+                    if ( !documentAnnotation.equals("") ) {
+                        XsdAnyURIType wsdlFile = serviceRef.addNewWsdlFile();
+                        wsdlFile.setStringValue(documentAnnotation);
                         serviceRef.setWsdlFile(wsdlFile);
                     }
 
@@ -448,7 +443,7 @@
             boolean exists = false;
             ResourceRefType[] resourceRefs = annotatedApp.getResourceRefArray();
             for (ResourceRefType resourceRef : resourceRefs) {
-                if (resourceRef.getResRefName().getStringValue().equals(resourceName)) {
+                if (resourceRef.getResRefName().getStringValue().trim().equals(resourceName)) {
                     exists = true;
                     break;
                 }
@@ -456,6 +451,8 @@
             if (!exists) {
                 try {
 
+                    log.debug("addResource(): Does not exist in DD: " + resourceName);
+
                     // Doesn't exist in deployment descriptor -- add new
                     ResourceRefType resourceRef = annotatedApp.addNewResourceRef();
 
@@ -464,27 +461,19 @@
                     //------------------------------------------------------------------------------
 
                     // resource-ref-name
-                    JndiNameType resourceRefName = JndiNameType.Factory.newInstance();
+                    JndiNameType resourceRefName = resourceRef.addNewResRefName();
                     resourceRefName.setStringValue(resourceName);
                     resourceRef.setResRefName(resourceRefName);
 
                     if (!resourceType.equals("")) {
                         // resource-ref-type
-                        FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
+                        FullyQualifiedClassType qualifiedClass = resourceRef.addNewResType();
                         qualifiedClass.setStringValue(resourceType);
                         resourceRef.setResType(qualifiedClass);
                     } else if (!injectionJavaType.equals("")) {
                         // injectionTarget
-                        InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
-                        FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
-                        JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
-                        qualifiedClass.setStringValue(injectionClass);
-                        javaType.setStringValue(injectionJavaType);
-                        injectionTarget.setInjectionTargetClass(qualifiedClass);
-                        injectionTarget.setInjectionTargetName(javaType);
-                        int arraySize = resourceRef.sizeOfInjectionTargetArray();
-                        resourceRef.insertNewInjectionTarget(arraySize);
-                        resourceRef.setInjectionTargetArray(arraySize, injectionTarget);
+                        InjectionTargetType injectionTarget = resourceRef.addNewInjectionTarget();
+                        configureInjectionTarget(injectionTarget, injectionClass, injectionJavaType);
                     }
 
                     //------------------------------------------------------------------------------
@@ -493,32 +482,32 @@
 
                     // description
                     String descriptionAnnotation = annotation.description();
-                    if (descriptionAnnotation.length() > 0) {
-                        DescriptionType description = DescriptionType.Factory.newInstance();
+                    if ( !descriptionAnnotation.equals("") ) {
+                        DescriptionType description = resourceRef.addNewDescription();
                         description.setStringValue(descriptionAnnotation);
-                        int arraySize = resourceRef.sizeOfDescriptionArray();
-                        resourceRef.insertNewDescription(arraySize);
-                        resourceRef.setDescriptionArray(arraySize, description);
                     }
 
                     // authentication
-                    ResAuthType resAuth = ResAuthType.Factory.newInstance();
                     if (annotation.authenticationType() == Resource.AuthenticationType.CONTAINER) {
+                        ResAuthType resAuth = resourceRef.addNewResAuth();
                         resAuth.setStringValue("Container");
-                    } else if (annotation.authenticationType() == Resource.AuthenticationType.APPLICATION) {
+                        resourceRef.setResAuth(resAuth);
+                    }
+                    else if (annotation.authenticationType() == Resource.AuthenticationType.APPLICATION) {
+                        ResAuthType resAuth = resourceRef.addNewResAuth();
                         resAuth.setStringValue("Application");
+                        resourceRef.setResAuth(resAuth);
                     }
-                    resourceRef.setResAuth(resAuth);
 
                     // sharing scope
-                    ResSharingScopeType resScope = ResSharingScopeType.Factory.newInstance();
+                    ResSharingScopeType resScope = resourceRef.addNewResSharingScope();
                     resScope.setStringValue(annotation.shareable() ? "Shareable" : "Unshareable");
                     resourceRef.setResSharingScope(resScope);
 
                     // mappedName
                     String mappdedNameAnnotation = annotation.mappedName();
-                    if (mappdedNameAnnotation.length() > 0) {
-                        XsdStringType mappedName = XsdStringType.Factory.newInstance();
+                    if (!mappdedNameAnnotation.equals("") ) {
+                        XsdStringType mappedName = resourceRef.addNewMappedName();
                         mappedName.setStringValue(mappdedNameAnnotation);
                         resourceRef.setMappedName(mappedName);
                     }
@@ -542,7 +531,7 @@
             boolean exists = false;
             MessageDestinationRefType[] messageDestinationRefs = annotatedApp.getMessageDestinationRefArray();
             for (MessageDestinationRefType messageDestinationRef : messageDestinationRefs) {
-                if (messageDestinationRef.getMessageDestinationRefName().getStringValue().equals(resourceName)) {
+                if (messageDestinationRef.getMessageDestinationRefName().getStringValue().trim().equals(resourceName)) {
                     exists = true;
                     break;
                 }
@@ -550,6 +539,8 @@
             if (!exists) {
                 try {
 
+                    log.debug("addResource(): Does not exist in DD: " + resourceName);
+
                     // Doesn't exist in deployment descriptor -- add new
                     MessageDestinationRefType messageDestinationRef = annotatedApp.addNewMessageDestinationRef();
 
@@ -558,27 +549,19 @@
                     //------------------------------------------------------------------------------
 
                     // message-destination-ref-name
-                    JndiNameType messageDestinationRefName = JndiNameType.Factory.newInstance();
+                    JndiNameType messageDestinationRefName = messageDestinationRef.addNewMessageDestinationRefName();
                     messageDestinationRefName.setStringValue(resourceName);
                     messageDestinationRef.setMessageDestinationRefName(messageDestinationRefName);
 
                     if (!resourceType.equals("")) {
                         // message-destination-ref-type
-                        MessageDestinationTypeType msgDestType = MessageDestinationTypeType.Factory.newInstance();
+                        MessageDestinationTypeType msgDestType = messageDestinationRef.addNewMessageDestinationType();
                         msgDestType.setStringValue(resourceType);
                         messageDestinationRef.setMessageDestinationType(msgDestType);
                     } else if (!injectionJavaType.equals("")) {
                         // injectionTarget
-                        InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
-                        FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
-                        JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
-                        qualifiedClass.setStringValue(injectionClass);
-                        javaType.setStringValue(injectionJavaType);
-                        injectionTarget.setInjectionTargetClass(qualifiedClass);
-                        injectionTarget.setInjectionTargetName(javaType);
-                        int arraySize = messageDestinationRef.sizeOfInjectionTargetArray();
-                        messageDestinationRef.insertNewInjectionTarget(arraySize);
-                        messageDestinationRef.setInjectionTargetArray(arraySize, injectionTarget);
+                        InjectionTargetType injectionTarget = messageDestinationRef.addNewInjectionTarget();
+                        configureInjectionTarget(injectionTarget, injectionClass, injectionJavaType);
                     }
 
                     //------------------------------------------------------------------------------
@@ -587,18 +570,15 @@
 
                     // description
                     String descriptionAnnotation = annotation.description();
-                    if (descriptionAnnotation.length() > 0) {
-                        DescriptionType description = DescriptionType.Factory.newInstance();
+                    if ( !descriptionAnnotation.equals("") ) {
+                        DescriptionType description = messageDestinationRef.addNewDescription();
                         description.setStringValue(descriptionAnnotation);
-                        int arraySize = messageDestinationRef.sizeOfDescriptionArray();
-                        messageDestinationRef.insertNewDescription(arraySize);
-                        messageDestinationRef.setDescriptionArray(arraySize, description);
                     }
 
                     // mappedName
                     String mappdedNameAnnotation = annotation.mappedName();
-                    if (mappdedNameAnnotation.length() > 0) {
-                        XsdStringType mappedName = XsdStringType.Factory.newInstance();
+                    if (!mappdedNameAnnotation.equals("") ) {
+                        XsdStringType mappedName = messageDestinationRef.addNewMappedName();
                         mappedName.setStringValue(mappdedNameAnnotation);
                         messageDestinationRef.setMappedName(mappedName);
                     }
@@ -622,7 +602,7 @@
             boolean exists = false;
             ResourceEnvRefType[] resourceEnvRefs = annotatedApp.getResourceEnvRefArray();
             for (ResourceEnvRefType resourceEnvRef : resourceEnvRefs) {
-                if (resourceEnvRef.getResourceEnvRefName().getStringValue().equals(resourceName)) {
+                if (resourceEnvRef.getResourceEnvRefName().getStringValue().trim().equals(resourceName)) {
                     exists = true;
                     break;
                 }
@@ -630,6 +610,8 @@
             if (!exists) {
                 try {
 
+                    log.debug("addResource(): Does not exist in DD: " + resourceName);
+
                     // Doesn't exist in deployment descriptor -- add new
                     ResourceEnvRefType resourceEnvRef = annotatedApp.addNewResourceEnvRef();
 
@@ -638,27 +620,19 @@
                     //------------------------------------------------------------------------------
 
                     // resource-env-ref-name
-                    JndiNameType resourceEnvRefName = JndiNameType.Factory.newInstance();
+                    JndiNameType resourceEnvRefName = resourceEnvRef.addNewResourceEnvRefName();
                     resourceEnvRefName.setStringValue(resourceName);
                     resourceEnvRef.setResourceEnvRefName(resourceEnvRefName);
 
                     if (!resourceType.equals("")) {
                         // resource-env-ref-type
-                        FullyQualifiedClassType classType = FullyQualifiedClassType.Factory.newInstance();
-                        classType.setStringValue(resourceType);
-                        resourceEnvRef.setResourceEnvRefType(classType);
+                        FullyQualifiedClassType qualifiedClass = resourceEnvRef.addNewResourceEnvRefType();
+                        qualifiedClass.setStringValue(resourceType);
+                        resourceEnvRef.setResourceEnvRefType(qualifiedClass);
                     } else if (!injectionJavaType.equals("")) {
                         // injectionTarget
-                        InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
-                        FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
-                        JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
-                        qualifiedClass.setStringValue(injectionClass);
-                        javaType.setStringValue(injectionJavaType);
-                        injectionTarget.setInjectionTargetClass(qualifiedClass);
-                        injectionTarget.setInjectionTargetName(javaType);
-                        int arraySize = resourceEnvRef.sizeOfInjectionTargetArray();
-                        resourceEnvRef.insertNewInjectionTarget(arraySize);
-                        resourceEnvRef.setInjectionTargetArray(arraySize, injectionTarget);
+                        InjectionTargetType injectionTarget = resourceEnvRef.addNewInjectionTarget();
+                        configureInjectionTarget(injectionTarget, injectionClass, injectionJavaType);
                     }
 
                     //------------------------------------------------------------------------------
@@ -667,18 +641,15 @@
 
                     // description
                     String descriptionAnnotation = annotation.description();
-                    if (descriptionAnnotation.length() > 0) {
-                        DescriptionType description = DescriptionType.Factory.newInstance();
+                    if ( !descriptionAnnotation.equals("") ) {
+                        DescriptionType description = resourceEnvRef.addNewDescription();
                         description.setStringValue(descriptionAnnotation);
-                        int arraySize = resourceEnvRef.sizeOfDescriptionArray();
-                        resourceEnvRef.insertNewDescription(arraySize);
-                        resourceEnvRef.setDescriptionArray(arraySize, description);
                     }
 
                     // mappedName
                     String mappdedNameAnnotation = annotation.mappedName();
-                    if (mappdedNameAnnotation.length() > 0) {
-                        XsdStringType mappedName = XsdStringType.Factory.newInstance();
+                    if (!mappdedNameAnnotation.equals("") ) {
+                        XsdStringType mappedName = resourceEnvRef.addNewMappedName();
                         mappedName.setStringValue(mappdedNameAnnotation);
                         resourceEnvRef.setMappedName(mappedName);
                     }
@@ -693,13 +664,25 @@
         log.debug("addResource(): Exit");
     }
 
+
+    /**
+     * Configure Injection Target
+     *
+     * @param injectionTarget
+     * @param injectionClass
+     * @param injectionJavaType
+     */
     private static void configureInjectionTarget(InjectionTargetType injectionTarget, String injectionClass, String injectionJavaType) {
+        log.debug("configureInjectionTarget(): Entry");
+
         FullyQualifiedClassType qualifiedClass = injectionTarget.addNewInjectionTargetClass();
         JavaIdentifierType javaType = injectionTarget.addNewInjectionTargetName();
         qualifiedClass.setStringValue(injectionClass);
         javaType.setStringValue(injectionJavaType);
         injectionTarget.setInjectionTargetClass(qualifiedClass);
         injectionTarget.setInjectionTargetName(javaType);
+
+        log.debug("configureInjectionTarget(): Exit");
     }
 
 

Added: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/WebServiceRefAnnotationHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/WebServiceRefAnnotationHelper.java?view=auto&rev=513941
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/WebServiceRefAnnotationHelper.java (added)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/WebServiceRefAnnotationHelper.java Fri Mar  2 12:42:57 2007
@@ -0,0 +1,361 @@
+/**
+ * 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.j2ee.deployment.annotation;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.ws.WebServiceRef;
+import javax.xml.ws.WebServiceRefs;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
+import org.apache.geronimo.xbeans.javaee.FullyQualifiedClassType;
+import org.apache.geronimo.xbeans.javaee.InjectionTargetType;
+import org.apache.geronimo.xbeans.javaee.JavaIdentifierType;
+import org.apache.geronimo.xbeans.javaee.JndiNameType;
+import org.apache.geronimo.xbeans.javaee.ServiceRefType;
+import org.apache.geronimo.xbeans.javaee.XsdAnyURIType;
+import org.apache.xbean.finder.ClassFinder;
+
+
+/**
+ * Static helper class used to encapsulate all the functions related to the translation of
+ * <strong>@WebServieRef</strong> and <strong>@WebServieRef</strong> annotations to deployment
+ * descriptor tags. The WebServiceRefAnnotationHelper class can be used as part of the deployment of
+ * a module into the Geronimo server. It performs the following major functions:
+ *
+ * <ol>
+ *      <li>Translates annotations into corresponding deployment descriptor elements (so that the
+ *      actual deployment descriptor in the module can be updated or even created if necessary)
+ * </ol>
+ *
+ * <p><strong>Note(s):</strong>
+ * <ul>
+ *      <li>The user is responsible for invoking change to metadata-complete
+ *      <li>This helper class will validate any changes it makes to the deployment descriptor. An
+ *      exception will be thrown if it fails to parse
+ * </ul>
+ *
+ * <p><strong>Remaining ToDo(s):</strong>
+ * <ul>
+ *      <li>None
+ * </ul>
+ *
+ * @version $Rev $Date
+ * @since 03-2007
+ */
+public final class WebServiceRefAnnotationHelper {
+
+    // Private instance variables
+    private static final Log log = LogFactory.getLog(WebServiceRefAnnotationHelper.class);
+
+    // Private constructor to prevent instantiation
+    private WebServiceRefAnnotationHelper() {
+    }
+
+
+    /**
+     * Determine if there are any annotations present
+     *
+     * @return true or false
+     */
+    public static boolean annotationsPresent(ClassFinder classFinder) {
+        if ( classFinder.isAnnotationPresent(WebServiceRef.class) ) return true;
+        if ( classFinder.isAnnotationPresent(WebServiceRefs.class) ) return true;
+        return false;
+    }
+
+    /**
+     * Process the annotations
+     *
+     * @return Updated deployment descriptor
+     * @throws Exception if parsing or validation error
+     */
+    public static void processAnnotations(AnnotatedApp annotatedApp, ClassFinder classFinder) throws Exception {
+        if ( annotatedApp != null ) {
+            processWebServiceRefs(annotatedApp, classFinder);
+            processWebServiceRef(annotatedApp, classFinder);
+        }
+    }
+
+
+    /**
+     * Process annotations
+     *
+     * @param annotatedApp
+     * @param classFinder
+     * @throws Exception
+     */
+    private static void processWebServiceRef(AnnotatedApp annotatedApp, ClassFinder classFinder) throws Exception {
+        log.debug("processWebServiceRef(): Entry: AnnotatedApp: " + annotatedApp.toString());
+
+        List<Class> classeswithWebServiceRef = classFinder.findAnnotatedClasses(WebServiceRef.class);
+        List<Method> methodswithWebServiceRef = classFinder.findAnnotatedMethods(WebServiceRef.class);
+        List<Field> fieldswithWebServiceRef = classFinder.findAnnotatedFields(WebServiceRef.class);
+
+        // Class-level annotation
+        for ( Class cls : classeswithWebServiceRef ) {
+            WebServiceRef webServiceRef = (WebServiceRef) cls.getAnnotation(WebServiceRef.class);
+            if ( webServiceRef != null ) {
+                addWebServiceRef(annotatedApp, webServiceRef, cls, null, null);
+            }
+        }
+
+        // Method-level annotation
+        for ( Method method : methodswithWebServiceRef ) {
+            WebServiceRef webServiceRef = (WebServiceRef) method.getAnnotation(WebServiceRef.class);
+            if ( webServiceRef != null ) {
+                addWebServiceRef(annotatedApp, webServiceRef, null, method, null);
+            }
+        }
+
+        // Field-level annotation
+        for ( Field field : fieldswithWebServiceRef ) {
+            WebServiceRef webServiceRef = (WebServiceRef) field.getAnnotation(WebServiceRef.class);
+            if ( webServiceRef != null ) {
+                addWebServiceRef(annotatedApp, webServiceRef, null, null, field);
+            }
+        }
+
+        // Validate deployment descriptor to ensure it's still okay
+        validateDD(annotatedApp);
+
+        log.debug("processWebServiceRef(): Exit: AnnotatedApp: " + annotatedApp.toString());
+    }
+
+
+    /**
+     * Process multiple annotations
+     *
+     * @param annotatedApp
+     * @param classFinder
+     * @exception Exception
+     */
+    private static void processWebServiceRefs(AnnotatedApp annotatedApp, ClassFinder classFinder) throws Exception {
+        log.debug("processWebServiceRefs(): Entry");
+
+        List<Class> classeswithWebServiceRefs = classFinder.findAnnotatedClasses(WebServiceRefs.class);
+
+        // Class-level annotation(s)
+        List<WebServiceRef> webServiceRefList = new ArrayList<WebServiceRef>();
+        for ( Class cls : classeswithWebServiceRefs ) {
+            WebServiceRefs webServiceRefs = (WebServiceRefs) cls.getAnnotation(WebServiceRefs.class);
+            if ( webServiceRefs != null ) {
+                webServiceRefList.addAll(Arrays.asList(webServiceRefs.value()));
+            }
+            for ( WebServiceRef webServiceRef : webServiceRefList ) {
+                addWebServiceRef(annotatedApp, webServiceRef, cls, null, null);
+            }
+            webServiceRefList.clear();
+        }
+
+        log.debug("processWebServiceRefs(): Exit");
+    }
+
+
+    /**
+     * Add @WebServiceRef and @WebServiceRefs annotations to the deployment descriptor. XMLBeans are used to
+     * read and manipulate the deployment descriptor as necessary. The WebServiceRef annotation(s) will be
+     * converted to one of the following deployment descriptors:
+     *
+     * <ol>
+     *      <li><service-ref> -- Declares a reference to a Web Service
+     * </ol>
+     *
+     * <p><strong>Note(s):</strong>
+     * <ul>
+     *      <li>The deployment descriptor is the authoritative source so this method ensures that
+     *      existing elements in it are not overwritten by annoations
+     * </ul>
+     *
+     * @param annotation @WebServiceRef annotation
+     * @param cls        Class name with the @WebServiceRef annoation
+     * @param method     Method name with the @WebServiceRef annoation
+     * @param field      Field name with the @WebServiceRef annoation
+     */
+    private static void addWebServiceRef(AnnotatedApp annotatedApp, WebServiceRef annotation, Class cls, Method method, Field field) {
+        log.debug("addWebServiceRef( " + annotatedApp.toString() + "," + '\n' +
+                           annotation.name() + "," + '\n' +
+                           (cls != null ? cls.getName() : null) + "," + '\n' +
+                           (method != null ? method.getName() : null) + "," + '\n' +
+                           (field != null ? field.getName() : null) + " ): Entry");
+
+        //------------------------------------------------------------------------------------------
+        // WebServiceRef name:
+        // -- When annotation is applied on a class:    Name must be provided (cannot be inferred)
+        // -- When annotation is applied on a method:   Name is JavaBeans property name qualified
+        //                                              by the class (or as provided on the
+        //                                              annotation)
+        // -- When annotation is applied on a field:    Name is the field name qualified by the
+        //                                              class (or as provided on the annotation)
+        //------------------------------------------------------------------------------------------
+        String webServiceRefName = annotation.name();
+        if ( webServiceRefName.equals("") ) {
+            if ( method != null ) {
+                StringBuilder stringBuilder = new StringBuilder(method.getName().substring(3));
+                stringBuilder.setCharAt(0, Character.toLowerCase(stringBuilder.charAt(0)));
+                webServiceRefName = method.getDeclaringClass().getName() + "/" + stringBuilder.toString();
+            }
+            else if ( field != null ) {
+                webServiceRefName = field.getDeclaringClass().getName() + "/" + field.getName();
+            }
+        }
+        log.debug("addWebServiceRef(): webServiceRefName: " + webServiceRefName);
+
+        //------------------------------------------------------------------------------------------
+        // WebServiceRef types:
+        //
+        // 1. Generated Service Class (extends javax.xml.ws.Service)
+        // 2. Service Endpoint Interface (SEI)
+        //
+        // -- When annotation is applied on a class:    Type and Value must be provided (cannot be
+        //                                              inferred)
+        // -- When annotation is applied on a method:   Type is the JavaBeans property type (or as
+        //                                              provided on the annotation)
+        // -- When annotation is applied on a field:    Type is the field type (or as provided on
+        //                                              the annotation)
+        //------------------------------------------------------------------------------------------
+        String webServiceRefType = annotation.type().getCanonicalName();
+        Class webServiceRefValue = annotation.value().getClass();
+        if (webServiceRefType.equals("") || webServiceRefType.equals(Object.class.getName())) {
+            if (method != null) {
+                webServiceRefType = method.getParameterTypes()[0].getCanonicalName();
+            }
+            else if (field != null) {
+                webServiceRefType = field.getType().getName();
+            }
+        }
+        log.debug("addWebServiceRef(): webServiceRefType: " + webServiceRefType);
+        log.debug("addWebServiceRef(): webServiceRefValue: " + webServiceRefValue);
+
+        //------------------------------------------------------------------------------------------
+        // Method name (for setter-based injection) must follow JavaBeans conventions:
+        // -- Must start with "set"
+        // -- Have one parameter
+        // -- Return void
+        //------------------------------------------------------------------------------------------
+        String injectionJavaType = "";
+        String injectionClass = null;
+        if ( method != null ) {
+            injectionJavaType = method.getName().substring(3);
+            StringBuilder stringBuilder = new StringBuilder(injectionJavaType);
+            stringBuilder.setCharAt(0, Character.toLowerCase(stringBuilder.charAt(0)));
+            injectionJavaType = stringBuilder.toString();
+            injectionClass = method.getDeclaringClass().getName();
+        }
+        else if ( field != null ) {
+            injectionJavaType = field.getName();
+            injectionClass = field.getDeclaringClass().getName();
+        }
+        log.debug("addWebServiceRef(): injectionJavaType: " + injectionJavaType);
+        log.debug("addWebServiceRef(): injectionClass   : " + injectionClass);
+
+
+        //------------------------------------------------------------------------------------------
+        // 1. <service-ref>
+        //------------------------------------------------------------------------------------------
+        boolean exists = false;
+        ServiceRefType[] serviceRefs = annotatedApp.getServiceRefArray();
+        for ( ServiceRefType serviceRef : serviceRefs ) {
+            if ( serviceRef.getServiceRefName().getStringValue().trim().equals(webServiceRefName) ) {
+                exists = true;
+                break;
+            }
+        }
+        if ( !exists ) {
+            try {
+
+                log.debug("addWebServiceRef(): Does not exist in DD: " + webServiceRefName);
+
+                // Doesn't exist in deployment descriptor -- add new
+                ServiceRefType serviceRef = annotatedApp.addNewServiceRef();
+
+                //------------------------------------------------------------------------------
+                // <service-ref> required elements:
+                //------------------------------------------------------------------------------
+
+                // service-ref-name
+                JndiNameType serviceRefName = serviceRef.addNewServiceRefName();
+                serviceRefName.setStringValue(webServiceRefName);
+
+                // service-ref-type
+                if ( !webServiceRefType.equals("") ) {
+                    FullyQualifiedClassType qualifiedClass = serviceRef.addNewServiceInterface();
+                    qualifiedClass.setStringValue(webServiceRefType);
+                    serviceRef.setServiceInterface(qualifiedClass);
+                }
+                else if ( !webServiceRefValue.equals("") ) {
+                    // service-ref-type
+                    FullyQualifiedClassType qualifiedClass = serviceRef.addNewServiceInterface();
+                    qualifiedClass.setStringValue(webServiceRefValue.getName());
+                    serviceRef.setServiceInterface(qualifiedClass);
+                }
+
+                //------------------------------------------------------------------------------
+                // <service-ref> optional elements:
+                //------------------------------------------------------------------------------
+
+                // WSDL document location
+                String documentAnnotation = annotation.wsdlLocation();
+                if ( !documentAnnotation.equals("") ) {
+                    XsdAnyURIType wsdlFile = serviceRef.addNewWsdlFile();
+                    wsdlFile.setStringValue(documentAnnotation);
+                    serviceRef.setWsdlFile(wsdlFile);
+                }
+
+                if ( !injectionJavaType.equals("") ) {
+                    // injectionTarget
+                    InjectionTargetType injectionTarget = serviceRef.addNewInjectionTarget();
+                    FullyQualifiedClassType qualifiedClass = injectionTarget.addNewInjectionTargetClass();
+                    JavaIdentifierType javaType = injectionTarget.addNewInjectionTargetName();
+                    qualifiedClass.setStringValue(injectionClass);
+                    javaType.setStringValue(injectionJavaType);
+                    injectionTarget.setInjectionTargetClass(qualifiedClass);
+                    injectionTarget.setInjectionTargetName(javaType);
+                }
+
+            }
+            catch ( Exception anyException ) {
+                log.debug("WebServiceRefAnnotationHelper: Exception caught while processing <service-ref>");
+                anyException.printStackTrace();
+            }
+        }
+        log.debug("addWebServiceRef(): Exit");
+    }
+
+
+
+    /**
+     * Validate deployment descriptor
+     *
+     * @param AnnotatedApp
+     * @throws Exception thrown if deployment descriptor cannot be parsed
+     */
+    private static void validateDD(AnnotatedApp annotatedApp) throws Exception {
+        log.debug("validateDD( " + annotatedApp.toString() + " ): Entry");
+
+        XmlBeansUtil.parse(annotatedApp.toString());
+
+        log.debug("validateDD(): Exit");
+    }
+}

Propchange: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/WebServiceRefAnnotationHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/WebServiceRefAnnotationHelper.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/WebServiceRefAnnotationHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/SwitchingServiceRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/SwitchingServiceRefBuilder.java?view=diff&rev=513941&r1=513940&r2=513941
==============================================================================
--- geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/SwitchingServiceRefBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/SwitchingServiceRefBuilder.java Fri Mar  2 12:42:57 2007
@@ -17,30 +17,41 @@
 
 package org.apache.geronimo.naming.deployment;
 
+import java.io.IOException;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
 import javax.xml.namespace.QName;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedApp;
+import org.apache.geronimo.j2ee.deployment.annotation.WebServiceRefAnnotationHelper;
 import org.apache.geronimo.j2ee.deployment.Module;
+import org.apache.geronimo.j2ee.deployment.WebModule;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.config.MultiParentClassLoader;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
 import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefDocument;
 import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
 import org.apache.geronimo.xbeans.javaee.ServiceRefType;
-
+import org.apache.geronimo.xbeans.javaee.WebAppType;
+import org.apache.xbean.finder.ClassFinder;
+import org.apache.xbean.finder.UrlSet;
 import org.apache.xmlbeans.QNameSet;
 import org.apache.xmlbeans.XmlObject;
 
 public class SwitchingServiceRefBuilder extends AbstractNamingBuilder {
 
+    private static final Log log = LogFactory.getLog(SwitchingServiceRefBuilder.class);
+
     private static final QName GER_SERVICE_REF_QNAME = GerServiceRefDocument.type
             .getDocumentElementName();
 
@@ -80,6 +91,22 @@
                             Configuration remoteConfiguration,
                             Module module,
                             Map componentContext) throws DeploymentException {
+
+        if ( module instanceof WebModule ) {
+            //TODO determine if its metdatacomplete by presence of ClassFinder in module
+            //This will let this code work on any dd type.
+            WebAppType webApp = (WebAppType) specDD;
+            if (!webApp.getMetadataComplete()) {
+
+                // Discover and process any @WebServiceRef annotations
+                processAnnotations(module);
+
+                // Update both versions of specDD in module
+                module.setSpecDD(webApp);
+                module.setOriginalSpecDD(webApp.toString());
+            }
+        }
+
         ClassLoader cl = module.getEarContext().getClassLoader();
         Class jaxrpcClass = loadClass("javax.xml.rpc.Service", cl);
         Class jaxwsClass = loadClass("javax.xml.ws.Service", cl);
@@ -173,6 +200,43 @@
             }
         }
         return refMap;
+    }
+
+    private void processAnnotations(Module module) throws DeploymentException {
+
+        // Find all the annotated classes via ClassFinder
+        try {
+            ClassLoader classLoader = module.getEarContext().getClassLoader();
+            UrlSet urlSet = new UrlSet(classLoader);
+            if (classLoader instanceof MultiParentClassLoader) {
+                MultiParentClassLoader multiParentClassLoader = (MultiParentClassLoader) classLoader;
+                for (ClassLoader parent : multiParentClassLoader.getParents()) {
+                    if (parent != null) {
+                        urlSet = urlSet.exclude(parent);
+                    }
+                }
+            } else {
+                ClassLoader parent = classLoader.getParent();
+                if (parent != null) {
+                    urlSet = urlSet.exclude(parent);
+                }
+            }
+            ClassFinder finder = new ClassFinder(classLoader, urlSet.getUrls());
+
+            // Process all the annotations for this naming builder type
+            if (WebServiceRefAnnotationHelper.annotationsPresent(finder)) {
+                try {
+                    WebServiceRefAnnotationHelper.processAnnotations(module.getAnnotatedApp(), finder);
+                }
+                catch (Exception e) {
+                    log.warn("Unable to process @WebServiceRef annotations for web module" + module.getName(), e);
+                }
+            }
+
+        } catch (IOException e) {
+            // ignored... we tried
+            log.warn("Unable to process @WebServiceRef annotations for web module" + module.getName(), e);
+        }
     }
 
     public QNameSet getSpecQNameSet() {



Mime
View raw message