axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r473734 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/client/ src/org/apache/axis2/jaxws/i18n/ src/org/apache/axis2/jaxws/marshaller/ src/org/apache/axis2/jaxws/marshaller/impl/ src/org/apache/axis2/jaxws/mess...
Date Sat, 11 Nov 2006 15:38:40 GMT
Author: scheu
Date: Sat Nov 11 07:38:39 2006
New Revision: 473734

URL: http://svn.apache.org/viewvc?view=rev&rev=473734
Log:
AXIS2-1678
Contributor:Rich Scheuerle
Changes to JAX-WS Block subsystem and usage to ensure that the JAXB object in a block can always be rendered as an element.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatch.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatchAsyncListener.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
    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/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/JAXBBlockContext.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
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/JAXBBlockFactory.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/JAXBWrapperTool.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperToolImpl.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/MTOMSerializationTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/jaxb/wrapper/WrapperToolTest.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/BlockTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageRPCTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatch.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatch.java Sat Nov 11 07:38:39 2006
@@ -22,11 +22,11 @@
 import org.apache.axis2.jaxws.client.async.AsyncResponse;
 import org.apache.axis2.jaxws.handler.PortData;
 import org.apache.axis2.jaxws.impl.AsyncListener;
-import org.apache.axis2.jaxws.marshaller.ClassUtils;
 import org.apache.axis2.jaxws.message.Block;
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.Protocol;
 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.factory.MessageFactory;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
@@ -60,7 +60,12 @@
             JAXBBlockFactory factory = (JAXBBlockFactory) FactoryRegistry.getFactory(JAXBBlockFactory.class);
             
             Class clazz = value.getClass();
-            JAXBBlockContext context = new JAXBBlockContext(clazz, !ClassUtils.isXmlRootElementDefined(clazz), jaxbContext);
+            JAXBBlockContext context = null;
+            if (jaxbContext != null) {
+                context = new JAXBBlockContext(jaxbContext);
+            } else {
+                context = new JAXBBlockContext(clazz.getPackage());
+            }
             Block block = factory.createFrom(value, context, null);
             
             // The protocol of the Message that is created should be based
