Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2011, Red Hat Middleware LLC, 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.util;
 
 import static org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT;
 import static org.jboss.as.server.deployment.Attachments.RESOURCE_ROOTS;
 import static org.jboss.as.webservices.WSLogger.ROOT_LOGGER;
 import static org.jboss.as.webservices.util.DotNames.JAXWS_SERVICE_CLASS;
 import static org.jboss.as.webservices.util.DotNames.WEB_SERVICE_ANNOTATION;
 import static org.jboss.as.webservices.util.DotNames.WEB_SERVICE_PROVIDER_ANNOTATION;
 import static org.jboss.as.webservices.util.WSAttachmentKeys.JAXWS_ENDPOINTS_KEY;
 import static org.jboss.as.webservices.util.WSAttachmentKeys.JBOSS_WEBSERVICES_METADATA_KEY;
 
 import java.util.List;
 
 
 import  org.jboss.metadata.ear.jboss.JBossAppMetaData;
 import  org.jboss.metadata.ear.spec.ModuleMetaData;
 import  org.jboss.metadata.ear.spec.WebModuleMetaData;
 import  org.jboss.metadata.web.jboss.JBossServletMetaData;
 import  org.jboss.metadata.web.jboss.JBossWebMetaData;
 import  org.jboss.metadata.web.spec.ServletMetaData;
JBoss AS integration helper class.

