axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r474814 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: core/controller/ description/ description/impl/ marshaller/ marshaller/impl/ message/databinding/ message/databinding/impl/ util/
Date Tue, 14 Nov 2006 15:19:09 GMT
Author: scheu
Date: Tue Nov 14 07:19:08 2006
New Revision: 474814

URL: http://svn.apache.org/viewvc?view=rev&rev=474814
Log:
AXIS2-1697
Contributor: Rich Scheuerle
The set of Packages needed for data marshaling is now calculated and cached by the EndpointDescription.
As noted in the JIRA, there are two ways to do this (A) walk the schema or (B) walk the annotations.
This initial contribution walks the annotations.
Aside: I added a first pass at the JAXB namespace -> package algorithm (See org.apache.axis2.jaxws.utils.JavaUtils)

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/PackageSetBuilder.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/ClassUtils.java
      - copied, changed from r474807, webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/ClassUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/JavaUtils.java
Removed:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/ClassUtils.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointDescription.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/DocLitBareMethodMarshallerImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/DocLitWrappedMethodMarshallerImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/MethodMarshallerImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java?view=diff&rev=474814&r1=474813&r2=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java Tue Nov 14 07:19:08 2006
@@ -49,12 +49,12 @@
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.description.OperationDescription;
 import org.apache.axis2.jaxws.i18n.Messages;
-import org.apache.axis2.jaxws.marshaller.ClassUtils;
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
 import org.apache.axis2.jaxws.message.util.MessageUtils;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.jaxws.util.ClassUtils;
 import org.apache.axis2.jaxws.util.Constants;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HttpTransportProperties;

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointDescription.java?view=diff&rev=474814&r1=474813&r2=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointDescription.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointDescription.java Tue Nov 14 07:19:08 2006
@@ -19,6 +19,7 @@
 package org.apache.axis2.jaxws.description;
 
 import java.util.List;
+import java.util.Set;
 
 import javax.xml.namespace.QName;
 import javax.xml.ws.Service;
@@ -76,4 +77,11 @@
     public abstract QName getServiceQName();
     public abstract Service.Mode getServiceMode();
 
+    /**
+     * Returns the packages that are needed to marshal/unmarshal the 
+     * data objects.  Example: This set of packages is used to construct a 
+     * JAXBContext.
+     * @return Set<Package>
+     */
+    public Set<Package> getPackages();
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java?view=diff&rev=474814&r1=474813&r2=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java Tue Nov 14 07:19:08 2006
@@ -22,6 +22,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 
 import javax.jws.WebService;
@@ -94,6 +95,9 @@
     
     //This is the base WebService or WebServiceProvider that we are processing
     DescriptionBuilderComposite composite = null;
+ 
+    // Set of packages that are needed to marshal/unmashal data (used to set JAXBContext)
+    Set<Package> packages = null;
     
     private static final Log log = LogFactory.getLog(EndpointDescriptionImpl.class);
 