@@ -81,7 +86,7 @@
         Object value = null;
         try {
             JAXBBlockFactory factory = (JAXBBlockFactory) FactoryRegistry.getFactory(JAXBBlockFactory.class);
-            JAXBBlockContext context = new JAXBBlockContext(null, false, jaxbContext);
+            JAXBBlockContext context = new JAXBBlockContext(jaxbContext);
             Block block = message.getBodyBlock(0, context, factory);
             value = block.getBusinessObject(true);
         } catch (Exception e) {

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatchAsyncListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatchAsyncListener.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatchAsyncListener.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatchAsyncListener.java Sat Nov 11 07:38:39 2006
@@ -56,7 +56,7 @@
         Message message = mc.getMessage();
         try {
             JAXBBlockFactory factory = (JAXBBlockFactory) FactoryRegistry.getFactory(JAXBBlockFactory.class);
-            JAXBBlockContext context = new JAXBBlockContext(null, false, jaxbContext);
+            JAXBBlockContext context = new JAXBBlockContext(jaxbContext);
             Block block = message.getBodyBlock(0, context, factory);
             value = block.getBusinessObject(true);
         } catch (Exception e) {

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties Sat Nov 11 07:38:39 2006
@@ -120,6 +120,7 @@
 NoMaintainSessionProperty=Error: Maintain Session is enabled but none of the Session Properties (Cookies, Over-written URL) is returned.
 NullValueForMaintainSessionProperty=Error: The value of {0} Session property is NULL.
 JAXBBlockFactoryErr1=An internal assertion error occurred.  The context parameter of JAXBBlockFactory should be a JAXBBlockContext object, but a {0} object was found.
+JAXBBlockFactoryErr2=An internal assertion error occurred.  The business object parameter of JAXBBlockFactory should be a JAXBElement or an object with an @XmlRootElement annotation, but a {0} object was found.
 WebServiceContextInjectionImplErr1=Cannot inject Resource on a null Service Instance.
 WebServiceContextInjectionImplErr2=Injection on Private and Protected set methods not supported yet.
 WebServiceContextInjectionImplErr3=Cannot inject WebServiceContext on ServiceInstance Field, field cannot be NULL.

Modified: 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/marshaller/ClassUtils.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- 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/marshaller/ClassUtils.java Sat Nov 11 07:38:39 2006
@@ -32,10 +32,6 @@
 import java.util.List;
 
 import javax.management.openmbean.SimpleType;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlSchema;
-import javax.xml.namespace.QName;
 
 
 import org.apache.axis2.jaxws.i18n.Messages;
@@ -74,70 +70,7 @@
         return e;
     }
 	
-	/**
-	 * @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;
-    }
-    
-    
-	
-	
-    
-    
-    private static HashMap loadClassMap = new HashMap();
+	private static HashMap loadClassMap = new HashMap();
     static {
         loadClassMap.put("byte", byte.class);
         loadClassMap.put("int", int.class);
@@ -298,13 +231,14 @@
     
     /**
 	 * This method will return all the Class names excluding the interfaces from a given package. 
-	 * @param pckgname
+	 * @param pkg Package
 	 * @return
 	 * @throws ClassNotFoundException
 	 */
-	public static List<Class> getAllClassesFromPackage(String pckgname) 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
-	        ArrayList<File> directories = new ArrayList<File>();
+	        String pckgname = pkg.getName();
+            ArrayList<File> directories = new ArrayList<File>();
 	        try {
 	            ClassLoader cld = Thread.currentThread().getContextClassLoader();
 	            if (cld == 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=473734&r1=473733&r2=473734
==============================================================================
--- 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 Sat Nov 11 07:38:39 2006
@@ -19,9 +19,11 @@
 package org.apache.axis2.jaxws.marshaller.impl;
 
 import java.util.ArrayList;
+import java.util.Set;
 
 import javax.xml.bind.JAXBException;
 import javax.xml.stream.XMLStreamException;
+import javax.xml.ws.Holder;
 import javax.xml.ws.WebServiceException;
 
 import org.apache.axis2.jaxws.ExceptionFactory;
@@ -90,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(returnType, message);
+				Object bo = createBusinessObject(createContextPackageSet(returnType), message);
 				return bo;
 			}
 			else if(holdermps.size()>0 && returnType.getName().equals("void")){
@@ -104,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(returnType, message);
+				Object bo = createBusinessObject(createContextPackageSet(returnType), message);
 				return bo;
 			}
 
@@ -114,6 +116,47 @@
 			// Firewall.  Only WebServiceExceptions are thrown
 			throw ExceptionFactory.makeWebServiceException(e);
 		}
+        
+    }
+	private ArrayList<MethodParameter> createParameterForSEIMethod(Message message)throws IllegalAccessException, InstantiationException, ClassNotFoundException, MessageException, XMLStreamException, JAXBException{
+	    ArrayList<MethodParameter> mps = new ArrayList<MethodParameter>();
+	    if(message == null){
+	        return null;
+	    }
+	    ParameterDescription[] paramDescs = operationDesc.getParameterDescriptions();
+	    
+	    ArrayList<Object> paramValues = new ArrayList<Object>(); 
+	    for (int index = 0; index < paramDescs.length; index++) {
+	        ParameterDescription paramDesc = paramDescs[index];
+	        String paramName = paramDesc.getParameterName();
+	        String paramTNS = paramDesc.getTargetNamespace();
+	        boolean isHeader = paramDesc.isHeader();
+	        Class actualType = paramDesc.getParameterActualType();
+	        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);
+            
+            // Create the business object
+	        if(isHeader){
+	            bo = createBOFromHeaderBlock(contextPackages, message, paramTNS, paramName);
+	        }
+	        else{
+	            bo = createBOFromBodyBlock(contextPackages,message);
+	        }
+	        
+            // Now create an argument from the business object
+            Object arg = bo;
+	        if (paramDesc.isHolderType()) {
+                // If the parameter requires a holder, create a holder
+                // object containting the parameter
+	            arg = createHolder(paramDesc.getParameterType(), bo);
+	        } 
+	        paramValues.add(arg);
+	    }
+	    mps = createParameters(paramDescs, paramValues);
+	    
+	    return mps;
 	}
 
 	/* (non-Javadoc)

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=473734&r1=473733&r2=473734
==============================================================================
--- 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 Sat Nov 11 07:38:39 2006
@@ -20,7 +20,9 @@
 
 import java.util.ArrayList;
 
+import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.ws.WebServiceException;
 
@@ -32,9 +34,14 @@
 import org.apache.axis2.jaxws.description.ServiceDescription;
 import org.apache.axis2.jaxws.marshaller.DocLitWrappedMethodMarshaller;
 import org.apache.axis2.jaxws.marshaller.MethodParameter;
+import org.apache.axis2.jaxws.message.Block;
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
 import org.apache.axis2.jaxws.message.Protocol;
+import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
+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.wrapper.JAXBWrapperTool;
 import org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperToolImpl;
 import org.apache.commons.logging.Log;
@@ -78,7 +85,7 @@
     		}
     		
             String resultName = operationDesc.getResultName();
-    		businessObject = createBusinessObject(wrapperClazz, message);
+    		businessObject = createBusinessObject(createContextPackageSet(wrapperClazz), message);
             assignHolderValues(businessObject, inputArgs, false);
             
             // REVIEW: Is the the appropriate logic, to be checking for the existence of the annotation
@@ -110,7 +117,7 @@
 			ArrayList<MethodParameter> mps;
 
 			Class requestWrapperClazz = loadClass(className);
-			Object jaxbObject = createBusinessObject(requestWrapperClazz, message);
+			Object jaxbObject = createBusinessObject(createContextPackageSet(requestWrapperClazz), message);
 
 			if (log.isDebugEnabled()) {
 				log.debug("reading input method parameters");
@@ -150,7 +157,7 @@
 			// Get the necessary information from the OperationDesc
 			Class wrapperClazz = null;
 			String wrapperClazzName = operationDesc.getResponseWrapperClassName();
-			String wrapperXMLElementName = operationDesc.getResponseWrapperLocalName();
+			String wrapperLocalName = operationDesc.getResponseWrapperLocalName();
 			String wrapperTNS = operationDesc.getResponseWrapperTargetNamespace();
 			String webResult = operationDesc.getResultName();
 
@@ -196,8 +203,15 @@
 			}
 
 			JAXBWrapperTool wrapperTool = new JAXBWrapperToolImpl();
-			Object wrapper = wrapperTool.wrap(wrapperClazz, wrapperClazzName, mps);
-			Message message = createMessage(wrapper, wrapperClazz, wrapperXMLElementName, wrapperTNS);
+			Object wrapper = wrapperTool.wrap(wrapperClazz, mps);
+			
+            // If the wrapper class does not represent an root element, then make
+            // the appropriate JAXBElement
+            if (!JAXBUtils.isXmlRootElementDefined(wrapperClazz)) {
+                QName qName = new QName(wrapperTNS, wrapperLocalName);
+                wrapper = new JAXBElement(qName, wrapperClazz, wrapper);
+            }
+			Message message = createMessage(wrapper);
 
 
 			return message;
@@ -215,7 +229,7 @@
 	public Message marshalRequest(Object[] objects) throws WebServiceException {
 		try {
 			String className = operationDesc.getRequestWrapperClassName();
-			String localName = operationDesc.getRequestWrapperLocalName();
+			String wrapperLocalName = operationDesc.getRequestWrapperLocalName();
 			String wrapperTNS = operationDesc.getRequestWrapperTargetNamespace();
 
 			Class wrapperClazz = null;
@@ -231,12 +245,18 @@
 				log.debug("JAXBWrapperTool attempting to wrap propertes in WrapperClass :" + wrapperClazz);
 			}
 
-			jaxbObject = wrapTool.wrap(wrapperClazz, localName, methodParameters);
+			jaxbObject = wrapTool.wrap(wrapperClazz, methodParameters);
 			if (log.isDebugEnabled()) {
 				log.debug("JAXBWrapperTool wrapped following propertes :");
 			}
 
-			Message message = createMessage(jaxbObject, wrapperClazz, localName, wrapperTNS);
+            // If the wrapper class does not represent an root element, then make
+            // the appropriate JAXBElement
+            if (!JAXBUtils.isXmlRootElementDefined(wrapperClazz)) {
+                QName qName = new QName(wrapperTNS, wrapperLocalName);
+                jaxbObject = new JAXBElement(qName, wrapperClazz, jaxbObject);
+            }
+			Message message = createMessage(jaxbObject);
 
 
 			return message;
@@ -256,4 +276,32 @@
         Class c = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
 		return c;
 	}
+    
+    /**
+     * @param jaxbElement object representing the element to marshal (JAXBElement or object has @XmlRootElement)
+     * @return
+     * @throws JAXBException
+     * @throws MessageException
+     * @throws XMLStreamException
+     */
+    private Message createMessage(Object jaxbElement)throws JAXBException, MessageException, XMLStreamException{
+            Block bodyBlock = null;
+            
+            // Get the object that is the type
+            Object jaxbType = (jaxbElement instanceof JAXBElement) ? ((JAXBElement) jaxbElement).getValue() : jaxbElement; 
+     
+            // Create the context
+            JAXBBlockContext ctx = new JAXBBlockContext(createContextPackageSet(jaxbType.getClass()));
+            bodyBlock = createJAXBBlock(jaxbElement, ctx);
+            
+            if (log.isDebugEnabled()) {
+                log.debug("JAXBBlock Created");
+            }
+            
+            MessageFactory mf = (MessageFactory)FactoryRegistry.getFactory(MessageFactory.class);
+            
+            Message m = mf.create(protocol);
+            m.setBodyBlock(0,bodyBlock);
+            return m;
+        }
 }

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=473734&r1=473733&r2=473734
==============================================================================
--- 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 Sat Nov 11 07:38:39 2006
@@ -25,6 +25,8 @@
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.concurrent.Future;
 
 import javax.jws.WebParam.Mode;