Author(s):
Richard Opalka
Alessio Soldano
 
 public final class ASHelper {
 
     private ASHelper() {
     }

    
Gets list of JAXWS EJBs meta data.

Parameters:
unit deployment unit
Returns:
list of JAXWS EJBs meta data
 
     public static List<EJBEndpointgetJaxwsEjbs(final DeploymentUnit unit) {
         final JAXWSDeployment jaxwsDeployment = getOptionalAttachment(unit.);
         return jaxwsDeployment != null ? jaxwsDeployment.getEjbEndpoints() : Collections.<EJBEndpoint>emptyList();
     }

    
Gets list of JAXWS POJOs meta data.

Parameters:
unit deployment unit
Returns:
list of JAXWS POJOs meta data
    public static List<POJOEndpointgetJaxwsPojos(final DeploymentUnit unit) {
        final JAXWSDeployment jaxwsDeployment = unit.getAttachment(.);
        return jaxwsDeployment != null ? jaxwsDeployment.getPojoEndpoints() : Collections.<POJOEndpoint>emptyList();
    }

    
Returns endpoint name.

Parameters:
servletMD servlet meta data
Returns:
endpoint name
    public static String getEndpointName(final ServletMetaData servletMD) {
        final String endpointName = servletMD.getName();
        return endpointName != null ? endpointName.trim() : null;
    }

    
Returns endpoint class name.

Parameters:
servletMD servlet meta data
Returns:
endpoint class name
    public static String getEndpointClassName(final ServletMetaData servletMD) {
        final String endpointClass = servletMD.getServletClass();
        return endpointClass != null ? endpointClass.trim() : null;
    }

    
Returns servlet meta data for requested servlet name.

Parameters:
jbossWebMD jboss web meta data
servletName servlet name
Returns:
servlet meta data
    public static ServletMetaData getServletForName(final JBossWebMetaData jbossWebMDfinal String servletName) {
        for (JBossServletMetaData servlet : jbossWebMD.getServlets()) {
            if (servlet.getName().equals(servletName)) {
                return servlet;
            }
        }
        return null;
    }

    
Returns required attachment value from deployment unit.

Parameters:
<A> expected value
unit deployment unit
key attachment key
Returns:
required attachment
Throws:
IllegalStateException if attachment value is null
    public static <A> A getRequiredAttachment(final DeploymentUnit unitfinal AttachmentKey<A> key) {
        final A value = unit.getAttachment(key);
        if (value == null) {
            throw new IllegalStateException();
        }
        return value;
    }

    
Returns optional attachment value from deployment unit or null if not bound.

Parameters:
<A> expected value
unit deployment unit
key attachment key
Returns:
optional attachment value or null
    public static <A> A getOptionalAttachment(final DeploymentUnit unitfinal AttachmentKey<A> key) {
        return unit.getAttachment(key);
    }
    public static boolean isJaxwsService(final ClassInfo currentfinal CompositeIndex index) {
        ClassInfo tmp = current;
        while (tmp != null) {
            final DotName superName = tmp.superName();
            if (.equals(superName)) {
                return true;
            }
            tmp = index.getClassByName(superName);
        }
        return false;
    }
    public static boolean isJaxwsService(final ClassInfo currentfinal Index index) {
        ClassInfo tmp = current;
        while (tmp != null) {
            final DotName superName = tmp.superName();
            if (.equals(superName)) {
                return true;
            }
            tmp = index.getClassByName(superName);
        }
        return false;
    }
    public static boolean hasClassesFromPackage(final Index indexfinal String pck) {
        for (ClassInfo ci : index.getKnownClasses()) {
            if (ci.name().toString().startsWith(pck)) {
                return true;
            }
        }
        return false;
    }
    public static boolean isJaxwsEndpoint(final ClassInfo clazzfinal CompositeIndex index) {
        return isJaxwsEndpoint(clazzindextrue);
    }
    public static boolean isJaxwsEndpoint(final ClassInfo clazzfinal CompositeIndex indexboolean log) {
        // assert JAXWS endpoint class flags
        final short flags = clazz.flags();
        if (Modifier.isInterface(flags)) return false;
        if (Modifier.isAbstract(flags)) return false;
        if (!Modifier.isPublic(flags)) return false;
        if (isJaxwsService(clazzindex)) return false;
        final boolean hasWebServiceAnnotation = clazz.annotations().containsKey();
        final boolean hasWebServiceProviderAnnotation = clazz.annotations().containsKey();
        if (!hasWebServiceAnnotation && !hasWebServiceProviderAnnotation) {
            return false;
        }
        if (hasWebServiceAnnotation && hasWebServiceProviderAnnotation) {
            if (log) {
               .mutuallyExclusiveAnnotations(clazz.name().toString());
            }
            return false;
        }
        if (Modifier.isFinal(flags)) {
            if (log) {
                .finalEndpointClassDetected(clazz.name().toString());
            }
            return false;
        }
        return true;
    }
    public static boolean isJaxwsEndpoint(final EEModuleClassDescription classDescriptionfinal CompositeIndex index) {
        ClassInfo classInfo = null;
        WebServiceAnnotationInfo webserviceAnnoationInfo = null;
        final ClassAnnotationInformation<WebServiceWebServiceAnnotationInfoclassAnnotationInfo = classDescription.getAnnotationInformation(WebService.class);
        if (classAnnotationInfo!= null && !classAnnotationInfo.getClassLevelAnnotations().isEmpty()) {
            webserviceAnnoationInfo = classAnnotationInfo.getClassLevelAnnotations().get(0);
            classInfo = (ClassInfo)webserviceAnnoationInfo.getTarget();
        }
        WebServiceProviderAnnotationInfo webserviceProviderAnnoationInfo = null;
        final ClassAnnotationInformation<WebServiceProviderWebServiceProviderAnnotationInfoproviderAnnotationInfo = classDescription.getAnnotationInformation(WebServiceProvider.class);
        if (providerAnnotationInfo!= null && !providerAnnotationInfo.getClassLevelAnnotations().isEmpty()) {
            webserviceProviderAnnoationInfo = providerAnnotationInfo.getClassLevelAnnotations().get(0);
            classInfo = (ClassInfo)webserviceProviderAnnoationInfo.getTarget();
        }
        if (classInfo == null) {
            return false;
        }
        // assert JAXWS endpoint class flags
        final short flags = classInfo.flags();
        if (Modifier.isInterface(flags)) return false;
        if (Modifier.isAbstract(flags)) return false;
        if (!Modifier.isPublic(flags)) return false;
        if (isJaxwsService(classInfoindex)) return false;
        if (webserviceAnnoationInfo !=null && webserviceProviderAnnoationInfo != null) {
            .mutuallyExclusiveAnnotations(classInfo.name().toString());
            return false;
        }
        if (Modifier.isFinal(flags)) {
            .finalEndpointClassDetected(classInfo.name().toString());
            return false;
        }
        return true;
    }

    
Gets the JBossWebMetaData from the WarMetaData attached to the provided deployment unit, if any.

Parameters:
unit
Returns:
the JBossWebMetaData or null if either that or the parent WarMetaData are not found.
    public static JBossWebMetaData getJBossWebMetaData(final DeploymentUnit unit) {
        final WarMetaData warMetaData = getOptionalAttachment(unit.);
        JBossWebMetaData result = null;
        if (warMetaData != null) {
            result = warMetaData.getMergedJBossWebMetaData();
            if (result == null) {
                result = warMetaData.getJBossWebMetaData();
            }
        } else {
            result = getOptionalAttachment(unit.);
        }
        return result;
    }
    public static List<AnnotationInstancegetAnnotations(final DeploymentUnit unitfinal DotName annotation) {
       final CompositeIndex compositeIndex = getRequiredAttachment(unit.);
       return compositeIndex.getAnnotations(annotation);
    }
    public static JAXWSDeployment getJaxwsDeployment(final DeploymentUnit unit) {
        JAXWSDeployment wsDeployment = unit.getAttachment();
        if (wsDeployment == null) {
            wsDeployment = new JAXWSDeployment();
            unit.putAttachment(wsDeployment);
        }
        return wsDeployment;
    }

    
Return a named port-component from the jboss-webservices.xml

Parameters:
unit
name
Returns:
        final DeploymentUnit unitfinal String name) {
        if (name != null) {
            final JBossWebservicesMetaData jbossWebserviceMetaData = unit.getAttachment();
            if (jbossWebserviceMetaData != null) {
                JBossPortComponentMetaData[] portComponent = jbossWebserviceMetaData.getPortComponents();
                if (portComponent != null) {
                    for (JBossPortComponentMetaData component : portComponent) {
                        if (name.equals(component.getEjbName())) {
                            return component;
                        }
                    }
                }
            }
        }
        return null;
    }

    