@@ -1136,6 +1140,36 @@
      */
     public List<String> getHandlerList() {
         return handlerList;
+    }
+    
+    /**
+     * Returns the packages that are needed to marshal/unmarshal the 
+     * data objects.  Example: this set of packages is used to construct a 
+     * JAXBContext.
+     * @return Set<Package>
+     */
+    public Set<Package> getPackages() {
+        // @REVIEW Currently the package set is stored on the
+        // EndpointDescription.  We may consider moving this to 
+        // ServiceDescription. 
+        
+        // The set of packages is calcuated once and saved
+        if (packages == null) {
+            synchronized(this) {
+                // @TODO There are two ways to get the packages.
+                // Schema Walk (prefered) and Annotation Walk.
+                // The Schema walk requires an existing or generated schema.
+                // For now, we will force the use of annotation walk
+                // @See PackageSetBuilder for details
+                boolean useSchemaWalk = false;
+                if (useSchemaWalk) {
+                    packages = PackageSetBuilder.getPackagesFromSchema(this.getServiceDescription());
+                } else {
+                    packages = PackageSetBuilder.getPackagesFromAnnotations(this);
+                }
+            }
+        }
+        return packages;
     }
 }
 

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/PackageSetBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/PackageSetBuilder.java?view=auto&rev=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/PackageSetBuilder.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/impl/PackageSetBuilder.java Tue Nov 14 07:19:08 2006
@@ -0,0 +1,320 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.axis2.jaxws.description.impl;
+
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.bind.JAXBElement;
+
+import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.axis2.jaxws.description.EndpointInterfaceDescription;
+import org.apache.axis2.jaxws.description.FaultDescription;
+import org.apache.axis2.jaxws.description.OperationDescription;
+import org.apache.axis2.jaxws.description.ParameterDescription;
+import org.apache.axis2.jaxws.description.ServiceDescription;
+import org.apache.axis2.jaxws.util.ClassUtils;
+import org.apache.axis2.jaxws.util.JavaUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * In order to marshal or unmarshal the user data, we need to know
+ * the set of packages involved.  The set of packages is used to construct
+ * an appropriate JAXBContext object during the marshalling/unmarshalling.
+ * 
+ * There are two ways to get this data.
+ * 
+ * Schema Walk (preferred):  Get the list of packages by walking the schemas
+ * that are referenced by the wsdl (or generated wsdl).  Each schema
+ * represents a different package.  The package is obtained using the
+ * jaxb customization or JAXB default ns<->package rule. 
+ * 
+ * Annotation Walk(secondary) : Walk the list of Endpoints, Operations,
+ * Parameters, etc. and build a list of packages by looking at the
+ * classes involved.  
+ * 
+ * The Schema Walk is faster and more complete, but relies on the 
+ * presence of the schema or wsdl.
+ * 
+ * The Annotation Walk is slower and is not complete.  For example,
+ * the annotation walk may not discover the packages for derived types
+ * that are defined in a different schema than the formal parameter types.
+ */
+public class PackageSetBuilder {
+    
+    private static Log log = LogFactory.getLog(PackageSetBuilder.class);
+
+    /**
+     * This is a static utility class.  The constructor is intentionally private
+     */
+    private PackageSetBuilder() {}
+    
+    /**
+     * Walks the schemas of the serviceDesc's wsdl (or generated wsdl) to determine the list of 
+     * packages.
+     * This is the preferred algorithm for discovering the package set.
+     * 
+     * @param serviceDesc ServiceDescription
+     * @return Set of Packages
+     */
+    public static Set<Package> getPackagesFromSchema(ServiceDescription serviceDesc) {
+        // TODO Missing Support
+        throw new UnsupportedOperationException("PackageSetBuilder.getPackagesFromSchema");
+    }
+    
+    /**
+     * @param serviceDescription ServiceDescription
+     * @return Set of Packages
+     */
+    public static Set<Package> getPackagesFromAnnotations(ServiceDescription serviceDesc) {
+        HashSet<Package> set = new HashSet<Package>();
+        EndpointDescription[] endpointDescs = serviceDesc.getEndpointDescriptions();
+        
+        // Build a set of packages from all of the endpoints
+        if (endpointDescs != null) {
+            for (int i=0; i< endpointDescs.length; i++) {
+                set.addAll(getPackagesFromAnnotations(endpointDescs[i]));
+            }
+        }
+        return set;
+    }
+    
+    /**
+     * @param endpointDesc EndpointDescription
+     * @return Set of Packages
+     */
+    public static Set<Package> getPackagesFromAnnotations(EndpointDescription endpointDesc) {
+        EndpointInterfaceDescription endpointInterfaceDesc = 
+            endpointDesc.getEndpointInterfaceDescription();
+        if (endpointInterfaceDesc == null) {
+            return new HashSet<Package>(); 
+        } else {
+            return getPackagesFromAnnotations(endpointInterfaceDesc);
+        }
+    }
+    
+    /**
+     * @param endpointInterfaceDescription EndpointInterfaceDescription
+     * @return Set of Packages
+     */
+    public static Set<Package> getPackagesFromAnnotations(EndpointInterfaceDescription endpointInterfaceDesc) {
+        HashSet<Package> set = new HashSet<Package>();
+        OperationDescription[] opDescs = endpointInterfaceDesc.getOperations();
+        
+        // Build a set of packages from all of the opertions
+        if (opDescs != null) {
+            for (int i=0; i< opDescs.length; i++) {
+                getPackagesFromAnnotations(opDescs[i], set);
+            }
+        }
+        return set;
+    }
+    
+    /**
+     * Update the package set with the packages referenced by this OperationDesc
+     * @param opDesc OperationDescription
+     * @param set Set<Package> that is updated
+     */
+    private static void getPackagesFromAnnotations(OperationDescription opDesc, Set<Package> set) {
+       
+       // Walk the parameter information
+       ParameterDescription[] parameterDescs = opDesc.getParameterDescriptions();
+       if (parameterDescs != null) {
+           for (int i=0; i <parameterDescs.length; i++) {
+               getPackagesFromAnnotations(parameterDescs[i], set);
+           }
+       }
+       
+       // Walk the fault information
+       FaultDescription[] faultDescs = opDesc.getFaultDescriptions();
+       if (faultDescs != null) {
+           for (int i=0; i <faultDescs.length; i++) {
+               getPackagesFromAnnotations(faultDescs[i], set);
+           }
+       }
+       
+       // Also consider the request and response wrappers
+       Package pkg = getPackageFromClassName(opDesc.getRequestWrapperClassName());
+       if (pkg != null) {
+           set.add(pkg);
+       }
+       pkg = getPackageFromClassName(opDesc.getResponseWrapperClassName());
+       if (pkg != null) {
+           set.add(pkg);
+       }
+    }
+    
+    /**
+     * Update the package set with the packages referenced by this ParameterDescription
+     * @param paramDesc ParameterDesc
+     * @param set Set<Package> that is updated
+     */
+    private static void getPackagesFromAnnotations(ParameterDescription paramDesc, Set<Package> set) {
+       
+       // Get the type that defines the actual data.  (this is never a holder )
+       Class paramClass = paramDesc.getParameterActualType();
+       
+       if (paramClass != null) {
+           setTypeAndElementPackages(paramClass, paramDesc.getTargetNamespace(), paramDesc.getPartName(), set);
+       }
+       
+    }
+    
+    /**
+     * Update the package set with the packages referenced by this FaultDescription
+     * @param faultDesc FaultDescription
+     * @param set Set<Package> that is updated
+     */
+    private static void getPackagesFromAnnotations(FaultDescription faultDesc, Set<Package> set) {
+      
+      Class faultBean = loadClass(faultDesc.getFaultBean());  
+      if (faultBean != null) {
+          setTypeAndElementPackages(faultBean, faultDesc.getTargetNamespace(), faultDesc.getName(), set);
+      }
+    }
+    
+    /**
+     * For each data element, we need the package for both the element and its type.
+     * @param cls Class representing element, type or both
+     * @param namespace of the element
+     * @param localPart of the element
+     * @param set with both type and element packages set
+     */
+    private static void setTypeAndElementPackages(Class cls, String namespace, String localPart, Set<Package> set) {
+        
+        // Get the element and type classes
+        Class eClass = getElement(cls);
+        Class tClass = getType(cls);
+        
+        // Set the package for the type
+        if (tClass != null) {
+            Package pkg = tClass.getPackage();
+            if (pkg != null) {
+                set.add(pkg);
+            }
+        }
+        
+        // Set the package for the element
+        if (tClass != eClass) {
+            if (eClass == null) {
+                // A null or empty namespace indicates that the element is
+                // unqualified.  This can occur if the parameter is represented as a child element 
+                // in doc/lit wrapped.  The package is determined from the wrapper element in such casses.
+                if (namespace != null && namespace.length() > 0) {
+                    // Use default namespace to package algorithm
+                    Package pkg = makePackage(namespace);
+                    if (pkg != null) {
+                        set.add(pkg);
+                    }
+                }
+            } else {
+                Package pkg = eClass.getPackage();
+                if (pkg != null) {
+                    set.add(pkg);
+                }
+            }
+        }
+    }
+    
+    /**
+     * If cls represents an xml element then cls is returned.
+     * Otherwise null is returned
+     * @param cls Class
+     * @return Class or null
+     */
+    private static Class getElement(Class cls) {
+        if (!ClassUtils.isXmlRootElementDefined(cls)) {
+            return null;
+        } 
+        return cls;
+    }
+    
+    private final static Class[] noClass = new Class[] {};
+    /** Returns the class that defines the type.
+     * @param cls
+     * @return
+     */
+    private static Class getType(Class cls) {
+        if (JAXBElement.class.isAssignableFrom(cls)) {
+            try {
+                Method m = cls.getMethod("getValue", noClass);
+                return m.getReturnType();
+            } catch (Exception e) {
+                // We should never get here
+                if (log.isDebugEnabled()) {
+                    log.debug("Cannot find JAXBElement.getValue method.");
+                }
+                return null;
+            }
+        } else {
+            return cls;
+        }
+    }
+    
+    /**
+     * Default Namespace to Package algorithm
+     * @param ns
+     * @return
+     */
+    private static Package makePackage(String ns) {
+        String pkgName = JavaUtils.getPackageFromNamespace(ns);
+        Package pkg = null;
+        if (pkgName != null) {
+            pkg = Package.getPackage(pkgName);
+        }
+        return pkg;
+    }
+    
+    /**
+     * Return the package associated with the class name.  The className may 
+     * not be specified (in which case a null Package is returned)
+     * @param className String (may be null or empty)
+     * @return Package or null if problems occur
+     */
+    private static Package getPackageFromClassName(String className) {
+        Class clz = loadClass(className);
+        Package pkg = (clz == null) ? null : clz.getPackage();
+        return pkg;
+    }
+    
+    /**
+     * Loads the class 
+     * @param className
+     * @return Class (or null if the class cannot be loaded)
+     */
+    private static Class loadClass(String className) {
+        if (className == null || className.length() == 0) {
+            return null;
+        }
+        try {
+            // TODO J2W AccessController Needed
+            // Don't make this public, its a security exposure
+            return Class.forName(className, true, Thread.currentThread().getContextClassLoader());
+            
+        } catch (ClassNotFoundException e) {
+            // TODO Should the exception be swallowed ?
+            if (log.isDebugEnabled()) {
+                log.debug("PackageSetBuilder cannot load the following class:" + className);
+            }
+        }
+        return null;
+    }
+    
+   
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/DocLitBareMethodMarshallerImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/DocLitBareMethodMarshallerImpl.java?view=diff&rev=474814&r1=474813&r2=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/DocLitBareMethodMarshallerImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/DocLitBareMethodMarshallerImpl.java Tue Nov 14 07:19:08 2006
@@ -92,7 +92,7 @@
 			}
 			else if(holdermps.size() == 0 && !returnType.getName().equals("void")){
 				// No holders but a return type example --> public ReturnType someMethod()
-				Object bo = createBusinessObject(createContextPackageSet(returnType), message);
+				Object bo = createBusinessObject(createContextPackageSet(), message);
 				return bo;
 			}
 			else if(holdermps.size()>0 && returnType.getName().equals("void")){
@@ -106,7 +106,7 @@
 				// WSGen and WsImport Generate Holders with return type as one of the Holder JAXBObject 
 				// property, if wsdl schema forces a holder and a return type.
 				assignHolderValues(holdermps, holderArgs, message);
-				Object bo = createBusinessObject(createContextPackageSet(returnType), message);
+				Object bo = createBusinessObject(createContextPackageSet(), message);
 				return bo;
 			}
 
