Author: sagara
Date: Fri May 18 09:51:52 2012
New Revision: 1340051

URL: http://svn.apache.org/viewvc?rev=1340051&view=rev
Log:
AXIS2-5322 -  Refactored JAXWSDeployer  so that codes can be shared among 
JAXWSDeployer and JAXWSServiceBuilderExtension through newly introduced 
JAXWSDeployerSupport class. JAXWSServiceBuilderExtension support to deploy 
JAX-WS artefacts based on  service.xml file.  Test coverage need to be added.

Added:
    
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployerSupport.java
   (with props)
    
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSServiceBuilderExtension.java
   (with props)
Modified:
    
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java

Modified: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java?rev=1340051&r1=1340050&r2=1340051&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java
 Fri May 18 09:51:52 2012
@@ -27,26 +27,13 @@ import org.apache.axis2.deployment.Deplo
 import org.apache.axis2.deployment.DeploymentErrorMsgs;
 import org.apache.axis2.deployment.repository.util.DeploymentFileData;
 import org.apache.axis2.deployment.util.Utils;
-import org.apache.axis2.description.AxisOperation;
-import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisServiceGroup;
-import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.i18n.Messages;
-import org.apache.axis2.jaxws.addressing.util.EndpointContextMap;
-import org.apache.axis2.jaxws.addressing.util.EndpointContextMapManager;
-import org.apache.axis2.jaxws.addressing.util.EndpointKey;
-import org.apache.axis2.jaxws.description.DescriptionFactory;
-import org.apache.axis2.jaxws.description.EndpointDescription;
-import org.apache.axis2.jaxws.server.JAXWSMessageReceiver;
-import org.apache.axis2.util.Loader;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.jws.WebService;
-import javax.xml.namespace.QName;
-import javax.xml.ws.WebServiceProvider;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -104,7 +91,8 @@ public class JAXWSDeployer extends Abstr
                                 
getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR),
                         axisConfig.isChildFirstClassLoading());
                 Thread.currentThread().setContextClassLoader(classLoader);