Returns an EJBEndpoint based upon fully qualified classname.

Parameters:
jaxwsDeployment
className
Returns:
    public static EJBEndpoint getWebserviceMetadataEJBEndpoint(final JAXWSDeployment jaxwsDeployment,
                                                               final String className) {
        java.util.List<EJBEndpointejbEndpointList = jaxwsDeployment.getEjbEndpoints();
        for (EJBEndpoint ejbEndpoint : ejbEndpointList) {
            if (className.equals(ejbEndpoint.getClassName())) {
                return ejbEndpoint;
            }
        }
        return null;
    }

    
Returns context root associated with webservice deployment. If there's application.xml descriptor provided defining nested web module, then context root defined there will be returned. Otherwise context root defined in jboss-web.xml will be returned.

Parameters:
dep webservice deployment
jbossWebMD jboss web meta data
Returns:
context root
    public static String getContextRoot(final Deployment depfinal JBossWebMetaData jbossWebMD) {
        final DeploymentUnit unit = WSHelper.getRequiredAttachment(depDeploymentUnit.class);
        final JBossAppMetaData jbossAppMD = unit.getParent() == null ? null : ASHelper.getOptionalAttachment(unit.getParent(),
                .);
        String contextRoot = null;
        // prefer context root defined in application.xml over one defined in jboss-web.xml
        if (jbossAppMD != null) {
            final ModuleMetaData moduleMD = jbossAppMD.getModules().get(dep.getSimpleName());
            if (moduleMD != null) {
                final WebModuleMetaData webModuleMD = (WebModuleMetaData) moduleMD.getValue();
                contextRoot = webModuleMD.getContextRoot();
            }
        }
        if (contextRoot == null) {
            contextRoot = jbossWebMD != null ? jbossWebMD.getContextRoot() : null;
        }
        return contextRoot;
    }
    @SuppressWarnings("unchecked")
    public static <T> T getMSCService(final ServiceName serviceNamefinal Class<T> clazz) {
        ServiceController<T> service = (ServiceController<T>) CurrentServiceContainer.getServiceContainer().getService(serviceName);
        return service != null ? service.getValue() : null;
    }
    @SuppressWarnings("unchecked")
    public static <T> T getMSCService(final ServiceName serviceNamefinal Class<T> clazzfinal OperationContext context) {
        ServiceController<T> service = (ServiceController<T>)context.getServiceRegistry(false).getService(serviceName);
        return service != null ? service.getValue() : null;
    }
    public static WSRefRegistry getWSRefRegistry(final DeploymentUnit unit) {
        WSRefRegistry refRegistry = unit.getAttachment(.);
        if (refRegistry == null) {
            refRegistry = WSRefRegistry.newInstance();
            unit.putAttachment(.refRegistry);
        }
        return refRegistry;
    }
    public static List<ResourceRootgetResourceRoots(DeploymentUnit unit) {
        // wars define resource roots
        AttachmentList<ResourceRootresourceRoots = unit.getAttachment();
        if (!unit.getName().endsWith(".war") && EjbDeploymentMarker.isEjbDeployment(unit)) {
            // ejb archives don't define resource roots, using root resource
            resourceRoots = new AttachmentList<ResourceRoot>(ResourceRoot.class);
            final ResourceRoot root = unit.getAttachment();
            resourceRoots.add(root);
        }
        return resourceRoots;
    }
New to GrepCode? Check out our FAQ X