Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 52740 invoked from network); 2 Mar 2007 20:43:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Mar 2007 20:43:23 -0000 Received: (qmail 4658 invoked by uid 500); 2 Mar 2007 20:43:31 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 4614 invoked by uid 500); 2 Mar 2007 20:43:31 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 4602 invoked by uid 99); 2 Mar 2007 20:43:31 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2007 12:43:31 -0800 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2007 12:43:20 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 47A441A981A; Fri, 2 Mar 2007 12:43:00 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: scm@geronimo.apache.org From: djencks@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070302204300.47A441A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ asm + + org.apache.axis2 + axis2-jaxws-api + + 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 @@ * @EJB and @EJBs 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: - *

+ * *

    *
  1. Translates annotations into corresponding deployment descriptor elements (so that the * actual deployment descriptor in the module can be updated or even created if necessary) *
- *

+ * *

Note(s): *

    *
  • The user is responsible for invoking change to metadata-complete *
  • This helper class will validate any changes it makes to the deployment descriptor. An * exception will be thrown if it fails to parse *
- *

+ * *

Remaining ToDo(s): *

    - *
  • None + *
  • Usage of mappedName *
* * @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 classesWithEJB = classFinder.findAnnotatedClasses(EJB.class); List methodsWithEJB = classFinder.findAnnotatedMethods(EJB.class); List 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 classesWithEJBs = classFinder.findAnnotatedClasses(EJBs.class); - // Class-level EJBs + // Class-level annotation(s) List ejbList = new ArrayList(); for (Class cls : classesWithEJBs) { EJBs ejbs = (EJBs) cls.getAnnotation(EJBs.class); @@ -253,7 +251,7 @@ log.debug("addEJB(): 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(): 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(): 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 to the + + log.debug("addEJB(): Does not exist in DD: " + remoteRefName); + + // Doesn't exist in deployment descriptor -- add as an 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 @@ * @Resource and @Resources 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: - *

+ * *

    - *
  1. Translates annotations into corresponding deployment descriptor elements (so that the - * actual deployment descriptor in the module can be updated or even created if necessary) + *
  2. Translates annotations into corresponding deployment descriptor elements (so that the + * actual deployment descriptor in the module can be updated or even created if necessary) *
- *

+ * *

Note(s): *

    - *
  • The user is responsible for invoking change to metadata-complete - *
  • This helper class will validate any changes it makes to the deployment descriptor. An - * exception will be thrown if it fails to parse + *
  • The user is responsible for invoking change to metadata-complete + *
  • This helper class will validate any changes it makes to the deployment descriptor. An + * exception will be thrown if it fails to parse *
- *

+ * *

Remaining ToDo(s): *

    - *
  • None + *
  • Usage of mappedName *
* * @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 classeswithResource = classFinder.findAnnotatedClasses(Resource.class); List methodswithResource = classFinder.findAnnotatedMethods(Resource.class); List 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 classeswithResources = classFinder.findAnnotatedClasses(Resources.class); - //--------------------------- - // Class-level Resources - //--------------------------- - List ResourceList = new ArrayList(); + // Class-level annotation(s) + List resourceList = new ArrayList(); 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 @@ *

*

    *
  1. -- Used to declare an application's environment entry - *
  2. -- Declares a reference to a Web service + *
  3. -- Declares a reference to a Web Service *
  4. -- Contains a declaration of a Deployment Component's reference to an * external resource *
  5. -- 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 + * @WebServieRef and @WebServieRef 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: + * + *
      + *
    1. Translates annotations into corresponding deployment descriptor elements (so that the + * actual deployment descriptor in the module can be updated or even created if necessary) + *
    + * + *

    Note(s): + *

      + *
    • The user is responsible for invoking change to metadata-complete + *
    • This helper class will validate any changes it makes to the deployment descriptor. An + * exception will be thrown if it fails to parse + *
    + * + *

    Remaining ToDo(s): + *

      + *
    • None + *
    + * + * @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 classeswithWebServiceRef = classFinder.findAnnotatedClasses(WebServiceRef.class); + List methodswithWebServiceRef = classFinder.findAnnotatedMethods(WebServiceRef.class); + List 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 classeswithWebServiceRefs = classFinder.findAnnotatedClasses(WebServiceRefs.class); + + // Class-level annotation(s) + List webServiceRefList = new ArrayList(); + 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: + * + *
      + *
    1. -- Declares a reference to a Web Service + *
    + * + *

    Note(s): + *

      + *
    • The deployment descriptor is the authoritative source so this method ensures that + * existing elements in it are not overwritten by annoations + *
    + * + * @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. + //------------------------------------------------------------------------------------------ + 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(); + + //------------------------------------------------------------------------------ + // 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); + } + + //------------------------------------------------------------------------------ + // 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 "); + 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() {