@@ -135,7 +135,7 @@
 	        Object bo = null;
             // Create a set of context packages that will be needed to demarshal
             // the jaxb object.  For now just consider the actualType
-            Set<Package> contextPackages = createContextPackageSet(actualType);
+            Set<Package> contextPackages = createContextPackageSet();
             
             // Create the business object
 	        if(isHeader){

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/DocLitWrappedMethodMarshallerImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/DocLitWrappedMethodMarshallerImpl.java?view=diff&rev=474814&r1=474813&r2=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/DocLitWrappedMethodMarshallerImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/DocLitWrappedMethodMarshallerImpl.java Tue Nov 14 07:19:08 2006
@@ -45,6 +45,7 @@
 import org.apache.axis2.jaxws.message.databinding.JAXBUtils;
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.jaxws.util.ClassUtils;
 import org.apache.axis2.jaxws.wrapper.JAXBWrapperTool;
 import org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperException;
 import org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperToolImpl;
@@ -89,7 +90,7 @@
     		}
     		
             String resultName = operationDesc.getResultName();
-    		businessObject = createBusinessObject(createContextPackageSet(wrapperClazz), message);
+    		businessObject = createBusinessObject(createContextPackageSet(), message);
             assignHolderValues(businessObject, inputArgs, false);
             
             // REVIEW: Is the the appropriate logic, to be checking for the existence of the annotation