@@ -133,10 +135,10 @@
 			} else {
 				// Create a JAXBContext object that can handle any of the 
 				// checked exceptions defined on this operation
-				Class[] classes = new Class[operationDesc.getFaultDescriptions().length];
+                HashSet<Package> contextPackages = new HashSet<Package>();
 				for(int i=0; i<operationDesc.getFaultDescriptions().length; i++) {
 					FaultDescription fd = operationDesc.getFaultDescriptions()[i];
-					classes[i] = loadClass(fd.getFaultBean());
+					contextPackages.add(loadClass(fd.getFaultBean()).getPackage());
 				}
 				
 				// TODO what if there are multiple blocks in the detail ?
@@ -145,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(classes, block);
+				Object obj = createFaultBusinessObject(contextPackages, block);
                 QName faultQName = null;
                 if (obj instanceof JAXBElement) {
                     faultQName = ((JAXBElement)obj).getName();
                     obj = ((JAXBElement)obj).getValue();
                 } else {
-                    faultQName = ClassUtils.getXmlRootElementQName(obj);
+                    faultQName = JAXBUtils.getXmlRootElementQName(obj);
                 }
                 
 				// Find the JAX-WS exception using a qname match
@@ -202,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(faultBean.getClass());
+            	JAXBBlockContext context = createJAXBBlockContext(createContextPackageSet(faultBean.getClass()));
             	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 (!ClassUtils.isXmlRootElementDefined(faultBean.getClass())) {
+            	if (!JAXBUtils.isXmlRootElementDefined(faultBean.getClass())) {
                     QName faultQName = new QName(fd.getTargetNamespace(), fd.getName());
                     faultBean = new JAXBElement(faultQName, faultBean.getClass(), faultBean);
                 }
@@ -399,40 +401,7 @@
         
 	}
 	
-	protected ArrayList<MethodParameter> createParameterForSEIMethod(Message message)throws IllegalAccessException, InstantiationException, ClassNotFoundException, MessageException, XMLStreamException, JAXBException{
-		ArrayList<MethodParameter> mps = new ArrayList<MethodParameter>();
- 		if(message == null){
- 			return null;
- 		}
-		ParameterDescription[] paramDescs = operationDesc.getParameterDescriptions();
-		
-		ArrayList<Object> paramValues = new ArrayList<Object>(); 
-		for (int index = 0; index < paramDescs.length; index++) {
-			ParameterDescription paramDesc = paramDescs[index];
-			String paramName = paramDesc.getParameterName();
-			String paramTNS = paramDesc.getTargetNamespace();
-			boolean isHeader = paramDesc.isHeader();
-			Class actualType = paramDesc.getParameterActualType();
-			Object bo = null;
-			if(isHeader){
-				bo = createBOFromHeaderBlock(actualType, message, paramTNS, paramName);
-			}
-			else{
-				bo = createBOFromBodyBlock(actualType,message);
-			}
-			
-			if (bo != null && !isHolder(bo)
-					&& paramDesc.isHolderType()) {
-				Holder<Object> holder = createHolder(paramDesc.getParameterType(),
-						bo);
-				bo = holder;
-			}
-			paramValues.add(bo);
-		}
-		mps = createParameters(paramDescs, paramValues);
-		
-		return mps;
-	}
+	
 	/*
 	 * Extract Holder parameter from supplied parameters and add annotation data for these parameters.
 	 */
@@ -543,7 +512,8 @@
 					
 		return mps;
 	}
-	private ArrayList<MethodParameter> createParameters(
+    
+	protected ArrayList<MethodParameter> createParameters(
 			ParameterDescription[] paramDescs, ArrayList<Object> paramValues){
 		ArrayList<MethodParameter> mps = new ArrayList<MethodParameter>();
 		int index = 0;
@@ -835,11 +805,11 @@
 		        }
 				throw ExceptionFactory.makeWebServiceException(Messages.getMessage("DocLitProxyHandlerErr2"));
 			}