-                deployClasses("JAXWS-Builtin", file.toURL(), 
Thread.currentThread().getContextClassLoader(), classList);
+                JAXWSDeployerSupport deployerSupport = new 
JAXWSDeployerSupport(configCtx, directory);
+                deployerSupport.deployClasses("JAXWS-Builtin", file.toURL(), 
Thread.currentThread().getContextClassLoader(), classList);
             } catch (NoClassDefFoundError e) {
                 if (log.isDebugEnabled()) {
                     log.debug(Messages.getMessage("deployingexception", 
e.getMessage()), e);
@@ -121,10 +109,10 @@ public class JAXWSDeployer extends Abstr
 
     protected ArrayList<String> getClassesInWebInfDirectory(File file) {
         String filePath = file.getAbsolutePath();
-        Collection files = FileUtils.listFiles(file, new String[]{"class"}, 
true);
+        Collection<File> files = FileUtils.listFiles(file, new 
String[]{"class"}, true);
         ArrayList<String> classList = new ArrayList<String>();
-        for (Iterator iterator = files.iterator(); iterator.hasNext();) {
-            File f = (File) iterator.next();
+        for (Iterator<File> iterator = files.iterator(); iterator.hasNext();) {
+            File f = iterator.next();
             String fPath = f.getAbsolutePath();
             String fqcn = fPath.substring(filePath.length() + 1);
             fqcn = fqcn.substring(0, fqcn.length() - ".class".length());
@@ -164,7 +152,8 @@ public class JAXWSDeployer extends Abstr
                 Thread.currentThread().setContextClassLoader(classLoader);
 
                 List<String> classList = 
Utils.getListOfClasses(deploymentFileData);
-                AxisServiceGroup serviceGroup = deployClasses(groupName, 
location, classLoader, classList);
+                JAXWSDeployerSupport deployerSupport = new 
JAXWSDeployerSupport(configCtx, directory);
+                AxisServiceGroup serviceGroup = 
deployerSupport.deployClasses(groupName, location, classLoader, classList);
                 
                 if(serviceGroup == null) {
                     String msg = "Error while deploying JAX-WS jar: " +
@@ -186,61 +175,6 @@ public class JAXWSDeployer extends Abstr
         }
     }
 
-    protected AxisServiceGroup deployClasses(String groupName, URL location, 
ClassLoader classLoader, List<String> classList)
-            throws ClassNotFoundException, InstantiationException, 
IllegalAccessException, AxisFault {
-        ArrayList<AxisService> axisServiceList = new ArrayList<AxisService>();
-        // Get the hierarchical path of the service
-        String serviceHierarchy = 
Utils.getServiceHierarchy(location.getPath(), this.directory);
-        for (String className : classList) {
-            Class<?> pojoClass;
-            try {
-                pojoClass = Loader.loadClass(classLoader, className);
-            } catch (Exception e){
-                continue;
-            }
-            WebService wsAnnotation = 
pojoClass.getAnnotation(WebService.class);
-            WebServiceProvider wspAnnotation = null;
-            if (wsAnnotation == null) {
-                wspAnnotation = 
pojoClass.getAnnotation(WebServiceProvider.class);
-            }
-
-            // Create an Axis Service only if the class is not an interface 
and it has either 
-            // @WebService annotation or @WebServiceProvider annotation.
-            if ((wsAnnotation != null
-                    || wspAnnotation != null)
-                    && !pojoClass.isInterface()) {
-                AxisService axisService;
-                axisService =
-                        createAxisService(classLoader,
-                                className,
-                                location);
-                if(axisService != null) {
-                    if (serviceHierarchy != null) {
-                        axisService.setName(serviceHierarchy + 
axisService.getName());
-                    }
-                    log.info("Deploying JAXWS annotated class " + className + 
" as a service - "
-                            + axisService.getName());
-                    axisServiceList.add(axisService);
-                }
-            }
-        }
-        int size = axisServiceList.size();
-        if (size <= 0) {
-            return null;
-        }
-        //creating service group by considering the hierarchical path also
-        AxisServiceGroup serviceGroup = new AxisServiceGroup();
-        if (serviceHierarchy != null) {
-            serviceGroup.setServiceGroupName(serviceHierarchy + groupName);
-        }
-        for (AxisService axisService : axisServiceList) {
-            serviceGroup.addService(axisService);
-        }
-        axisConfig.addServiceGroup(serviceGroup);
-        configureAddressing(serviceGroup);
-        return serviceGroup;
-    }
-
     protected void storeFaultyService(DeploymentFileData deploymentFileData, 
Throwable t) {
         StringWriter errorWriter = new StringWriter();
         PrintWriter ptintWriter = new PrintWriter(errorWriter);
@@ -250,37 +184,6 @@ public class JAXWSDeployer extends Abstr
                 put(deploymentFileData.getFile().getAbsolutePath(), error);
     }
 
-    protected AxisService createAxisService(ClassLoader classLoader,
-                                          String className,
-                                          URL serviceLocation) throws 
ClassNotFoundException,
-            InstantiationException,
-            IllegalAccessException,
-            AxisFault {
-        Class<?> pojoClass = Loader.loadClass(classLoader, className);
-        AxisService axisService;
-        try {
-            axisService = DescriptionFactory.createAxisService(pojoClass, 
configCtx);
-        } catch (Throwable t) {
-            log.info("Exception creating Axis Service : " + t.getCause(), t);
-            return null;
-        }
-        if (axisService != null) {
-            Iterator<AxisOperation> operations = axisService.getOperations();
-            while (operations.hasNext()) {
-                AxisOperation axisOperation = operations.next();
-                if (axisOperation.getMessageReceiver() == null) {
-                    axisOperation.setMessageReceiver(new 
JAXWSMessageReceiver());
-                }
-            }
-            axisService.setElementFormDefault(false);
-            axisService.setFileName(serviceLocation);
-            axisService.setClassLoader(classLoader);
-            axisService.addParameter(new 
Parameter(org.apache.axis2.jaxws.spi.Constants.CACHE_CLASSLOADER, classLoader));
-            axisService.addParameter(new 
Parameter("modifyUserWSDLPortAddress", "true"));
-        }
-        return axisService;
-    }
-
     public void setDirectory(String directory) {
         this.directory = directory;
     }
@@ -326,35 +229,6 @@ public class JAXWSDeployer extends Abstr
         return false;
     }
 
-    private boolean isEmpty(String string) {
-        return (string == null || "".equals(string));
-    }
-    
-    //Store the address URIs that we will need to create endpoint references 
at runtime.
-    private void configureAddressing(AxisServiceGroup serviceGroup) {
-        EndpointContextMap map =
-            (EndpointContextMap) 
configCtx.getProperty(org.apache.axis2.jaxws.Constants.ENDPOINT_CONTEXT_MAP);
-        
-        if (map == null) {
-            map = EndpointContextMapManager.getEndpointContextMap();
-            
configCtx.setProperty(org.apache.axis2.jaxws.Constants.ENDPOINT_CONTEXT_MAP, 
map);
-        }
-        
-        Iterator<AxisService> iterator = serviceGroup.getServices();
-        
-        while (iterator.hasNext()) {
-            AxisService axisService = iterator.next();
-            Parameter param =
-                
axisService.getParameter(EndpointDescription.AXIS_SERVICE_PARAMETER);
-            EndpointDescription ed = (EndpointDescription) param.getValue();
-            QName serviceName = ed.getServiceQName();
-            QName portName = ed.getPortQName();
-            EndpointKey key = new EndpointKey(serviceName, portName);
-
-            map.put(key, axisService);
-        }
-    }
-
     /**
      * Checks whether there's a 'lib' folder inside the provided folder and 
adds all the lib URLs
      * into the provided URL list.

Added: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployerSupport.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployerSupport.java?rev=1340051&view=auto
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployerSupport.java
 (added)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployerSupport.java
 Fri May 18 09:51:52 2012
@@ -0,0 +1,349 @@
+package org.apache.axis2.jaxws.framework;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceProvider;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.axis2.deployment.repository.util.DeploymentFileData;
+import org.apache.axis2.deployment.util.Utils;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.jaxws.addressing.util.EndpointContextMap;
+import org.apache.axis2.jaxws.addressing.util.EndpointContextMapManager;
+import org.apache.axis2.jaxws.addressing.util.EndpointKey;
+import org.apache.axis2.jaxws.description.DescriptionFactory;
+import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.axis2.jaxws.server.JAXWSMessageReceiver;
+import org.apache.axis2.util.Loader;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * <p>The Class JAXWSDeployerSupport act as a helper class for both 
JAXWSDeployer
+ * and JAXWSServiceBuilderExtension.</p>
+ * 
+ * @since 1.7.0
+ */
+public class JAXWSDeployerSupport {
+
+    private static final Log log = 
LogFactory.getLog(JAXWSDeployerSupport.class);
+
+    /** The configuration context. */
+    private ConfigurationContext configurationContext;
+
+    /** The directory. */
+    private String directory;
+
+    public JAXWSDeployerSupport() {
+        this(null, null);
+    }
+
+    /**
+     * Instantiates a new jAXWS deployer support.
+     * 
+     * @param configurationContext
+     *            the configuration context
+     */
+    public JAXWSDeployerSupport(ConfigurationContext configurationContext) {
+        this(configurationContext, null);
+    }
+
+    /**
+     * Instantiates a new jAXWS deployer support.
+     * 
+     * @param configurationContext
+     *            the configuration context
+     * @param directory
+     *            the directory
+     */
+    public JAXWSDeployerSupport(ConfigurationContext configurationContext, 
String directory) {
+        this.configurationContext = configurationContext;
+        this.directory = directory;
+    }
+
+    /**
+     * Gets the configuration context.
+     * 
+     * @return the configuration context
+     */
+    public ConfigurationContext getConfigurationContext() {
+        return configurationContext;
+    }
+
+    /**
+     * Sets the configuration context.
+     * 
+     * @param configurationContext
+     *            the new configuration context
+     */
+    public void setConfigurationContext(ConfigurationContext 
configurationContext) {
+        this.configurationContext = configurationContext;
+    }
+
+    /**
+     * Gets the directory.
+     * 
+     * @return the directory
+     */
+    public String getDirectory() {
+        return directory;
+    }
+
+    /**
+     * Sets the directory.
+     * 
+     * @param directory
+     *            the new directory
+     */
+    public void setDirectory(String directory) {
+        this.directory = directory;
+    }
+
+    /**
+     * Deploy classes.
+     * 
+     * @param groupName
+     *            the group name
+     * @param location
+     *            the location
+     * @param classLoader
+     *            the class loader
+     * @param classList
+     *            the class list
+     * @return the axis service group
+     * @throws ClassNotFoundException
+     *             the class not found exception
+     * @throws InstantiationException
+     *             the instantiation exception
+     * @throws IllegalAccessException
+     *             the illegal access exception
+     * @throws AxisFault
+     *             the axis fault
+     */
+    protected AxisServiceGroup deployClasses(String groupName, URL location,
+            ClassLoader classLoader, List<String> classList) throws 
ClassNotFoundException,
+            InstantiationException, IllegalAccessException, AxisFault {
+
+        String serviceHierarchy = 
Utils.getServiceHierarchy(location.getPath(), this.directory);
+        Collection<AxisService> axisServiceList = deployClasses(location, 
classLoader, classList)
+                .values();
+        // creating service group by considering the hierarchical path also
+        if (axisServiceList.size() > 0) {
+            AxisServiceGroup serviceGroup = new AxisServiceGroup();
+            for (Iterator<AxisService> axItr = axisServiceList.iterator(); 
axItr.hasNext();) {
+                serviceGroup.addService(axItr.next());
+            }
+            if (serviceHierarchy != null) {
+                serviceGroup.setServiceGroupName(serviceHierarchy + groupName);
+            }
+            
getConfigurationContext().getAxisConfiguration().addServiceGroup(serviceGroup);
+            configureAddressing(serviceGroup);
+            return serviceGroup;
+        }
+        return null;
+    }
+
+    /**
+     * Deploy classes.
+     * 
+     * @param location
+     *            the location
+     * @param classLoader
+     *            the class loader
+     * @param classList
+     *            the class list
+     * @return the hash map
+     * @throws ClassNotFoundException
+     *             the class not found exception
+     * @throws InstantiationException
+     *             the instantiation exception
+     * @throws IllegalAccessException
+     *             the illegal access exception
+     * @throws AxisFault
+     *             the axis fault
+     */
+    protected HashMap<String, AxisService> deployClasses(URL location, 
ClassLoader classLoader,
+            List<String> classList) throws ClassNotFoundException, 
InstantiationException,
+            IllegalAccessException, AxisFault {
+        HashMap<String, AxisService> services = new HashMap<String, 
AxisService>();
+        // Get the hierarchical path of the service
+
+        String serviceHierarchy = 
Utils.getServiceHierarchy(location.getPath(), getDirectory());
+        for (String className : classList) {
+            Class<?> pojoClass;
+            try {
+                pojoClass = Loader.loadClass(classLoader, className);
+            } catch (Exception e) {
+                continue;
+            }
+            WebService wsAnnotation = 
pojoClass.getAnnotation(WebService.class);
+            WebServiceProvider wspAnnotation = null;
+            if (wsAnnotation == null) {
+                wspAnnotation = 
pojoClass.getAnnotation(WebServiceProvider.class);
+            }
+
+            // Create an Axis Service only if the class is not an interface and
+            // it has either
+            // @WebService annotation or @WebServiceProvider annotation.
+            if ((wsAnnotation != null || wspAnnotation != null) && 
!pojoClass.isInterface()) {
+                AxisService axisService;
+                axisService = createAxisService(classLoader, className, 
location);
+                if (axisService != null) {
+                    log.info("Deploying JAXWS annotated class " + className + 
" as a service - "
+                            + serviceHierarchy + axisService.getName());
+                    services.put(axisService.getName(), axisService);
+                }
+            }
+        }
+        return services;
+    }
+
+    /**
+     * Creates the axis service.
+     * 
+     * @param classLoader
+     *            the class loader
+     * @param className
+     *            the class name
+     * @param serviceLocation
+     *            the service location
+     * @return the axis service
+     * @throws ClassNotFoundException
+     *             the class not found exception
+     * @throws InstantiationException
+     *             the instantiation exception
+     * @throws IllegalAccessException
+     *             the illegal access exception
+     * @throws AxisFault
+     *             the axis fault
+     */
+    protected AxisService createAxisService(ClassLoader classLoader, String 
className,
+            URL serviceLocation) throws ClassNotFoundException, 
InstantiationException,
+            IllegalAccessException, AxisFault {
+        Class<?> pojoClass = Loader.loadClass(classLoader, className);
+        AxisService axisService;
+        try {
+            axisService = DescriptionFactory
+                    .createAxisService(pojoClass, getConfigurationContext());
+        } catch (Throwable t) {
+            log.info("Exception creating Axis Service : " + t.getCause(), t);
+            return null;
+        }
+        if (axisService != null) {
+            Iterator<AxisOperation> operations = axisService.getOperations();
+            while (operations.hasNext()) {
+                AxisOperation axisOperation = operations.next();
+                if (axisOperation.getMessageReceiver() == null) {
+                    axisOperation.setMessageReceiver(new 
JAXWSMessageReceiver());
+                }
+            }
+            axisService.setElementFormDefault(false);
+            axisService.setFileName(serviceLocation);
+            axisService.setClassLoader(classLoader);
+            axisService.addParameter(new Parameter(
+                    org.apache.axis2.jaxws.spi.Constants.CACHE_CLASSLOADER, 
classLoader));
+        }
+        return axisService;
+    }
+
+    /**
+     * Gets the list of classes.
+     * 
+     * @param deploymentFileData
+     *            the deployment file data
+     * @return the list of classes
+     * @throws DeploymentException
+     *             the deployment exception
+     */
+    public List<String> getListOfClasses(DeploymentFileData deploymentFileData)
+            throws DeploymentException {
+        return Utils.getListOfClasses(deploymentFileData);
+    }
+
+    /**
+     * Gets the service class name from meta data.
+     * 
+     * @param serviceMetaData
+     *            the service meta data
+     * @return the service class name from meta data
+     */
+    public List<String> getServiceClassNameFromMetaData(OMElement 
serviceMetaData) {
+        List<String> classNames = new ArrayList<String>();
+        if (serviceMetaData.getLocalName().equals("serviceGroup")) {
+            for (Iterator<OMElement> services = 
serviceMetaData.getChildrenWithLocalName("service"); services
+                    .hasNext();) {
+                for (Iterator<OMElement> parameters = 
services.next().getChildrenWithLocalName(
+                        "parameter"); parameters.hasNext();) {
+                    OMElement parameter = parameters.next();
+                    OMAttribute att = parameter.getAttribute(new 
QName("name"));
+                    if (att != null) {
+                        String value = att.getAttributeValue();
+                        if (value != null && "ServiceClass".equals(value)) {
+                            classNames.add(parameter.getText());
+                        }
+                    }
+                }
+            }
+
+        } else if (serviceMetaData.getLocalName().equals("service")) {
+            for (Iterator<OMElement> parameters = serviceMetaData
+                    .getChildrenWithLocalName("parameter"); 
parameters.hasNext();) {
+                OMElement parameter = parameters.next();
+                OMAttribute att = parameter.getAttribute(new QName("name"));
+                if (att != null) {
+                    String value = att.getAttributeValue();
+                    if (value != null && "ServiceClass".equals(value)) {
+                        classNames.add(parameter.getText());
+                    }
+                }
+            }
+
+        }
+        return classNames;
+    }
+
+    /**
+     * Configure addressing.
+     * 
+     * @param serviceGroup
+     *            the service group
+     */
+    private void configureAddressing(AxisServiceGroup serviceGroup) {
+        EndpointContextMap map = (EndpointContextMap) 
getConfigurationContext().getProperty(
+                org.apache.axis2.jaxws.Constants.ENDPOINT_CONTEXT_MAP);
+
+        if (map == null) {
+            map = EndpointContextMapManager.getEndpointContextMap();
+            getConfigurationContext().setProperty(
+                    org.apache.axis2.jaxws.Constants.ENDPOINT_CONTEXT_MAP, 
map);
+        }
+
+        Iterator<AxisService> iterator = serviceGroup.getServices();
+
+        while (iterator.hasNext()) {
+            AxisService axisService = iterator.next();
+            Parameter param = 
axisService.getParameter(EndpointDescription.AXIS_SERVICE_PARAMETER);
+            EndpointDescription ed = (EndpointDescription) param.getValue();
+            QName serviceName = ed.getServiceQName();
+            QName portName = ed.getPortQName();
+            EndpointKey key = new EndpointKey(serviceName, portName);
+
+            map.put(key, axisService);
+        }
+    }
+
+}

Propchange: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployerSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSServiceBuilderExtension.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSServiceBuilderExtension.java?rev=1340051&view=auto
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSServiceBuilderExtension.java
 (added)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSServiceBuilderExtension.java
 Fri May 18 09:51:52 2012
@@ -0,0 +1,170 @@
+package org.apache.axis2.jaxws.framework;
+
+import java.net.MalformedURLException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.deployment.AbstractServiceBuilderExtension;
+import org.apache.axis2.deployment.DeploymentConstants;
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.axis2.deployment.repository.util.DeploymentFileData;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.jaxws.server.JAXWSMessageReceiver;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * <p>
+ * The Class JAXWSServiceBuilderExtension is an implementation of
+ * org.apache.axis2.deployment.ServiceBuilderExtension interface and facilitate
+ * to deploy JAX-WS artifacts through other Deployers.
+ * </p>
+ * 
+ * <p>
+ * As an example it is possible to use JAXWSServiceBuilderExtension class to 
add
+ * JAX-WS support for service.xml meta file based service deployment. First,
+ * JAXWSServiceBuilderExtension create initial AxisService and ServiceDeployer
+ * add further configuration based of provided service.xml meta data file.
+ * Annotated call may load from embedded archive (AAR), a exploded directory or
+ * from Classpath.
+ * </p>
+ * 
+ * <p>
+ * It is expected to define only JAXWSMessageReceiver as MessageReceivers in 
the
+ * service.xml file
+ * </p>
+ * 
+ * <p>
+ * Example :
+ * </p>
+ * 
+ * <pre>
+ * {@code
+ *  <messageReceivers>
+ *         <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"; 
class="org.apache.axis2.jaxws.server.JAXWSMessageReceiver"/>
+ *         <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"; 
class="org.apache.axis2.jaxws.server.JAXWSMessageReceiver"/>
+ *     </messageReceivers>
+ * 
+ * }
+ * </pre>
+ * 
+ * @since 1.7.0
+ */
+public class JAXWSServiceBuilderExtension extends 
AbstractServiceBuilderExtension {
+
+    private static final Log log = 
LogFactory.getLog(JAXWSServiceBuilderExtension.class);
+
+    public Map<String, AxisService> buildAxisServices(DeploymentFileData 
deploymentFileData)
+            throws DeploymentException {
+
+        if (!checkPreconditions(deploymentFileData.getServiceMetaData())) {
+            // Should not process further.
+            return null;
+        }
+
+        ClassLoader threadClassLoader = 
Thread.currentThread().getContextClassLoader();
+        try {
+            
Thread.currentThread().setContextClassLoader(deploymentFileData.getClassLoader());
+            try {
+                JAXWSDeployerSupport deployerSupport = new 
JAXWSDeployerSupport(
+                        getConfigurationContext(), getDirectory());
+                List<String> listOfClasses = 
deployerSupport.getListOfClasses(deploymentFileData);
+
+                /*
+                 * if listOfClasses contains no results, let's try to load
+                 * implementation class from service.xml.
+                 */
+                if ((listOfClasses == null || listOfClasses.size() == 0)
+                        && deploymentFileData.getServiceMetaData() != null
+                        && deploymentFileData.getServiceMetaData() instanceof 
OMElement) {
+                    OMElement serviceMetaData = (OMElement) 
deploymentFileData.getServiceMetaData();
+                    listOfClasses = deployerSupport
+                            .getServiceClassNameFromMetaData(serviceMetaData);
+                }
+
+                return 
deployerSupport.deployClasses(deploymentFileData.getFile().toURL(),
+                        deploymentFileData.getClassLoader(), listOfClasses);
+
+            } catch (AxisFault e) {
+                log.error(e);
+            } catch (MalformedURLException e) {
+                log.error(e);
+            } catch (ClassNotFoundException e) {
+                log.error(e);
+            } catch (InstantiationException e) {
+                log.error(e);
+            } catch (IllegalAccessException e) {
+                log.error(e);
+            }
+        } finally {
+            Thread.currentThread().setContextClassLoader(threadClassLoader);
+        }
+        return null;
+    }
+
+    /**
+     * This method check whether all the defined <messageReceiver> are type of
+     * JAXWSMessageReceiver. Return true only if all the <messageReceiver>
+     * elements satisfy above condition.
+     * 
+     * @param metaData
+     *            the meta data
+     * @return true, if successful
+     */
+    protected boolean checkPreconditions(Object metaData) {
+        boolean checkOK = false;
+        if (metaData != null && metaData instanceof OMElement) {
+            OMElement metaDataEle = (OMElement) metaData;
+            if 
(DeploymentConstants.TAG_SERVICE.equals(metaDataEle.getLocalName())) {
+                // if only one <service> present.
+                return checkMessageReceivers(metaDataEle);
+            } else if 
(DeploymentConstants.TAG_SERVICE_GROUP.equals(metaDataEle.getLocalName())) {
+                // if <serviceGroup> present.
+                OMElement groupMrs = metaDataEle.getFirstChildWithName(new 
QName(
+                        DeploymentConstants.TAG_MESSAGE_RECEIVERS));
+                // check MRs direct under <serviceGroup>.
+                if (groupMrs != null && !checkMessageReceivers(metaDataEle)) {
+                    return false;
+                }
+                for (Iterator<OMElement> serviceItr = metaDataEle
+                        
.getChildrenWithLocalName(DeploymentConstants.TAG_SERVICE); serviceItr
+                        .hasNext();) {
+                    // check list of <service> under <serviceGroup>.
+                    if (!checkMessageReceivers(serviceItr.next())) {
+                        return false;
+                    } else {
+                        checkOK = true;
+                    }
+                }
+            }
+        }
+        return checkOK;
+    }
+
+    private boolean checkMessageReceivers(OMElement mrsElement) {
+        boolean checkOK = false;
+        if (mrsElement != null) {
+            Iterator<OMElement> eleItr = (mrsElement)
+                    
.getChildrenWithLocalName(DeploymentConstants.TAG_MESSAGE_RECEIVERS);
+            for (Iterator<OMElement> mrItr = 
eleItr.next().getChildrenWithLocalName(
+                    DeploymentConstants.TAG_MESSAGE_RECEIVER); 
mrItr.hasNext();) {
+                OMElement mrEle = mrItr.next();
+                String mrCalssName = mrEle.getAttributeValue(new QName(
+                        DeploymentConstants.ATTRIBUTE_CLASS));
+                if (mrCalssName != null
+                        && 
!JAXWSMessageReceiver.class.getName().equals(mrCalssName)) {
+                    return false;
+                } else {
+                    checkOK = true;
+                }
+            }
+        }
+        return checkOK;
+    }
+
+}

Propchange: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSServiceBuilderExtension.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to