JBossWS SVN: r7991 - in stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core: soap and 1 other directory.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2008-08-01 12:29:11 -0400 (Fri, 01 Aug 2008)
New Revision: 7991
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java
Log:
[JBWS-2270] Re-use JAXBContext whenever possible
Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java
===================================================================
--- stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java 2008-08-01 16:22:44 UTC (rev 7990)
+++ stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java 2008-08-01 16:29:11 UTC (rev 7991)
@@ -21,18 +21,6 @@
*/
package org.jboss.ws.core.jaxws;
-import org.jboss.ws.extensions.xop.jaxws.AttachmentUnmarshallerImpl;
-import org.jboss.ws.core.binding.BindingException;
-import org.jboss.ws.core.binding.TypeMappingImpl;
-import org.jboss.ws.core.binding.ComplexTypeDeserializer;
-import org.jboss.ws.core.binding.SerializationContext;
-import org.jboss.ws.core.soap.MessageContextAssociation;
-import org.jboss.ws.metadata.umdm.EndpointMetaData;
-import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
-import org.jboss.logging.Logger;
-import org.jboss.wsf.spi.deployment.Endpoint;
-import org.jboss.wsf.spi.binding.BindingCustomization;
-
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
@@ -40,6 +28,14 @@
import javax.xml.transform.Source;
import javax.xml.ws.WebServiceException;
+import org.jboss.logging.Logger;
+import org.jboss.ws.core.binding.BindingException;
+import org.jboss.ws.core.binding.ComplexTypeDeserializer;
+import org.jboss.ws.core.binding.SerializationContext;
+import org.jboss.ws.core.binding.TypeMappingImpl;
+import org.jboss.ws.extensions.xop.jaxws.AttachmentUnmarshallerImpl;
+import org.jboss.wsf.spi.binding.BindingCustomization;
+
/**
* A Deserializer that can handle complex types by delegating to JAXB.
*
Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java
===================================================================
--- stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java 2008-08-01 16:22:44 UTC (rev 7990)
+++ stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java 2008-08-01 16:29:11 UTC (rev 7991)
@@ -21,14 +21,8 @@
*/
package org.jboss.ws.core.jaxws;
-import org.jboss.logging.Logger;
-import org.jboss.ws.extensions.xop.jaxws.AttachmentMarshallerImpl;
-import org.jboss.ws.core.binding.BindingException;
-import org.jboss.ws.core.binding.ComplexTypeSerializer;
-import org.jboss.ws.core.binding.SerializationContext;
-import org.jboss.ws.core.binding.BufferedStreamResult;
-import org.jboss.wsf.spi.binding.BindingCustomization;
-import org.w3c.dom.NamedNodeMap;
+import java.util.Arrays;
+import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
@@ -38,6 +32,15 @@
import javax.xml.transform.Result;
import javax.xml.ws.WebServiceException;
+import org.jboss.logging.Logger;
+import org.jboss.ws.core.binding.BindingException;
+import org.jboss.ws.core.binding.BufferedStreamResult;
+import org.jboss.ws.core.binding.ComplexTypeSerializer;
+import org.jboss.ws.core.binding.SerializationContext;
+import org.jboss.ws.extensions.xop.jaxws.AttachmentMarshallerImpl;
+import org.jboss.wsf.spi.binding.BindingCustomization;
+import org.w3c.dom.NamedNodeMap;
+
/**
* A Serializer that can handle complex types by delegating to JAXB.
*
@@ -61,11 +64,9 @@
Result result = null;
try
{
- // The serialization context contains the base type, which is needed for JAXB to marshall xsi:type correctly.
- // This should be more efficient and accurate than searching the type mapping
Class expectedType = serContext.getJavaType();
- Class actualType = value.getClass();
- Class[] types = shouldFilter(actualType) ? new Class[]{expectedType} : new Class[]{expectedType, actualType};
+ Class[] types = getClassesForContextCreation(serContext, value);
+
JAXBContext jaxbContext = getJAXBContext(types);
Marshaller marshaller = jaxbContext.createMarshaller();
@@ -87,8 +88,28 @@
return result;
}
-
+
/**
+ * Selects the array of classes to use to create the JAXBContext, as
+ * using the array of types registered for the current endpoint saves time.
+ *
+ * @param serContext
+ * @param value
+ * @return
+ */
+ private Class[] getClassesForContextCreation(SerializationContext serContext, Object value)
+ {
+ // The serialization context contains the base type, which is needed for JAXB to marshall xsi:type correctly.
+ // This should be more efficient and accurate than searching the type mapping
+ Class expectedType = serContext.getJavaType();
+ Class actualType = value.getClass();
+ Class[] types = shouldFilter(actualType) ? new Class[]{expectedType} : new Class[]{expectedType, actualType};
+ Class[] registeredTypes = (Class[])serContext.getProperty(SerializationContextJAXWS.JAXB_CONTEXT_TYPES);
+ List<Class> typesList = Arrays.asList(registeredTypes);
+ return typesList.containsAll(Arrays.asList(types)) ? registeredTypes : types;
+ }
+
+ /**
* Retrieve JAXBContext from cache or create new one and cache it.
* @param types
* @return JAXBContext
Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java
===================================================================
--- stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java 2008-08-01 16:22:44 UTC (rev 7990)
+++ stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java 2008-08-01 16:29:11 UTC (rev 7991)
@@ -22,6 +22,7 @@
package org.jboss.ws.core.soap;
import java.lang.reflect.Method;
+import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
@@ -36,6 +37,9 @@
import org.jboss.ws.core.binding.SerializerSupport;
import org.jboss.ws.core.binding.TypeMappingImpl;
import org.jboss.ws.core.jaxrpc.binding.NullValueSerializer;
+import org.jboss.ws.core.jaxws.SerializationContextJAXWS;
+import org.jboss.ws.metadata.umdm.OperationMetaData;
+import org.jboss.ws.metadata.umdm.ParameterMetaData;
import org.jboss.wsf.common.JavaUtils;
/**
@@ -139,6 +143,10 @@
SerializationContext serContext = msgContext.getSerializationContext();
serContext.setJavaType(javaType);
+ ParameterMetaData pmd = container.getParamMetaData();
+ OperationMetaData opMetaData = pmd.getOperationMetaData();
+ List<Class> registeredTypes = opMetaData.getEndpointMetaData().getRegisteredTypes();
+ serContext.setProperty(SerializationContextJAXWS.JAXB_CONTEXT_TYPES, registeredTypes.toArray(new Class[0]));
TypeMappingImpl typeMapping = serContext.getTypeMapping();
XMLFragment xmlFragment = null;