Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2011, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.jboss.as.webservices.deployers;
 
 import static org.jboss.as.webservices.util.ASHelper.getEndpointClassName;
 import static org.jboss.as.webservices.util.ASHelper.getEndpointName;
 import static org.jboss.as.webservices.util.ASHelper.getJBossWebMetaData;
 import static org.jboss.as.webservices.util.ASHelper.getJaxwsDeployment;
 import static org.jboss.as.webservices.util.ASHelper.getJBossWebserviceMetaDataPortComponent;
 import static org.jboss.as.webservices.util.ASHelper.getRequiredAttachment;
 import static org.jboss.as.webservices.util.ASHelper.isJaxwsEndpoint;
 import static org.jboss.as.webservices.util.ASHelper.getWebserviceMetadataEJBEndpoint;
 import static org.jboss.as.webservices.util.WSAttachmentKeys.JMS_ENDPOINT_METADATA_KEY;
 import static org.jboss.as.webservices.util.WebMetaDataHelper.getServlets;
 
 import java.util.Map;
 import java.util.Set;
 
 
 import  org.jboss.metadata.web.jboss.JBossWebMetaData;
 import  org.jboss.metadata.web.spec.ServletMappingMetaData;
 import  org.jboss.metadata.web.spec.ServletMetaData;

Author(s):
Richard Opalka
Alessio Soldano
Jim Ma
 
 
     public WSIntegrationProcessorJAXWS_POJO() {
     }
 
     // @Override
     protected void processAnnotation(final DeploymentUnit unitfinal EEModuleDescription moduleDescription)
             throws DeploymentUnitProcessingException {
         if (!DeploymentTypeMarker.isType(.unit)) {
             return;
         }
         final Map<StringEEModuleClassDescriptionclassDescriptionMap = new HashMap<StringEEModuleClassDescription>();
         final CompositeIndex index = unit.getAttachment(.);
         for (EEModuleClassDescription classDescritpion : moduleDescription.getClassDescriptions()) {
             if (isJaxwsEndpoint(classDescritpionindex) && !exclude(unitclassDescritpion)) {
                 classDescriptionMap.put(classDescritpion.getClassName(), classDescritpion);
             }
         }
         final JBossWebMetaData jbossWebMD = getJBossWebMetaData(unit);
         final JAXWSDeployment jaxwsDeployment = getJaxwsDeployment(unit);
         if (jbossWebMD != null) {
             final Set<StringmatchedEps = new HashSet<String>();
             for (final ServletMetaData servletMD : getServlets(jbossWebMD)) {
                 final String endpointClassName = getEndpointClassName(servletMD);
                 final String endpointName = getEndpointName(servletMD);
                 if (classDescriptionMap.containsKey(endpointClassName) || matchedEps.contains(endpointClassName)) {
                     // creating component description for POJO endpoint
                     final ComponentDescription pojoComponent = createComponentDescription(unitendpointName,
                            endpointClassNameendpointName);
                    final ServiceName pojoViewName = registerView(pojoComponentendpointClassName);
                    final String urlPattern = getUrlPattern(endpointNameunit);
                    jaxwsDeployment.addEndpoint(new POJOEndpoint(endpointNameendpointClassNamepojoViewNameurlPattern));
                    classDescriptionMap.remove(endpointClassName);
                    matchedEps.add(endpointClassName);
                } else {
                    if (unit.getParent() != null && DeploymentTypeMarker.isType(.unit.getParent())) {
                        final EEModuleDescription eeModuleDescription = unit.getParent().getAttachment(
                                ......);
                        final CompositeIndex parentIndex = unit.getParent().getAttachment.);
                        for (EEModuleClassDescription classDescription : eeModuleDescription.getClassDescriptions()) {
                            if (classDescription.getClassName().equals(endpointClassName)
                                    && isJaxwsEndpoint(classDescriptionparentIndex)) {
                                final ComponentDescription pojoComponent = createComponentDescription(unitendpointName,
                                        endpointClassNameendpointName);
                                final ServiceName pojoViewName = registerView(pojoComponentendpointClassName);
                                final String urlPattern = getUrlPattern(endpointNameunit);
                                jaxwsDeployment.addEndpoint(new POJOEndpoint(endpointNameendpointClassNamepojoViewNameurlPattern));
                            }
                        }
                    }
                }
            }
        }
        for (EEModuleClassDescription classDescription : classDescriptionMap.values()) {
            ClassInfo classInfo = null;
            String serviceName = null;
            String urlPattern = null;
            // #1 Override serviceName with the explicit urlPattern from port-component/port-component-uri in jboss-webservices.xml
            EJBEndpoint ejbEndpoint = getWebserviceMetadataEJBEndpoint(jaxwsDeploymentclassDescription.getClassName());
            if (ejbEndpoint != null) {
                urlPattern = UrlPatternUtils.getUrlPatternByPortComponentURI(
                    getJBossWebserviceMetaDataPortComponent(unitejbEndpoint.getName()));
            }
            // #2 Override serviceName with @WebContext.urlPattern
            if (urlPattern == null) {
                final ClassAnnotationInformation<WebContextWebContextAnnotationInfoannotationWebContext =
                    classDescription.getAnnotationInformation(WebContext.class);
                if (annotationWebContext != null) {
                    WebContextAnnotationInfo wsInfo = annotationWebContext.getClassLevelAnnotations().get(0);
                    if (wsInfo != null && wsInfo.getUrlPattern().length() > 0) {
                        urlPattern = wsInfo.getUrlPattern();
                    }
                }
            }
            // #3 use serviceName declared in a class annotation
            if (urlPattern == null) {
                final ClassAnnotationInformation<WebServiceWebServiceAnnotationInfoannotationInfo = classDescription
                    .getAnnotationInformation(WebService.class);
                if (annotationInfo != null) {
                    WebServiceAnnotationInfo wsInfo = annotationInfo.getClassLevelAnnotations().get(0);
                    serviceName = wsInfo.getServiceName();
                    classInfo = (ClassInfo)wsInfo.getTarget();
                    urlPattern = UrlPatternUtils.getUrlPattern(classInfo.name().local(), serviceName);
                    if (jaxwsDeployment.contains(urlPattern)){
                        urlPattern = UrlPatternUtils.getUrlPattern(classInfo.name().local(), serviceNamewsInfo.getName());
                    }
                }
                final ClassAnnotationInformation<WebServiceProviderWebServiceProviderAnnotationInfoannotationProviderInfo = classDescription
                    .getAnnotationInformation(WebServiceProvider.class);
                if (annotationProviderInfo != null) {
                    WebServiceProviderAnnotationInfo wsInfo = annotationProviderInfo.getClassLevelAnnotations().get(0);
                    serviceName = wsInfo.getServiceName();
                    classInfo = (ClassInfo)wsInfo.getTarget();
                }
            }
            if (classInfo != null) {
                final String endpointClassName = classDescription.getClassName();
                final ComponentDescription pojoComponent = createComponentDescription(unitendpointClassName,
                        endpointClassNameendpointClassName);
                final ServiceName pojoViewName = registerView(pojoComponentendpointClassName);
                if (urlPattern == null) {
                    urlPattern = UrlPatternUtils.getUrlPattern(classInfo.name().local(), serviceName);
                }
                // register POJO endpoint
                jaxwsDeployment.addEndpoint(new POJOEndpoint(endpointClassName,
                    pojoViewName, UrlPatternUtils.getUrlPattern(urlPattern)));
            }
        }
    }
    private boolean exclude(final DeploymentUnit unitfinal EEModuleClassDescription classDescription) {
        //exclude if it's ejb3 and jms endpoint
        ClassInfo classInfo = null;
        ClassAnnotationInformation<WebServiceWebServiceAnnotationInfoannotationInfo = classDescription
                .getAnnotationInformation(WebService.class);
        if (annotationInfo != null) {
            classInfo = (ClassInfoannotationInfo.getClassLevelAnnotations().get(0).getTarget();
        } else {
            ClassAnnotationInformation<WebServiceProviderWebServiceProviderAnnotationInfoprovidreInfo = classDescription
                    .getAnnotationInformation(WebServiceProvider.class);
            classInfo = (ClassInfoprovidreInfo.getClassLevelAnnotations().get(0).getTarget();
        }
        if (isEjb3(classInfo) || isJmsEndpoint(unitclassInfo)) {
            return true;
        }
        return false;
    }
    private static String getUrlPattern(final String servletNamefinal DeploymentUnit unit) {
        final JBossWebMetaData jbossWebMD = getJBossWebMetaData(unit);
        for (final ServletMappingMetaData servletMappingMD : jbossWebMD.getServletMappings()) {
            if (servletName.equals(servletMappingMD.getServletName())) {
                return servletMappingMD.getUrlPatterns().get(0);
            }
        }
        throw new IllegalStateException();
    }
    private static boolean isJmsEndpoint(final DeploymentUnit unitfinal ClassInfo classInfo) {
        final String endpointClassName = classInfo.name().toString();
        final JMSEndpointsMetaData jmsEndpointsMD = getRequiredAttachment(unit);
        for (final JMSEndpointMetaData endpoint : jmsEndpointsMD.getEndpointsMetaData()) {
            if (endpointClassName.equals(endpoint.getImplementor())) {
                return true;
            }
        }
        return false;
    }
New to GrepCode? Check out our FAQ X