Author: thomas.diesler(a)jboss.com
Date: 2007-01-24 12:24:03 -0500 (Wed, 24 Jan 2007)
New Revision: 2082
Modified:
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/utils/JavaUtils.java
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveXOPScanner.java
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/umdm/FaultMetaData.java
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/umdm/ParameterMetaData.java
Log:
Refactor wrapper generation to be more explicit
Modified:
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java
===================================================================
---
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java 2007-01-24
15:12:07 UTC (rev 2081)
+++
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java 2007-01-24
17:24:03 UTC (rev 2082)
@@ -75,10 +75,7 @@
*/
public void generate(ParameterMetaData pmd)
{
- // If a wrapper already present, no need to generate one
String wrapperName = pmd.getJavaTypeName();
- if (JavaUtils.isLoaded(wrapperName, loader))
- return;
List<WrappedParameter> wrappedParameters = pmd.getWrappedParameters();
OperationMetaData opMetaData = pmd.getOperationMetaData();
@@ -119,11 +116,7 @@
public void generate(FaultMetaData fmd)
{
- // If a wrapper already present, no need to generate one
String faultBeanName = fmd.getFaultBeanName();
- if (faultBeanName == null || JavaUtils.isLoaded(faultBeanName, loader))
- return;
-
log.debug("Generating fault bean: " + faultBeanName);
QName xmlType = fmd.getXmlType();
Modified:
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/utils/JavaUtils.java
===================================================================
---
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/utils/JavaUtils.java 2007-01-24
15:12:07 UTC (rev 2081)
+++
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/utils/JavaUtils.java 2007-01-24
17:24:03 UTC (rev 2082)
@@ -520,20 +520,6 @@
return c + source.substring(1);
}
- public static boolean isLoaded(String className, ClassLoader loader)
- {
- try
- {
- loadJavaType(className, loader);
- }
- catch (ClassNotFoundException e)
- {
- return false;
- }
-
- return true;
- }
-
public static String getPackageName(Class<?> clazz)
{
String fullName = clazz.getName();
Modified:
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveXOPScanner.java
===================================================================
---
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveXOPScanner.java 2007-01-24
15:12:07 UTC (rev 2081)
+++
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveXOPScanner.java 2007-01-24
17:24:03 UTC (rev 2082)
@@ -21,17 +21,18 @@
*/
package org.jboss.ws.extensions.xop.jaxws;
-import org.jboss.ws.core.utils.JavaUtils;
-
-import javax.activation.DataHandler;
-import javax.xml.bind.annotation.XmlMimeType;
-import javax.xml.transform.Source;
-import java.awt.*;
+import java.awt.Image;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
+import javax.activation.DataHandler;
+import javax.xml.bind.annotation.XmlMimeType;
+import javax.xml.transform.Source;
+
+import org.jboss.ws.core.utils.JavaUtils;
+
/**
* Scans data types for MTOM declarations.
* In order to re-use an instance of this class you need to invoke
<code>reset()</code>
Modified:
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
===================================================================
---
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java 2007-01-24
15:12:07 UTC (rev 2081)
+++
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java 2007-01-24
17:24:03 UTC (rev 2082)
@@ -52,8 +52,8 @@
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
import javax.xml.ws.WebFault;
+import javax.xml.ws.addressing.Action;
import javax.xml.ws.addressing.AddressingProperties;
-import javax.xml.ws.addressing.Action;
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
@@ -292,7 +292,7 @@
FaultMetaData fmd = new FaultMetaData(omd, xmlName, xmlType, exception.getName());
fmd.setFaultBeanName(faultBeanName);
- if (generate)
+ if (fmd.loadFaultBean() == null)
wrapperGenerator.generate(fmd);
javaTypes.add(fmd.getFaultBean());
@@ -718,16 +718,22 @@
// Generate wrapper beans
if (opMetaData.isDocumentWrapped())
{
- wrapperGenerator.generate(wrapperParameter);
+ if (wrapperParameter.loadWrapperBean() == null)
+ wrapperGenerator.generate(wrapperParameter);
+
Class wrapperClass = wrapperParameter.getJavaType();
javaTypes.add(wrapperClass);
+
// In case there is no @XmlRootElement
typeRefs.add(new TypeReference(wrapperParameter.getXmlName(), wrapperClass));
if (!opMetaData.isOneWay())
{
- wrapperGenerator.generate(wrapperOutputParameter);
+ if (wrapperOutputParameter.loadWrapperBean() == null)
+ wrapperGenerator.generate(wrapperOutputParameter);
+
wrapperClass = wrapperOutputParameter.getJavaType();
javaTypes.add(wrapperClass);
+
// In case there is no @XmlRootElement
typeRefs.add(new TypeReference(wrapperOutputParameter.getXmlName(),
wrapperClass));
}
Modified:
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/umdm/FaultMetaData.java
===================================================================
---
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/umdm/FaultMetaData.java 2007-01-24
15:12:07 UTC (rev 2081)
+++
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/umdm/FaultMetaData.java 2007-01-24
17:24:03 UTC (rev 2082)
@@ -42,6 +42,7 @@
import org.jboss.ws.core.utils.JavaUtils;
import org.jboss.ws.metadata.acessor.ReflectiveFieldAccessor;
import org.jboss.ws.metadata.acessor.ReflectiveMethodAccessor;
+import org.jboss.ws.metadata.umdm.EndpointMetaData.Type;
/**
* A Fault component describes a fault that a given operation supports.
@@ -65,7 +66,7 @@
private Class<? extends Exception> javaType;
private Class<?> faultBean;
- private Method getFaultInfoMethod;
+ private Method faultInfoMethod;
private Constructor<? extends Exception> serviceExceptionConstructor;
private Method[] serviceExceptionGetters;
@@ -156,6 +157,21 @@
this.faultBeanName = faultBeanName;
}
+ public Class loadFaultBean()
+ {
+ Class faultBean = null;
+ try
+ {
+ ClassLoader loader =
getOperationMetaData().getEndpointMetaData().getClassLoader();
+ faultBean = JavaUtils.loadJavaType(faultBeanName, loader);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ // ignore
+ }
+ return faultBean;
+ }
+
public Class getFaultBean()
{
Class tmpFaultBean = faultBean;
@@ -181,17 +197,27 @@
public void eagerInitialize()
{
- ClassLoader loader = opMetaData.getEndpointMetaData().getClassLoader();
- new DynamicWrapperGenerator(loader).generate(this);
+ Type epType = getOperationMetaData().getEndpointMetaData().getType();
+ if (epType == EndpointMetaData.Type.JAXWS && faultBeanName != null)
+ {
+ if (loadFaultBean() == null)
+ {
+ ClassLoader loader = opMetaData.getEndpointMetaData().getClassLoader();
+ new DynamicWrapperGenerator(loader).generate(this);
+ }
+ }
// Initialize the cache
javaType = getJavaType().asSubclass(Exception.class);
if (javaType == null)
throw new WSException("Cannot load java type: " + javaTypeName);
- faultBean = getFaultBean();
- if (faultBean != null)
- initializeFaultBean();
+ if (epType == EndpointMetaData.Type.JAXWS)
+ {
+ faultBean = getFaultBean();
+ if (faultBean != null)
+ initializeFaultBean();
+ }
}
private void initializeFaultBean()
@@ -209,7 +235,7 @@
* . WrapperException(String message, FaultBean faultInfo, Throwable cause)
* . FaultBean getFaultInfo() */
serviceExceptionConstructor = javaType.getConstructor(String.class, faultBean);
- getFaultInfoMethod = javaType.getMethod("getFaultInfo");
+ faultInfoMethod = javaType.getMethod("getFaultInfo");
}
/* JAX-WS 3.7: For exceptions that do not match the pattern described in
* section 2.5, JAX-WS maps those exceptions to Java beans and then uses
@@ -296,10 +322,10 @@
{
/* is the service exception a wrapper
* (i.e. does it match the pattern in JAX-WS 2.5)? */
- if (getFaultInfoMethod != null)
+ if (faultInfoMethod != null)
{
// extract the fault bean from the wrapper exception
- faultBeanInstance = getFaultInfoMethod.invoke(serviceException);
+ faultBeanInstance = faultInfoMethod.invoke(serviceException);
}
else
{
@@ -346,7 +372,7 @@
{
/* is the service exception a wrapper
* (i.e. does it match the pattern in JAX-WS 2.5)? */
- if (getFaultInfoMethod != null)
+ if (faultInfoMethod != null)
{
serviceException = serviceExceptionConstructor.newInstance(message,
faultBean);
}
Modified:
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/umdm/ParameterMetaData.java
===================================================================
---
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/umdm/ParameterMetaData.java 2007-01-24
15:12:07 UTC (rev 2081)
+++
branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/metadata/umdm/ParameterMetaData.java 2007-01-24
17:24:03 UTC (rev 2082)
@@ -24,7 +24,6 @@
// $Id$
import java.lang.reflect.Method;
-import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -43,6 +42,7 @@
import org.jboss.ws.core.utils.JavaUtils;
import org.jboss.ws.extensions.xop.jaxws.ReflectiveXOPScanner;
import org.jboss.ws.metadata.acessor.ReflectiveMethodAccessor;
+import org.jboss.ws.metadata.umdm.EndpointMetaData.Type;
/**
* A request/response parameter that a given operation supports.
@@ -109,7 +109,7 @@
private static boolean matchParameter(Method method, int index, Class expectedType,
Set<Integer> matches, boolean exact, boolean holder)
{
Class returnType = method.getReturnType();
- Type[] genericParameters = method.getGenericParameterTypes();
+ java.lang.reflect.Type[] genericParameters = method.getGenericParameterTypes();
Class[] classParameters = method.getParameterTypes();
if (index == -1 && matchTypes(returnType, expectedType, exact, false))
@@ -134,12 +134,12 @@
return false;
}
- private static boolean matchTypes(Type actualType, Class expectedType, boolean exact,
boolean holder)
+ private static boolean matchTypes(java.lang.reflect.Type actualType, Class
expectedType, boolean exact, boolean holder)
{
if (holder && HolderUtils.isHolderType(actualType) == false)
return false;
- Type valueType = (holder ? HolderUtils.getValueType(actualType) : actualType);
+ java.lang.reflect.Type valueType = (holder ? HolderUtils.getValueType(actualType) :
actualType);
Class valueClass = JavaUtils.erasure(valueType);
return matchTypesInternal(valueClass, expectedType, exact);
@@ -230,6 +230,21 @@
javaTypeName = typeName;
javaType = null;
}
+
+ public Class loadWrapperBean()
+ {
+ Class wrapperBean = null;
+ try
+ {
+ ClassLoader loader =
getOperationMetaData().getEndpointMetaData().getClassLoader();
+ wrapperBean = JavaUtils.loadJavaType(javaTypeName, loader);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ // ignore
+ }
+ return wrapperBean;
+ }
/** Load the java type.
* It should only be cached during eager initialization.
@@ -420,9 +435,16 @@
javaType = null;
// FIXME - Remove messageType hack
+ Type epType = getOperationMetaData().getEndpointMetaData().getType();
if (getOperationMetaData().isDocumentWrapped() && !isInHeader() &&
!isSwA() && !isMessageType())
{
- new DynamicWrapperGenerator(getClassLoader()).generate(this);
+ if (loadWrapperBean() == null)
+ {
+ if (epType == EndpointMetaData.Type.JAXRPC)
+ throw new WSException("Autogeneration of wrapper beans not
supported with JAXRPC");
+
+ new DynamicWrapperGenerator(getClassLoader()).generate(this);
+ }
// Initialize accessors
AccessorFactory factory = accessorFactoryCreator.create(this);
@@ -435,19 +457,21 @@
throw new WSException("Cannot load java type: " + javaTypeName);
// check if the JavaType is an mtom parameter
- // TODO: this should only apply to JAX-WS and needs to happen outside UMD
- ReflectiveXOPScanner scanner = new ReflectiveXOPScanner();
- String mimeType = scanner.scan(javaType);
- if (mimeType != null)
+ if (epType == EndpointMetaData.Type.JAXWS)
{
- log.debug("MTOM parameter found: " + xmlName);
- setXOP(true);
+ ReflectiveXOPScanner scanner = new ReflectiveXOPScanner();
+ String mimeType = scanner.scan(javaType);
+ if (mimeType != null)
+ {
+ log.debug("MTOM parameter found: " + xmlName);
+ setXOP(true);
+ }
}
}
private ClassLoader getClassLoader()
{
- ClassLoader loader =
opMetaData.getEndpointMetaData().getServiceMetaData().getUnifiedMetaData().getClassLoader();
+ ClassLoader loader = opMetaData.getEndpointMetaData().getClassLoader();
if (loader == null)
throw new WSException("ClassLoader not available");
return loader;