@@ -121,7 +122,7 @@
 			ArrayList<MethodParameter> mps;
 
 			Class requestWrapperClazz = loadClass(className);
-			Object jaxbObject = createBusinessObject(createContextPackageSet(requestWrapperClazz), message);
+			Object jaxbObject = createBusinessObject(createContextPackageSet(), message);
 
 			if (log.isDebugEnabled()) {
 				log.debug("reading input method parameters");
@@ -210,7 +211,7 @@
 			
             // If the wrapper class does not represent an root element, then make
             // the appropriate JAXBElement
-            if (!JAXBUtils.isXmlRootElementDefined(wrapperClazz)) {
+            if (!ClassUtils.isXmlRootElementDefined(wrapperClazz)) {
                 QName qName = new QName(wrapperTNS, wrapperLocalName);
                 wrapper = new JAXBElement(qName, wrapperClazz, wrapper);
             }
@@ -249,7 +250,7 @@
 
             // If the wrapper class does not represent an root element, then make
             // the appropriate JAXBElement
-            if (!JAXBUtils.isXmlRootElementDefined(wrapperClazz)) {
+            if (!ClassUtils.isXmlRootElementDefined(wrapperClazz)) {
                 QName qName = new QName(wrapperTNS, wrapperLocalName);
                 jaxbObject = new JAXBElement(qName, wrapperClazz, jaxbObject);
             }
@@ -288,7 +289,7 @@
             Object jaxbType = (jaxbElement instanceof JAXBElement) ? ((JAXBElement) jaxbElement).getValue() : jaxbElement; 
      
             // Create the context
-            JAXBBlockContext ctx = new JAXBBlockContext(createContextPackageSet(jaxbType.getClass()));
+            JAXBBlockContext ctx = new JAXBBlockContext(createContextPackageSet());
             bodyBlock = createJAXBBlock(jaxbElement, ctx);
             
             if (log.isDebugEnabled()) {

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/MethodMarshallerImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/MethodMarshallerImpl.java?view=diff&rev=474814&r1=474813&r2=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/MethodMarshallerImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/MethodMarshallerImpl.java Tue Nov 14 07:19:08 2006
@@ -51,7 +51,6 @@
 import org.apache.axis2.jaxws.description.ParameterDescription;
 import org.apache.axis2.jaxws.description.ServiceDescription;
 import org.apache.axis2.jaxws.i18n.Messages;
-import org.apache.axis2.jaxws.marshaller.ClassUtils;
 import org.apache.axis2.jaxws.marshaller.MethodMarshaller;
 import org.apache.axis2.jaxws.marshaller.MethodParameter;
 import org.apache.axis2.jaxws.message.Block;
@@ -66,6 +65,7 @@
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
 import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.jaxws.util.ClassUtils;
 import org.apache.axis2.jaxws.wrapper.JAXBWrapperTool;
 import org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperException;
 import org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperToolImpl;
@@ -147,13 +147,13 @@
 				
 				// Now demarshal the block to get a business object (faultbean)
                 // Capture the qname of the element, which will be used to find the JAX-WS Exception
-				Object obj = createFaultBusinessObject(contextPackages, block);
+				Object obj = createFaultBusinessObject(block);
                 QName faultQName = null;
                 if (obj instanceof JAXBElement) {
                     faultQName = ((JAXBElement)obj).getName();
                     obj = ((JAXBElement)obj).getValue();
                 } else {
-                    faultQName = JAXBUtils.getXmlRootElementQName(obj);
+                    faultQName = ClassUtils.getXmlRootElementQName(obj);
                 }
                 
 				// Find the JAX-WS exception using a qname match
@@ -204,14 +204,14 @@
 				// Service Exception.  Create an XMLFault with the fault bean
             	Method getFaultInfo = t.getClass().getMethod("getFaultInfo", null);
             	Object faultBean = getFaultInfo.invoke(t, null);
-            	JAXBBlockContext context = createJAXBBlockContext(createContextPackageSet(faultBean.getClass()));
+            	JAXBBlockContext context = createJAXBBlockContext(createContextPackageSet());
             	Block[] detailBlocks = new Block[1];
                 
                 // Make sure to createJAXBBlock with an object that is 
                 // a JAXBElement or has the XMLRootElement annotation
                 // The actual faultBean object's class is used (because
                 // the actual object may be a derived type of the formal declaration)
-            	if (!JAXBUtils.isXmlRootElementDefined(faultBean.getClass())) {
+            	if (!ClassUtils.isXmlRootElementDefined(faultBean.getClass())) {
                     QName faultQName = new QName(fd.getTargetNamespace(), fd.getName());
                     faultBean = new JAXBElement(faultQName, faultBean.getClass(), faultBean);
                 }
@@ -805,11 +805,11 @@
 		        }
 				throw ExceptionFactory.makeWebServiceException(Messages.getMessage("DocLitProxyHandlerErr2"));
 			}
-			JAXBBlockContext ctx = createJAXBBlockContext(createContextPackageSet(objectType));
+			JAXBBlockContext ctx = createJAXBBlockContext(createContextPackageSet());
 			if (log.isDebugEnabled()) {
 	            log.debug("Attempting to create Block");
 	        }
-			if(JAXBUtils.isXmlRootElementDefined(objectType)){
+			if(ClassUtils.isXmlRootElementDefined(objectType)){
 				block = createJAXBBlock(object, ctx);
 			}
 			else{
@@ -888,9 +888,9 @@
 	 * @throws MessageException
 	 * @throws XMLStreamException
 	 */
-	protected Object createFaultBusinessObject(Set<Package> contextPackages, Block block)
+	protected Object createFaultBusinessObject(Block block)
 			throws JAXBException, MessageException, XMLStreamException {
-		JAXBBlockContext blockContext = new JAXBBlockContext(contextPackages);		
+		JAXBBlockContext blockContext = new JAXBBlockContext(createContextPackageSet());		
 		// Get a JAXBBlockFactory instance. 
         JAXBBlockFactory factory = (JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
         
@@ -898,18 +898,19 @@
         return jaxbBlock.getBusinessObject(true); 
 	}
 	
-    protected void assignHolderValues(ArrayList<MethodParameter> mps, ArrayList<Object> inputArgHolders, Message message)throws JAXBException, MessageException, XMLStreamException{
+    protected void assignHolderValues(ArrayList<MethodParameter> mps, ArrayList<Object> inputArgHolders, Message message)
+            throws JAXBException, MessageException, XMLStreamException{
 		Object bo = null;
 		int index = 0;
 		for(MethodParameter mp:mps){
 			ParameterDescription pd = mp.getParameterDescription();
 			if (pd.isHeader() && pd.isHolderType()) {
-				bo = createBOFromHeaderBlock(createContextPackageSet(pd.getParameterActualType()),
+				bo = createBOFromHeaderBlock(createContextPackageSet(),
 						message, pd.getTargetNamespace(), pd
 								.getParameterName());
 			}
 			else if(!pd.isHeader() && pd.isHolderType()){
-				bo = createBOFromBodyBlock(createContextPackageSet(pd.getParameterActualType()), message);
+				bo = createBOFromBodyBlock(createContextPackageSet(), message);
 			}
 			try{
 				Holder inputArgHolder = (Holder)inputArgHolders.get(index);
@@ -926,22 +927,8 @@
      * @param cls
      * @return
      */
-    protected Set<Package> createContextPackageSet(Class cls) {
-        HashSet<Package> set = new HashSet<Package>();
-        set.add(cls.getPackage());
-        return set;
-    }
-    /**
-     * Simple utility to create package set from two classes
-     * @param cls1
-     * @param cls2
-     * @return
-     */
-    protected Set<Package> createContextPackageSet(Class cls1, Class cls2) {
-        HashSet<Package> set = new HashSet<Package>();
-        set.add(cls1.getPackage());
-        set.add(cls2.getPackage());
-        return set;
+    protected Set<Package> createContextPackageSet() {
+         return operationDesc.getEndpointInterfaceDescription().getEndpointDescription().getPackages();
     }
 	
     protected void assignHolderValues(Object bo, Object[] inputArgs, boolean isBare)throws JAXBWrapperException, InstantiationException, ClassNotFoundException, IllegalAccessException{

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java?view=diff&rev=474814&r1=474813&r2=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java Tue Nov 14 07:19:08 2006
@@ -25,17 +25,13 @@
 import java.util.WeakHashMap;
 
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.JAXBIntrospector;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlSchema;
-import javax.xml.namespace.QName;
 
-import org.apache.axis2.jaxws.marshaller.ClassUtils;
 import org.apache.axis2.jaxws.message.databinding.impl.JAXBBlockImpl;
+import org.apache.axis2.jaxws.util.ClassUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -251,62 +247,4 @@
         }
         imap.put(context, introspector);
 	}
-
-    /**
-     * @param clazz
-     * @return namespace of root element qname or null if this is not object does not represent a root element
-     */
-    public static QName getXmlRootElementQName(Object obj){
-        
-        // A JAXBElement stores its name
-        if (obj instanceof JAXBElement) {
-            return ((JAXBElement) obj).getName();
-        }
-        
-        Class clazz = obj.getClass();
-        
-    	// If the clazz is a primitive, then it does not have a corresponding root element.
-    	if (clazz.isPrimitive() ||
-    	    ClassUtils.getWrapperClass(clazz) != null) {
-    		return null;
-    	}
-    	
-    	// See if the object represents a root element
-    	XmlRootElement root = (XmlRootElement) clazz.getAnnotation(XmlRootElement.class);
-        if (root == null) {
-            return null;
-        }
-        
-        String namespace = root.namespace();
-        String localPart = root.name();
-        
-        // The namespace may need to be defaulted
-        if (namespace == null || namespace.length() == 0 || namespace.equals("##default")) {
-            Package pkg = clazz.getPackage();
-            XmlSchema schema = (XmlSchema) pkg.getAnnotation(XmlSchema.class);
-            if (schema != null) {
-                namespace = schema.namespace();
-            } else {
-                return null;
-            }
-        }
-    	return new QName(namespace, localPart);
-    }
-
-    /**
-     * @param clazz
-     * @return true if this class has a corresponding xml root element
-     */
-    public static boolean isXmlRootElementDefined(Class clazz){
-        // If the clazz is a primitive, then it does not have a corresponding root element.
-        if (clazz.isPrimitive() ||
-            ClassUtils.getWrapperClass(clazz) != null) {
-            return false;
-        }
-        // TODO We could also prune out other known classes that will not have root elements defined.
-        // java.util.Date, arrays, java.math.BigInteger.
-        
-        XmlRootElement root = (XmlRootElement) clazz.getAnnotation(XmlRootElement.class);
-        return root !=null;
-    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java?view=diff&rev=474814&r1=474813&r2=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java Tue Nov 14 07:19:08 2006
@@ -27,9 +27,9 @@
 import org.apache.axis2.jaxws.message.Block;
 import org.apache.axis2.jaxws.message.MessageException;
 import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
-import org.apache.axis2.jaxws.message.databinding.JAXBUtils;
 import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
 import org.apache.axis2.jaxws.message.impl.BlockFactoryImpl;
+import org.apache.axis2.jaxws.util.ClassUtils;
 
 /**
  * JAXBBlockFactoryImpl
@@ -77,7 +77,7 @@
         
         // The business object must be either a JAXBElement or a block with an @XmlRootElement qname.  The best way
         // to verify this is to get the QName from the business object.
-        QName bQName = JAXBUtils.getXmlRootElementQName(businessObject);
+        QName bQName = ClassUtils.getXmlRootElementQName(businessObject);
         if (bQName == null) {
             throw ExceptionFactory.makeMessageException(Messages.getMessage("JAXBBlockFactoryErr2", businessObject.getClass().getName()), null);
         }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java?view=diff&rev=474814&r1=474813&r2=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java Tue Nov 14 07:19:08 2006
@@ -44,6 +44,7 @@
 import org.apache.axis2.jaxws.message.databinding.JAXBUtils;
 import org.apache.axis2.jaxws.message.factory.BlockFactory;
 import org.apache.axis2.jaxws.message.impl.BlockImpl;
+import org.apache.axis2.jaxws.util.ClassUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -109,7 +110,7 @@
             jaxb = u.unmarshal(reader);
             
             // Set the qname 
-            QName qName = JAXBUtils.getXmlRootElementQName(jaxb);
+            QName qName = ClassUtils.getXmlRootElementQName(jaxb);
             if (qName != null) {  // qname should always be non-null
                 setQName(qName); 
             }

Copied: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/ClassUtils.java (from r474807, webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/ClassUtils.java)
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/ClassUtils.java?view=diff&rev=474814&p1=webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/ClassUtils.java&r1=474807&p2=webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/ClassUtils.java&r2=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/ClassUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/ClassUtils.java Tue Nov 14 07:19:08 2006
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.axis2.jaxws.marshaller;
+package org.apache.axis2.jaxws.util;
 
 import java.io.File;
 import java.io.IOException;
@@ -29,6 +29,10 @@
 import java.util.List;
 
 import javax.jws.WebService;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchema;
+import javax.xml.namespace.QName;
 import javax.xml.ws.Holder;
 import javax.xml.ws.WebFault;
 import javax.xml.ws.WebServiceClient;
@@ -235,76 +239,79 @@
 	 * @return
 	 * @throws ClassNotFoundException
 	 */
-	public static List<Class> getAllClassesFromPackage(Package pkg) throws ClassNotFoundException {
-	        // This will hold a list of directories matching the pckgname. There may be more than one if a package is split over multiple jars/paths
-	        String pckgname = pkg.getName();
-            ArrayList<File> directories = new ArrayList<File>();
-	        try {
-	            ClassLoader cld = Thread.currentThread().getContextClassLoader();
-	            if (cld == null) {
-	            	if(log.isDebugEnabled()){
-	            		log.debug("Unable to get class loader");
-	            	}
-	                throw new ClassNotFoundException(Messages.getMessage("ClassUtilsErr1"));
-	            }
-	            String path = pckgname.replace('.', '/');
-	            // Ask for all resources for the path
-	            Enumeration<URL> resources = cld.getResources(path);
-	            while (resources.hasMoreElements()) {
-	                directories.add(new File(URLDecoder.decode(resources.nextElement().getPath(), "UTF-8")));
-	            }
-	        } catch (UnsupportedEncodingException e) {
-	        	if(log.isDebugEnabled()){
-            		log.debug(pckgname + " does not appear to be a valid package (Unsupported encoding)");
-            	}
-	            throw new ClassNotFoundException(Messages.getMessage("ClassUtilsErr2", pckgname));
-	        } catch (IOException e) {
-	        	if(log.isDebugEnabled()){
-            		log.debug("IOException was thrown when trying to get all resources for "+ pckgname);
-            	}
-	            throw new ClassNotFoundException(Messages.getMessage("ClassUtilsErr3", pckgname));
-	        }
-	 
-	        ArrayList<Class> classes = new ArrayList<Class>();
-	        // For every directory identified capture all the .class files
-	        for (File directory : directories) {
-	            if (log.isDebugEnabled()) {
-	                log.debug("Adding classes from: " + directory.getName());
+    public static List<Class> getAllClassesFromPackage(Package pkg) throws ClassNotFoundException {
+        if (pkg == null) {
+            return new ArrayList<Class>();
+        }   
+        // This will hold a list of directories matching the pckgname. There may be more than one if a package is split over multiple jars/paths
+        String pckgname = pkg.getName();
+        ArrayList<File> directories = new ArrayList<File>();
+        try {
+            ClassLoader cld = Thread.currentThread().getContextClassLoader();
+            if (cld == null) {
+                if(log.isDebugEnabled()){
+                    log.debug("Unable to get class loader");
                 }
-                if (directory.exists()) {
-	                // Get the list of the files contained in the package
-	                String[] files = directory.list();
-	                for (String file : files) {
-                        // we are only interested in .class files
-	                    if (file.endsWith(".class")) {
-                            // removes the .class extension
-	                    	// TODO Java2 Sec
-	                    	try {
-	                    		Class clazz = Class.forName(pckgname + '.' + file.substring(0, file.length() - 6), 
-                                        false, 
-                                        Thread.currentThread().getContextClassLoader());
-	                    		// Don't add any interfaces or JAXWS specific classes.  
-                                // Only classes that represent data and can be marshalled 
-                                // by JAXB should be added.
-	                    		if(!clazz.isInterface() 
-                                   && getDefaultPublicConstructor(clazz) != null
-                                   && !isJAXWSClass(clazz)){
-	                    			if (log.isDebugEnabled()) {
-	                    			    log.debug("Adding class: " + file);
-                                    }
-                                    classes.add(clazz);
-	                    		}
-	                    	} catch (Exception e) {
-	                    	    e.printStackTrace();
+                throw new ClassNotFoundException(Messages.getMessage("ClassUtilsErr1"));
+            }
+            String path = pckgname.replace('.', '/');
+            // Ask for all resources for the path
+            Enumeration<URL> resources = cld.getResources(path);
+            while (resources.hasMoreElements()) {
+                directories.add(new File(URLDecoder.decode(resources.nextElement().getPath(), "UTF-8")));
+            }
+        } catch (UnsupportedEncodingException e) {
+            if(log.isDebugEnabled()){
+                log.debug(pckgname + " does not appear to be a valid package (Unsupported encoding)");
+            }
+            throw new ClassNotFoundException(Messages.getMessage("ClassUtilsErr2", pckgname));
+        } catch (IOException e) {
+            if(log.isDebugEnabled()){
+                log.debug("IOException was thrown when trying to get all resources for "+ pckgname);
+            }
+            throw new ClassNotFoundException(Messages.getMessage("ClassUtilsErr3", pckgname));
+        }
+        
+        ArrayList<Class> classes = new ArrayList<Class>();
+        // For every directory identified capture all the .class files
+        for (File directory : directories) {
+            if (log.isDebugEnabled()) {
+                log.debug("Adding classes from: " + directory.getName());
+            }
+            if (directory.exists()) {
+                // Get the list of the files contained in the package
+                String[] files = directory.list();
+                for (String file : files) {
+                    // we are only interested in .class files
+                    if (file.endsWith(".class")) {
+                        // removes the .class extension
+                        // TODO Java2 Sec
+                        try {
+                            Class clazz = Class.forName(pckgname + '.' + file.substring(0, file.length() - 6), 
+                                    false, 
+                                    Thread.currentThread().getContextClassLoader());
+                            // Don't add any interfaces or JAXWS specific classes.  
+                            // Only classes that represent data and can be marshalled 
+                            // by JAXB should be added.
+                            if(!clazz.isInterface() 
+                                    && getDefaultPublicConstructor(clazz) != null
+                                    && !isJAXWSClass(clazz)){
+                                if (log.isDebugEnabled()) {
+                                    log.debug("Adding class: " + file);
+                                }
+                                classes.add(clazz);
                             }
-	                       
-	                    }
-	                }
-	            }
-	        }
-	        return classes;
-	    }
-	
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                        
+                    }
+                }
+            }
+        }
+        return classes;
+    }
+    
 	private static final Class[] noClass=new Class[] {};
 	/**
 	 * Get the default public constructor
@@ -361,5 +368,64 @@
         }
         return false;
     }
+
+    
+    /**
+     * @param clazz
+     * @return namespace of root element qname or null if this is not object does not represent a root element
+     */
+    public static QName getXmlRootElementQName(Object obj){
+        
+        // A JAXBElement stores its name
+        if (obj instanceof JAXBElement) {
+            return ((JAXBElement) obj).getName();
+        }
+        
+        Class clazz = obj.getClass();
+        
+        // If the clazz is a primitive, then it does not have a corresponding root element.
+        if (clazz.isPrimitive() ||
+                getWrapperClass(clazz) != null) {
+            return null;
+        }
+        
+        // See if the object represents a root element
+        XmlRootElement root = (XmlRootElement) clazz.getAnnotation(XmlRootElement.class);
+        if (root == null) {
+            return null;
+        }
+        
+        String namespace = root.namespace();
+        String localPart = root.name();
+        
+        // The namespace may need to be defaulted
+        if (namespace == null || namespace.length() == 0 || namespace.equals("##default")) {
+            Package pkg = clazz.getPackage();
+            XmlSchema schema = (XmlSchema) pkg.getAnnotation(XmlSchema.class);
+            if (schema != null) {
+                namespace = schema.namespace();
+            } else {
+                return null;
+            }
+        }
+        return new QName(namespace, localPart);
+    }
     
+    /**
+     * @param clazz
+     * @return true if this class has a corresponding xml root element
+     */
+    public static boolean isXmlRootElementDefined(Class clazz){
+        // If the clazz is a primitive, then it does not have a corresponding root element.
+        if (clazz.isPrimitive() ||
+                getWrapperClass(clazz) != null) {
+            return false;
+        }
+        // TODO We could also prune out other known classes that will not have root elements defined.
+        // java.util.Date, arrays, java.math.BigInteger.
+        
+        XmlRootElement root = (XmlRootElement) clazz.getAnnotation(XmlRootElement.class);
+        return root !=null;
+    }
 }
+

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/JavaUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/JavaUtils.java?view=auto&rev=474814
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/JavaUtils.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/JavaUtils.java Tue Nov 14 07:19:08 2006
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.axis2.jaxws.util;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+/**
+ * Common Java Utilites
+ *
+ */
+public class JavaUtils extends org.apache.axis2.util.JavaUtils {
+    
+    /**
+     * Private Constructor...All methods of this class are static
+     */
+    private JavaUtils() {}
+    
+    /**
+     * Namespace 2 Package algorithm as defined by the JAXB Specification
+     * @param Namespace
+     * @return String represeting Namespace
+     */
+    public static String getPackageFromNamespace(String namespace) {
+        // The following steps correspond to steps described in the JAXB Specification
+        
+        // Step 1: Scan off the host name
+        String hostname = null;
+        try {
+            hostname = new URL(namespace).getHost();
+        }
+        catch (MalformedURLException e) {
+               // No FFDC code needed
+            if (namespace.indexOf(":") > -1) {
+                // Brain-dead code to skip over the protocol
+                hostname = namespace.substring(namespace.indexOf(":") + 1);
+            }
+            else {
+                hostname = namespace;
+            }
+        }
+        
+        // Step 3: Tokenize the host name using ":" and "/"
+        StringTokenizer st = new StringTokenizer( hostname, ":/" );
+        String[] words = new String[ st.countTokens() ];
+        for(int i = 0; i < words.length; ++i) {
+            words[i] = st.nextToken();
+        }
+        
+        // Now do step 2: Strip off the trailing "." (i.e. strip off .html)
+        String lastWord = words[words.length-1];
+        int index = lastWord.lastIndexOf('.');
+        if (index > 0) {
+            words[words.length-1] = lastWord.substring(0,index);
+        }
+        
+        
+        // Step 4: Unescape each escape sequence
+        // TODO I don't know what to do here.
+        
+        // Step 5: If protocol is urn, replace - with . in the first word
+        if (namespace.startsWith("urn:")) {
+            words[0] = replace(words[0], "-", ".");
+        }
+        
+        // Step 6: Tokenize the first word with "." and reverse the order. (the www is also removed).
+        // TODO This is not exactly equivalent to the JAXB Rule.
+        StringTokenizer st2 = new StringTokenizer(words[0], ".");
+        ArrayList<String> list = new ArrayList<String>();
+        while(st2.hasMoreTokens()) {
+            // Add the strings so they are in reverse order
+            list.add(0,st2.nextToken());
+        }
+        // Remove www
+        String last = list.get(list.size()-1);
+        if (last.equals("www")) {
+            list.remove(list.size()-1);
+        }
+        // Now each of words is represented by list
+        for (int i=1; i<words.length; i++) {
+            list.add(words[i]);
+        }
+        
+        // Step 7: lowercase each word
+        // Step 8: make into and an appropriate java word
+        for (int i =0; i<list.size(); i++) {
+            String word = list.get(i);
+            word = word.toLowerCase();
+            
+            // Convert non-java words to underscore.
+            // TODO: Need to do this for all chars..not just hyphens
+            word = replace(word, "-", "_");
+            if (JavaUtils.isJavaKeyword(word)) {
+                word = word + "_";
+            }
+            if (!Character.isJavaIdentifierPart(word.charAt(0)) ) {
+                word = "_" + word;
+            }
+            
+            list.set(i, word);
+        }
+        
+        // Step 9: Concatenate and return
+        String name = "";
+        for (int i =0; i<list.size(); i++) {
+            if (i == 0) {
+                name = list.get(0);
+            } else {
+                name = "." + list.get(i);
+            }
+        }
+        return name;
+    }
+    
+    /**
+     * replace:
+     * Like String.replace except that the old new items are strings.
+     *
+     * @param name string
+     * @param oldT old text to replace
+     * @param newT new text to use
+     * @return replacement string
+     **/
+    public static final String replace (String name,
+                                        String oldT, String newT) {
+
+        if (name == null) return "";
+
+        // Create a string buffer that is twice initial length.
+        // This is a good starting point.
+        StringBuffer sb = new StringBuffer(name.length()* 2);
+
+        int len = oldT.length ();
+        try {
+            int start = 0;
+            int i = name.indexOf (oldT, start);
+
+            while (i >= 0) {
+                sb.append(name.substring(start, i));
+                sb.append(newT);
+                start = i+len;
+                i = name.indexOf(oldT, start);
+            }
+            if (start < name.length())
+                sb.append(name.substring(start));
+        } catch (NullPointerException e) {
+               // No FFDC code needed
+        }
+
+        return new String(sb);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message