-			JAXBBlockContext ctx = createJAXBBlockContext(objectType);
+			JAXBBlockContext ctx = createJAXBBlockContext(createContextPackageSet(objectType));
 			if (log.isDebugEnabled()) {
 	            log.debug("Attempting to create Block");
 	        }
-			if(ClassUtils.isXmlRootElementDefined(objectType)){
+			if(JAXBUtils.isXmlRootElementDefined(objectType)){
 				block = createJAXBBlock(object, ctx);
 			}
 			else{
@@ -865,29 +835,6 @@
 		return m;
 	}
 	
-	protected Message createMessage(Object jaxbObject, Class jaxbClazz, String jaxbClassName, String targetNamespace)throws JAXBException, MessageException, XMLStreamException{
-		Block bodyBlock = null;
-		JAXBBlockContext ctx = createJAXBBlockContext(jaxbClazz);
-		if (log.isDebugEnabled()) {
-            log.debug("Attempting to create Block");
-        }
-		if(ClassUtils.isXmlRootElementDefined(jaxbClazz)){
-			bodyBlock = createJAXBBlock(jaxbObject, ctx);
-		}
-		else{
-			bodyBlock =  createJAXBBlock(jaxbClassName, jaxbObject, ctx, targetNamespace);
-		}
-		if (log.isDebugEnabled()) {
-            log.debug("JAXBBlock Created");
-        }
-		
-		MessageFactory mf = (MessageFactory)FactoryRegistry.getFactory(MessageFactory.class);
-		
-		Message m = mf.create(protocol);
-		m.setBodyBlock(0,bodyBlock);
-		return m;
-	}
-	
 	protected Message createFaultMessage(OMElement element) throws XMLStreamException, MessageException {
 		MessageFactory mf = (MessageFactory)FactoryRegistry.getFactory(MessageFactory.class);
 		return mf.createFrom(element);
@@ -901,9 +848,9 @@
 		return m;
 	}
 	
-	protected Object createBOFromHeaderBlock(Class jaxbClazz, Message message, String targetNamespace, String localPart) throws JAXBException, MessageException, XMLStreamException{
+	protected Object createBOFromHeaderBlock(Set<Package> contextPackages, Message message, String targetNamespace, String localPart) throws JAXBException, MessageException, XMLStreamException{
 		
-		JAXBBlockContext blockContext = createJAXBBlockContext(jaxbClazz);
+		JAXBBlockContext blockContext = createJAXBBlockContext(contextPackages);
 		
 		// Get a JAXBBlockFactory instance.  We'll need this to get the JAXBBlock
         // out of the Message
@@ -912,13 +859,13 @@
         return block.getBusinessObject(true);
 	}
 	
-	protected Object createBOFromBodyBlock(Class jaxbClazz, Message message) throws JAXBException, MessageException, XMLStreamException{
-		return createBusinessObject(jaxbClazz, message);
+	protected Object createBOFromBodyBlock(Set<Package> contextPackages, Message message) throws JAXBException, MessageException, XMLStreamException{
+		return createBusinessObject(contextPackages, message);
 	}
 
 	
-	protected Object createBusinessObject(Class jaxbClazz, Message message) throws JAXBException, MessageException, XMLStreamException{
-		JAXBBlockContext blockContext = createJAXBBlockContext(jaxbClazz);
+	protected Object createBusinessObject(Set<Package> contextPackages, Message message) throws JAXBException, MessageException, XMLStreamException{
+		JAXBBlockContext blockContext = createJAXBBlockContext(contextPackages);
 		
 		// Get a JAXBBlockFactory instance.  We'll need this to get the JAXBBlock
         // out of the Message
@@ -928,26 +875,22 @@
         return block.getBusinessObject(true);
 	}
 	
-	private JAXBBlockContext createJAXBBlockContext(Class jaxbClazz) throws JAXBException, MessageException {
-		// Primitives, simpleTypes and classes without a root element must be represented as a JAXBElement
-		boolean useJAXBElement = !ClassUtils.isXmlRootElementDefined(jaxbClazz);
-			
-		JAXBBlockContext blockContext = new JAXBBlockContext(jaxbClazz, useJAXBElement);
-		
+	private JAXBBlockContext createJAXBBlockContext(Set<Package> contextPackages) throws JAXBException, MessageException {
+		JAXBBlockContext blockContext = new JAXBBlockContext(contextPackages);
 		return blockContext;
 	}
 
 	/**
-	 * @param possibleClasses
+	 * @param contextPackages
 	 * @param block
 	 * @return
 	 * @throws JAXBException
 	 * @throws MessageException
 	 * @throws XMLStreamException
 	 */
-	protected Object createFaultBusinessObject(Class[] possibleClasses, Block block)
+	protected Object createFaultBusinessObject(Set<Package> contextPackages, Block block)
 			throws JAXBException, MessageException, XMLStreamException {
-		JAXBBlockContext blockContext = new JAXBBlockContext(possibleClasses, false);		
+		JAXBBlockContext blockContext = new JAXBBlockContext(contextPackages);		
 		// Get a JAXBBlockFactory instance. 
         JAXBBlockFactory factory = (JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
         
@@ -961,12 +904,12 @@
 		for(MethodParameter mp:mps){
 			ParameterDescription pd = mp.getParameterDescription();
 			if (pd.isHeader() && pd.isHolderType()) {
-				bo = createBOFromHeaderBlock(pd.getParameterActualType(),
+				bo = createBOFromHeaderBlock(createContextPackageSet(pd.getParameterActualType()),
 						message, pd.getTargetNamespace(), pd
 								.getParameterName());
 			}
 			else if(!pd.isHeader() && pd.isHolderType()){
-				bo = createBOFromBodyBlock(pd.getParameterActualType(), message);
+				bo = createBOFromBodyBlock(createContextPackageSet(pd.getParameterActualType()), message);
 			}
 			try{
 				Holder inputArgHolder = (Holder)inputArgHolders.get(index);
@@ -976,9 +919,30 @@
 				ExceptionFactory.makeWebServiceException(e);
 			}
 		}
-		
-	
 	}
+    
+    /**
+     * Simple utility to create package set from a single class
+     * @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 void assignHolderValues(Object bo, Object[] inputArgs, boolean isBare)throws JAXBWrapperException, InstantiationException, ClassNotFoundException, IllegalAccessException{
 		if(inputArgs == null){

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java Sat Nov 11 07:38:39 2006
@@ -16,92 +16,66 @@
  */
 package org.apache.axis2.jaxws.message.databinding;
 
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 
 /*
- * A JAXBBlockContext controls access to the JAXB Context/Marshal/Unmarshal code.
+ * A JAXBBlockContext controls access to the JAXB Context
  * In addition the JAXBBlockContext contains additional contextural information needed
- * by the JAX-WS component (i.e. the possible type(s) of the object)
+ * by the JAX-WS component
  * 
  * This class is immutable after construction.
  */
 public class JAXBBlockContext {
 
-	private Class[] types = null;
+	private Set<Package> contextPackages;  // List of packages needed by the context
 	private JAXBContext jaxbContext = null;
-	private boolean useJAXBElement = false;
 	
 	/**
 	 * Normal Constructor JAXBBlockContext
-	 * @param type Class object that represents the actual type of the object.
-	 * @param useJAXBElement boolean indicating whether the object should be rendered
-	 * as a JAXBElement.
-	 * 
-	 * Example: if the object is a primitive (type=int.class) then 
-	 * useJAXBElement must be set to true because int is not a JAXB object.
-	 * 
-	 * Example: if the object is a JAXB object you would normally set useJAXBElement
-	 * to false.  However if the JAXB object does not have a corresponding root element,
-	 * then useJAXBElement hould be set to false.
+	 * @param packages Set of packages needed by the JAXBContext.
 	 */
-	public JAXBBlockContext(Class type, boolean useJAXBElement) {
-		this(type, useJAXBElement, null);
+	public JAXBBlockContext(Set<Package> packages) {
+        this.contextPackages = packages;
 	}
+    
+    /**
+     * Normal Constructor JAXBBlockContext
+     * @param contextPackage
+     */
+    public JAXBBlockContext(Package contextPackage) {
+        this.contextPackages = new HashSet();
+        this.contextPackages.add(contextPackage);
+    }
 
 	/**
 	 * "Dispatch" Constructor
 	 * Use this full constructor when the JAXBContent is provided by
 	 * the customer.  
-	 * @param type
-	 * @param useJAXBElement
 	 * @param jaxbContext
 	 */
-	public JAXBBlockContext(Class type, boolean useJAXBElement, JAXBContext jaxbContext) {
-		this.types = new Class[] {type};
-		this.useJAXBElement = useJAXBElement;
-		this.jaxbContext = jaxbContext;
-	}
-	
-	/**
-	 * Constructor JAXBBlockContext
-	 * @param types Class[] object that represents the actual type of the object.
-	 * @param useJAXBElement boolean indicating whether the object should be rendered
-	 * as a JAXBElement.
-	 * 
-	 * This constructor is used when the demarshalling exceptions.
-	 */
-	public JAXBBlockContext(Class[] types, boolean useJAXBElement) {
-		this.types = types;
-		this.useJAXBElement = useJAXBElement;
+	public JAXBBlockContext(JAXBContext jaxbContext) {
 		this.jaxbContext = jaxbContext;
 	}
 
 	/**
 	 * @return Class representing type of the element
 	 */
-	public Class[] getTypes() {
-		return types;
+	public Set<Package> getContextPackages() {
+		return contextPackages;
 	}
-
-	/**
-	 * @return indicate if object should be rendered as JAXBElement
-	 */
-	public boolean isUseJAXBElement() {
-		return useJAXBElement;
-	}
-
+    
 	/**
 	 * @return get the JAXBContext
 	 * @throws JAXBException
 	 */
 	public JAXBContext getJAXBContext() throws JAXBException {
 		if (jaxbContext == null) {	
-			if (!useJAXBElement) {
-				jaxbContext = JAXBUtils.getJAXBContext(types);
-			} else {
-				jaxbContext = JAXBUtils.getJAXBContext(types);
-			}
+			jaxbContext = JAXBUtils.getJAXBContext(contextPackages);
 		}
 		return jaxbContext;
 	}

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=473734&r1=473733&r2=473734
==============================================================================
--- 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 Sat Nov 11 07:38:39 2006
@@ -18,15 +18,21 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 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;
@@ -42,9 +48,9 @@
 	
     private static final Log log = LogFactory.getLog(JAXBUtils.class);
     
-	// Create a synchronized weak hashmap key=class name, value= JAXBContext
-	private static Map<String, JAXBContext> map =
-			Collections.synchronizedMap(new WeakHashMap<String, JAXBContext>());
+	// Create a synchronized weak hashmap key=set contextPackages, value= JAXBContext
+	private static Map<Set<Package>, JAXBContext> map =
+			Collections.synchronizedMap(new WeakHashMap<Set<Package>, JAXBContext>());
 	private static JAXBContext genericJAXBContext = null;
 	
 	private static Map<JAXBContext,Unmarshaller> umap = 
@@ -81,48 +87,37 @@
 	
 	/**
 	 * Get a JAXBContext for the class
-	 * @param cls Class
+	 * @param contextPackage Set<Package>
 	 * @return JAXBContext
 	 * @throws JAXBException
 	 */
-	public static JAXBContext getJAXBContext(Class[] classes) throws JAXBException {
+	public static JAXBContext getJAXBContext(Set<Package> contextPackages) throws JAXBException {
 		// JAXBContexts for the same class can be reused and are supposed to be thread-safe
-		// TODO Can we cache by package name ?
-		Class cls = classes[0];
-        if (cls.isPrimitive()) {
+        if (contextPackages == null || contextPackages.isEmpty()) {
             return getGenericJAXBContext();
         }
-		JAXBContext context = map.get(cls.getName());
+		JAXBContext context = map.get(contextPackages);
 		if (context == null) {
             synchronized(map) {
                 try{
-                	// TODO
-                	// For now we are generating a list of all of the classes in each
-                	// of the referenced packages.  We have plans to use a contextPath instead
-                	List<Class> fullList = new ArrayList<Class>();
-                	for (int i=0; i<classes.length; i++) {
-                		Package pkg = classes[i].getPackage();
-                		if (log.isDebugEnabled()) {
-                			log.debug("Package for " + classes[i].getName() + " "+pkg.getName());
-                		}
-                		if (log.isDebugEnabled()) {
-                			log.debug("Attempting to read all classes from package " + pkg.getName());
-                		}
-                		fullList.addAll(ClassUtils.getAllClassesFromPackage(pkg.getName()));
+                    Iterator<Package> it = contextPackages.iterator();
+                    List<Class> fullList = new ArrayList<Class>();
+                    while (it.hasNext()) {
+                		fullList.addAll(ClassUtils.getAllClassesFromPackage(it.next()));
                 	}
                 	Class[] classArray = fullList.toArray(new Class[0]);
                 	context = JAXBContext.newInstance(classArray);
-                    map.put(cls.getName(), context);	
+                    map.put(contextPackages, context);	
                 }catch(ClassNotFoundException e){
                 	throw new JAXBException(e);
                 }
                 if (log.isDebugEnabled()) {
-                    log.debug("JAXBContext [created] for" + cls.getName());
+                    log.debug("JAXBContext [created] for" + contextPackages.toString());
                 }
             }
 		} else {
             if (log.isDebugEnabled()) {
-                log.debug("JAXBContext [from pool] for" + cls.getName());
+                log.debug("JAXBContext [from pool] for" + contextPackages.toString());
             }
         }
 		return context;
@@ -255,4 +250,62 @@
         }
         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=473734&r1=473733&r2=473734
==============================================================================
--- 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 Sat Nov 11 07:38:39 2006
@@ -27,6 +27,7 @@
 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;
 
@@ -64,7 +65,7 @@
 	 */
 	public Block createFrom(Object businessObject, Object context, QName qName) throws MessageException {
 		
-		// The context for a JAXBFactory must be non-null and should be a JAXBBlockContext.
+		// The context must be non-null and should be a JAXBBlockContext.
 		// For legacy reasons, a JAXBContext is also supported (and wrapped into a JAXBBlockContext)
 		if (context == null) {
 			throw ExceptionFactory.makeMessageException(Messages.getMessage("JAXBBlockFactoryErr1", "null"), null);
@@ -73,6 +74,18 @@
 		} else {
 			throw ExceptionFactory.makeMessageException(Messages.getMessage("JAXBBlockFactoryErr1", context.getClass().getName()), null);
 		}
+        
+        // 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);
+        if (bQName == null) {
+            throw ExceptionFactory.makeMessageException(Messages.getMessage("JAXBBlockFactoryErr2", businessObject.getClass().getName()), null);
+        }
+        
+        // If the business obect qname does not match the parameter, use the business object qname
+        if (!bQName.equals(qName)) {
+            qName = bQName;
+        }
 		try {
 			return new JAXBBlockImpl(businessObject, (JAXBBlockContext) context, qName, this);
 		} catch (JAXBException e) {

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=473734&r1=473733&r2=473734
==============================================================================
--- 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 Sat Nov 11 07:38:39 2006
@@ -50,7 +50,7 @@
 /**
  * JAXBBlockImpl
  * 
- * A Block containing a JAXB business object
+ * A Block containing a JAXB business object (either a JAXBElement or an object with @XmlRootElement)
  */
 public class JAXBBlockImpl extends BlockImpl implements JAXBBlock {
 
@@ -58,7 +58,8 @@
     
 	/**
 	 * Called by JAXBBlockFactory
-	 * @param busObject
+	 * @param busObject..The business object must be a JAXBElement or an object
+     * with an @XMLRootElement.  This is assertion is validated in the JAXBFactory.
 	 * @param busContext
 	 * @param qName
 	 * @param factory
@@ -103,15 +104,15 @@
                 u.setAttachmentUnmarshaller(aum);
             }
             Object jaxb = null;
-            if (!ctx.isUseJAXBElement()){
-            	// Normal Unmarshalling
-            	jaxb = u.unmarshal(reader);
-				setQName(getQName(jaxb, ctx));
-			} else {
-				// Unmarshal as a JAXBElement and then get the value
-				JAXBElement jaxbElement = u.unmarshal(reader, ctx.getTypes()[0]); 
-				jaxb = jaxbElement.getValue();
-			}
+            
+            // Unmarshal into the business object.
+            jaxb = u.unmarshal(reader);
+            
+            // Set the qname 
+            QName qName = JAXBUtils.getXmlRootElementQName(jaxb);
+            if (qName != null) {  // qname should always be non-null
+                setQName(qName); 
+            }
             
             // Successfully unmarshalled the object
             // TODO remove attachment unmarshaller ?
@@ -176,7 +177,6 @@
             }   
             
             m.marshal(busObject, writer);
-            
             
             // Successfully marshalled the data
             // TODO remove attachment marshaller ?

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/JAXBBlockFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/JAXBBlockFactory.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/JAXBBlockFactory.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/JAXBBlockFactory.java Sat Nov 11 07:38:39 2006
@@ -20,7 +20,9 @@
 /**
  * JAXBBlockFactory
  * 
- * Creates a JAXBBlock
+ * Creates a JAXBBlock.  The business object of a JAXBBlock must
+ * be either a JAXBElement or a generated object with the XMLRootElement 
+ * annotation
  * 
  * * The FactoryRegistry should be used to get access to the Factory
  * @see org.apache.axis2.jaxws.registry.FactoryRegistry

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/JAXBWrapperTool.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/JAXBWrapperTool.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/JAXBWrapperTool.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/JAXBWrapperTool.java Sat Nov 11 07:38:39 2006
@@ -30,7 +30,7 @@
 	/**
      * unwrap
      * Returns the list of child elements of the jaxb object
-     * @param javab Object that is the wrapper element
+     * @param jaxbObject that is the wrapper element (JAXBElement or object with @XMLRootElement)
      * @param jaxbContext JAXBContext
      * @param childNames list of xml child names as String
      * @return list of Objects in the same order as the element names.
@@ -40,35 +40,28 @@
 
     /**
      * wrap
-     * Creates a jaxb object that is initialized with the child objects
-     * @param javabClass Class of the JAXB object to return
-     * @param jaxbContext JAXBContext
+     * Creates a jaxb object that is initialized with the child objects.
+     * 
+     * Note that the jaxbClass must be the class the represents the complexType. (It should never be JAXBElement)
+     * 
+     * @param jaxbClass 
      * @param childObjects, component objects
      * @param childNames list of xml child names as String
      * @return list of Objects in the same order as the element names.
      */ 
-    public Object wrap(Class jaxbClass, String jaxbClassName, ArrayList<String> childNames, Map<String, Object> childObjects) throws JAXBWrapperException;
+    public Object wrap(Class jaxbClass, ArrayList<String> childNames, Map<String, Object> childObjects) throws JAXBWrapperException;
     /**
      * wrap
      * Creates a jaxb object that is initialized with the child objects
+     * 
+     * * Note that the jaxbClass must be the class the represents the complexType. (It should never be JAXBElement)
+     * 
      * @param jaxbClass
-     * @param jaxbClassName
      * @param methodParameters
      * @return
      * @throws JAXBWrapperException
      */
-    public Object wrap(Class jaxbClass, String jaxbClassName, ArrayList<MethodParameter> methodParameters) throws JAXBWrapperException;
-    /**
-     * wrapAsJAXBElement
-     * Creates a JAXBElement that is initialized with the child objects and can be serialsed to xml later.
-     * @param javabClass Class of the JAXB object to return
-     * @param jaxbContext JAXBContext
-     * @param childObjects, component objects
-     * @param childNames list of xml child names as String
-     * @return JAXBElement;
-     */
-    public JAXBElement wrapAsJAXBElement(Class jaxbClass, String jaxbClassName,
-			ArrayList<String> childNames, Map<String, Object> childObjects) throws JAXBWrapperException;
-		
+    public Object wrap(Class jaxbClass, ArrayList<MethodParameter> methodParameters) throws JAXBWrapperException;
+    
 }
 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperToolImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperToolImpl.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperToolImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/JAXBWrapperToolImpl.java Sat Nov 11 07:38:39 2006
@@ -56,11 +56,17 @@
 			if(childNames == null){
 				throw new JAXBWrapperException(Messages.getMessage("JAXBWrapperErr2"));
 			}
+            
+            // Get the object that will have the property descriptors (i.e. the object representing the complexType)
+            Object jaxbComplexTypeObj = (jaxbObject instanceof JAXBElement) ?
+                    ((JAXBElement)jaxbObject).getValue() : // Type object is the value of the JAXBElement
+                        jaxbObject;                        // Or JAXBObject represents both the element and anon complexType
+            
 			ArrayList<Object> objList = new ArrayList<Object>();
-			Map<String , PropertyInfo> pdTable = createPropertyDescriptors(jaxbObject.getClass(), childNames);
+			Map<String , PropertyInfo> pdTable = createPropertyDescriptors(jaxbComplexTypeObj.getClass(), childNames);
 			for(String childName:childNames){
 				PropertyInfo propInfo = pdTable.get(childName);
-				Object object = propInfo.get(jaxbObject);
+				Object object = propInfo.get(jaxbComplexTypeObj);
 				objList.add(object);
 			}
 			Object[] jaxbObjects = objList.toArray();
@@ -80,7 +86,7 @@
 	/* (non-Javadoc)
 	 * @see org.apache.axis2.jaxws.wrapped.JAXBWrapperTool#wrap(java.lang.Class, java.lang.String, java.util.ArrayList, java.util.ArrayList)
 	 */
-	public Object wrap(Class jaxbClass, String jaxbClassName,
+	public Object wrap(Class jaxbClass, 
 			ArrayList<String> childNames, Map<String, Object> childObjects)
 			throws JAXBWrapperException {
 		
@@ -111,7 +117,7 @@
 		}
 	}
 	
-	public Object wrap(Class jaxbClass, String jaxbClassName, ArrayList<MethodParameter> mps) throws JAXBWrapperException{
+	public Object wrap(Class jaxbClass, ArrayList<MethodParameter> mps) throws JAXBWrapperException{
 		if(mps == null){
 			throw new JAXBWrapperException(Messages.getMessage("JAXBWrapperErr7"));
 		}
@@ -130,15 +136,7 @@
 			nameList.add(name);
 			objectList.put(name, object);
 		}
-		return wrap(jaxbClass, jaxbClassName, nameList, objectList);
-	}
-	
-	public JAXBElement wrapAsJAXBElement(Class jaxbClass, String jaxbClassName,
-			ArrayList<String> childNames, Map<String, Object> childObjects) throws JAXBWrapperException{
-		
-		Object obj = wrap( jaxbClass, jaxbClassName, childNames, childObjects);
-		JAXBElement<Object> element = new JAXBElement<Object>(new QName(jaxbClassName), jaxbClass, obj);
-		return element;
+		return wrap(jaxbClass, nameList, objectList);
 	}
 	
 	/** creates propertyDescriptor for the childNames using the jaxbClass.  

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/MTOMSerializationTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/MTOMSerializationTests.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/MTOMSerializationTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/MTOMSerializationTests.java Sat Nov 11 07:38:39 2006
@@ -117,7 +117,7 @@
         imageDepot.setImageData(dataHandler);
         
         //JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
-        JAXBBlockContext context = new JAXBBlockContext(SendImage.class, false);
+        JAXBBlockContext context = new JAXBBlockContext(SendImage.class.getPackage());
         
         //Create a request bean with imagedepot bean as value
         ObjectFactory factory = new ObjectFactory();

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/jaxb/wrapper/WrapperToolTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/jaxb/wrapper/WrapperToolTest.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/jaxb/wrapper/WrapperToolTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/jaxb/wrapper/WrapperToolTest.java Sat Nov 11 07:38:39 2006
@@ -41,7 +41,7 @@
 			String symbolObj = new String("IBM");
 			Map<String, Object> childObjects= new WeakHashMap<String, Object>();
 			childObjects.put(childName, symbolObj);
-			Object jaxbObject = wrapper.wrap(jaxbClass, jaxbClassName,childNames, childObjects);
+			Object jaxbObject = wrapper.wrap(jaxbClass, childNames, childObjects);
 			org.test.stock2.GetPrice getPrice = (org.test.stock2.GetPrice)jaxbObject;
 			
 		}catch(JAXBWrapperException e){
@@ -92,7 +92,7 @@
 			childObjects.put(holding, topHolding);
 			childObjects.put(nav, navInMillion);
 			
-			Object jaxbObject = wrapper.wrap(jaxbClass, jaxbClassName,childNames, childObjects);
+			Object jaxbObject = wrapper.wrap(jaxbClass, childNames, childObjects);
 			org.test.stock1.GetPrice getPrice = (org.test.stock1.GetPrice)jaxbObject;
 			
 		}catch(JAXBWrapperException e){

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/BlockTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/BlockTests.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/BlockTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/BlockTests.java Sat Nov 11 07:38:39 2006
@@ -327,7 +327,7 @@
         ObjectFactory factory = new ObjectFactory();
         EchoString jaxb = factory.createEchoString(); 
         jaxb.setInput("Hello World");
-        JAXBBlockContext context = new JAXBBlockContext(EchoString.class, false);
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage());
        
         JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
         QName expectedQName = jbi.getElementName(jaxb);
@@ -376,7 +376,7 @@
         ObjectFactory factory = new ObjectFactory();
         EchoString jaxb = factory.createEchoString(); 
         jaxb.setInput("Hello World");
-        JAXBBlockContext context = new JAXBBlockContext(EchoString.class, false);
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage());
         
         JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
         QName expectedQName = jbi.getElementName(jaxb);
@@ -425,7 +425,7 @@
         ObjectFactory factory = new ObjectFactory();
         EchoString jaxb = factory.createEchoString(); 
         jaxb.setInput("Hello World");
-        JAXBBlockContext context = new JAXBBlockContext(EchoString.class, false);
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage());
 		
 		// On inbound, there will already be a XMLStreamReader (probably from OM)
 		// which represents the message.  We will simulate this with inflow.
@@ -472,7 +472,7 @@
         ObjectFactory factory = new ObjectFactory();
         EchoString jaxb = factory.createEchoString(); 
         jaxb.setInput("Hello World");
-        JAXBBlockContext context = new JAXBBlockContext(EchoString.class, false);
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage());
 
         JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
         QName expectedQName = jbi.getElementName(jaxb);
@@ -528,7 +528,7 @@
         ObjectFactory factory = new ObjectFactory();
         EchoString jaxb = factory.createEchoString(); 
         jaxb.setInput("Hello World");
-        JAXBBlockContext context = new JAXBBlockContext(EchoString.class, false);
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage());
         
         JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
         QName expectedQName = jbi.getElementName(jaxb);

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageRPCTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageRPCTests.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageRPCTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageRPCTests.java Sat Nov 11 07:38:39 2006
@@ -111,7 +111,7 @@
             FactoryRegistry.getFactory(JAXBBlockFactory.class);
         
         // Create the JAXBContext
-        JAXBBlockContext context = new JAXBBlockContext(StockPrice.class, true);
+        JAXBBlockContext context = new JAXBBlockContext(StockPrice.class.getPackage());
         
         // Create the JAX-B object
         ObjectFactory of = new ObjectFactory();
@@ -186,7 +186,7 @@
             FactoryRegistry.getFactory(JAXBBlockFactory.class);
         
         // Create the JAXBContext
-        JAXBBlockContext context = new JAXBBlockContext(StockPrice.class, false);
+        JAXBBlockContext context = new JAXBBlockContext(StockPrice.class.getPackage());
         
         // Create the JAX-B object
         ObjectFactory of = new ObjectFactory();
@@ -282,7 +282,7 @@
         
         // Create the JAXBContext instance that will be used
         // to deserialize the JAX-B object content in the message.
-        JAXBBlockContext context = new JAXBBlockContext(StockPrice.class, true);
+        JAXBBlockContext context = new JAXBBlockContext(StockPrice.class.getPackage());
         
         // Get the JAXBBlock that wraps the content
         Block b = m.getBodyBlock(0, context, bf);

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java?view=diff&rev=473734&r1=473733&r2=473734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java Sat Nov 11 07:38:39 2006
@@ -507,7 +507,7 @@
         obj.setEchoStringReturn("sample return value");
         
         // Create the JAXBContext
-        JAXBBlockContext context = new JAXBBlockContext(EchoStringResponse.class, false);
+        JAXBBlockContext context = new JAXBBlockContext(EchoStringResponse.class.getPackage());
         
         // Create a JAXBBlock using the Echo object as the content.  This simulates
         // what occurs on the outbound JAX-WS Dispatch<Object> client
@@ -573,7 +573,7 @@
         obj.setEchoStringReturn("sample return value");
         
         // Create the JAXBContext
-        JAXBBlockContext context = new JAXBBlockContext(EchoStringResponse.class, false);
+        JAXBBlockContext context = new JAXBBlockContext(EchoStringResponse.class.getPackage());
        
         // Create a JAXBBlock using the Echo object as the content.  This simulates
         // what occurs on the outbound JAX-WS Dispatch<Object> client
@@ -655,7 +655,7 @@
         
         // Create the JAXBContext instance that will be used
         // to deserialize the JAX-B object content in the message.
-        JAXBBlockContext context = new JAXBBlockContext(EchoStringResponse.class, false);
+        JAXBBlockContext context = new JAXBBlockContext(EchoStringResponse.class.getPackage());
         
         // Get the JAXBBlock that wraps the content
         Block b = m.getBodyBlock(0, context, bf);



---------------------------------------------------------------------
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