Author: alessio.soldano(a)jboss.com
Date: 2009-01-21 13:52:15 -0500 (Wed, 21 Jan 2009)
New Revision: 9085
Modified:
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/utils/JavassistUtils.java
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/metadata/umdm/WrappedParameter.java
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/tools/jaxws/impl/SourceWrapperGenerator.java
Log:
[JBWS-2451] Support for @XmlJavaTypeAdapter on SEI when producing wrapper beans and wsdl
Modified:
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java
===================================================================
---
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java 2009-01-21
15:07:17 UTC (rev 9084)
+++
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java 2009-01-21
18:52:15 UTC (rev 9085)
@@ -46,6 +46,7 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
import org.jboss.logging.Logger;
@@ -123,8 +124,7 @@
parameter.getName(), parameter.getVariable(),
parameter.getTypeArguments(),
new boolean[] {parameter.isSwaRef(), parameter.isXop()},
- false,
- parameter.isXmlList()
+ false, parameter.isXmlList(), parameter.getAdapter()
);
}
clazz.stopPruning(!prune);
@@ -161,7 +161,7 @@
addProperty(
clazz, prop.getReturnType().getName(),
new QName(prop.getName()), prop.getName(), null,
- new boolean[] {false, false}, prop.isTransientAnnotated(), false
+ new boolean[] {false, false}, prop.isTransientAnnotated(), false, null
);
clazz.stopPruning(!prune);
@@ -218,7 +218,7 @@
private void addProperty(CtClass clazz, String typeName,
QName name, String variable, String[] typeArguments,
- boolean[] attachments, boolean xmlTransient, boolean
xmlList)
+ boolean[] attachments, boolean xmlTransient, boolean xmlList,
String adapter)
throws CannotCompileException, NotFoundException
{
ConstPool constPool = clazz.getClassFile().getConstPool();
@@ -269,6 +269,13 @@
annotation = JavassistUtils.createAnnotation(XmlList.class, constPool);
annotation.markField(field);
}
+ //@XmlJavaTypeAdapter
+ if (adapter != null)
+ {
+ annotation = JavassistUtils.createAnnotation(XmlJavaTypeAdapter.class,
constPool);
+ annotation.addClassParameter("value", adapter);
+ annotation.markField(field);
+ }
clazz.addField(field);
// Add accessor methods
Modified:
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/utils/JavassistUtils.java
===================================================================
---
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/utils/JavassistUtils.java 2009-01-21
15:07:17 UTC (rev 9084)
+++
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/utils/JavassistUtils.java 2009-01-21
18:52:15 UTC (rev 9085)
@@ -31,6 +31,7 @@
import javassist.bytecode.MethodInfo;
import javassist.bytecode.SignatureAttribute;
import javassist.bytecode.annotation.ArrayMemberValue;
+import javassist.bytecode.annotation.ClassMemberValue;
import javassist.bytecode.annotation.EnumMemberValue;
import javassist.bytecode.annotation.StringMemberValue;
@@ -105,6 +106,12 @@
enumValue.setValue(value.name());
annotation.addMemberValue(name, enumValue);
}
+
+ public void addClassParameter(String name, String value)
+ {
+ ClassMemberValue classValue = new ClassMemberValue(value, constPool);
+ annotation.addMemberValue(name, classValue);
+ }
public void addParameter(String name, String[] values)
{
Modified:
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
===================================================================
---
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java 2009-01-21
15:07:17 UTC (rev 9084)
+++
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java 2009-01-21
18:52:15 UTC (rev 9085)
@@ -45,6 +45,7 @@
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.xml.bind.annotation.XmlList;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.ws.BindingType;
@@ -448,24 +449,19 @@
return HolderUtils.isHolderType(javaType) ? ParameterMode.INOUT :
ParameterMode.IN;
}
- private WebParam getWebParamAnnotation(Method method, int pos)
+ @SuppressWarnings("unchecked")
+ private <T extends Annotation> T getAnnotation(Class<T> annotation, Method
method, int pos)
{
- for (Annotation annotation : method.getParameterAnnotations()[pos])
- if (annotation instanceof WebParam)
- return (WebParam)annotation;
-
+ for (Annotation an : method.getParameterAnnotations()[pos])
+ {
+ if (annotation.isAssignableFrom(an.annotationType()))
+ {
+ return (T)an;
+ }
+ }
return null;
}
-
- private XmlList getXmlListAnnotation(Method method, int pos)
- {
- for (Annotation annotation : method.getParameterAnnotations()[pos])
- if (annotation instanceof XmlList)
- return (XmlList)annotation;
- return null;
- }
-
private QName getWebParamName(OperationMetaData opMetaData, int index, WebParam
webParam)
{
String namespace = null;
@@ -643,7 +639,7 @@
Class<?> javaType = parameterTypes[i];
Type genericType = genericTypes[i];
String javaTypeName = javaType.getName();
- WebParam anWebParam = getWebParamAnnotation(method, i);
+ WebParam anWebParam = getAnnotation(WebParam.class, method, i);
boolean isHeader = anWebParam != null && anWebParam.header();
boolean isWrapped = opMetaData.isDocumentWrapped() && !isHeader;
ParameterMode mode = getParameterMode(anWebParam, javaType);
@@ -666,7 +662,13 @@
WrappedParameter wrappedParameter = new WrappedParameter(wrappedElementName,
javaTypeName, variable, i);
wrappedParameter.setTypeArguments(convertTypeArguments(javaType,
genericType));
- wrappedParameter.setXmlList(getXmlListAnnotation(method, i) != null);
+ wrappedParameter.setXmlList(getAnnotation(XmlList.class, method, i) !=
null);
+ XmlJavaTypeAdapter xmlJavaTypeAdapter =
getAnnotation(XmlJavaTypeAdapter.class, method, i);
+ if (xmlJavaTypeAdapter != null)
+ {
+ //XmlJavaTypeAdapter.type() is for package only
+ wrappedParameter.setAdapter(xmlJavaTypeAdapter.value().getName());
+ }
if (mode != ParameterMode.OUT)
wrappedParameters.add(wrappedParameter);
@@ -735,6 +737,12 @@
WrappedParameter wrapped = new WrappedParameter(xmlName, returnTypeName,
convertToVariable(xmlName.getLocalPart()), -1);
wrapped.setTypeArguments(convertTypeArguments(returnType,
genericReturnType));
wrapped.setXmlList(method.getAnnotation(XmlList.class) != null);
+ XmlJavaTypeAdapter xmlJavaTypeAdapter =
method.getAnnotation(XmlJavaTypeAdapter.class);
+ if (xmlJavaTypeAdapter != null)
+ {
+ //XmlJavaTypeAdapter.type() is for package only
+ wrapped.setAdapter(xmlJavaTypeAdapter.value().getName());
+ }
// insert at the beginning just for prettiness
wrappedOutputParameters.add(0, wrapped);
Modified:
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/metadata/umdm/WrappedParameter.java
===================================================================
---
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/metadata/umdm/WrappedParameter.java 2009-01-21
15:07:17 UTC (rev 9084)
+++
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/metadata/umdm/WrappedParameter.java 2009-01-21
18:52:15 UTC (rev 9085)
@@ -44,6 +44,7 @@
private boolean swaRef;
private boolean xop;
private boolean xmlList;
+ private String adapter = null;
public WrappedParameter(WrappedParameter wrapped)
{
@@ -164,6 +165,16 @@
this.xmlList = xmlList;
}
+ public String getAdapter()
+ {
+ return adapter;
+ }
+
+ public void setAdapter(String adapter)
+ {
+ this.adapter = adapter;
+ }
+
public String toString()
{
return "[name = " + getName() + ", type = " + getType() +
", typeArgs = " + JavaUtils.printArray(getTypeArguments()) + ", variable =
" + getVariable()
Modified:
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/tools/jaxws/impl/SourceWrapperGenerator.java
===================================================================
---
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/tools/jaxws/impl/SourceWrapperGenerator.java 2009-01-21
15:07:17 UTC (rev 9084)
+++
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/tools/jaxws/impl/SourceWrapperGenerator.java 2009-01-21
18:52:15 UTC (rev 9085)
@@ -35,6 +35,7 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
import org.jboss.logging.Logger;
@@ -111,7 +112,7 @@
addClassAnnotations(clazz, parameterMD.getXmlName(), parameterMD.getXmlType(),
null);
for (WrappedParameter wrapped : wrappedParameters)
{
- addProperty(clazz, wrapped.getType(), wrapped.getName(),
wrapped.getVariable(), wrapped.getTypeArguments(), false, wrapped.isXmlList(), loader);
+ addProperty(clazz, wrapped.getType(), wrapped.getName(),
wrapped.getVariable(), wrapped.getTypeArguments(), false, wrapped.isXmlList(),
wrapped.getAdapter(), loader);
}
}
catch (Exception e)
@@ -136,7 +137,7 @@
for (String property : propertyOrder)
{
ExceptionProperty p = properties.get(property);
- addProperty(clazz, p.getReturnType().getName(), new QName(property),
property, null, p.isTransientAnnotated(), false, loader);
+ addProperty(clazz, p.getReturnType().getName(), new QName(property),
property, null, p.isTransientAnnotated(), false, null, loader);
}
}
catch (Exception e)
@@ -150,7 +151,7 @@
return (Boolean.TYPE == type || Boolean.class == type) ? "is" :
"get";
}
- private void addProperty(JDefinedClass clazz, String typeName, QName name, String
variable, String[] typeArguments, boolean xmlTransient, boolean xmlList, ClassLoader
loader)
+ private void addProperty(JDefinedClass clazz, String typeName, QName name, String
variable, String[] typeArguments, boolean xmlTransient, boolean xmlList, String adapter,
ClassLoader loader)
throws Exception
{
// define variable
@@ -161,12 +162,12 @@
}
else
{
- addProperty(clazz, javaType, name, variable, typeArguments, xmlTransient,
xmlList, codeModel);
+ addProperty(clazz, javaType, name, variable, typeArguments, xmlTransient,
xmlList, adapter, codeModel);
}
}
- private static void addProperty(JDefinedClass clazz, Class<?> javaType, QName
name, String variable, String[] typeArguments, boolean xmlTransient, boolean xmlList,
JCodeModel codeModel)
- throws Exception
+ private static void addProperty(JDefinedClass clazz, Class<?> javaType, QName
name, String variable, String[] typeArguments, boolean xmlTransient, boolean xmlList,
+ String adapter, JCodeModel codeModel) throws Exception
{
// be careful about reserved keywords when generating variable names
String realVariableName = JavaUtils.isReservedKeyword(variable) ? "_" +
variable : variable;
@@ -204,6 +205,12 @@
{
field.annotate(XmlList.class);
}
+
+ if (adapter != null)
+ {
+ JAnnotationUse xmlJavaTypeAdapter = field.annotate(XmlJavaTypeAdapter.class);
+ xmlJavaTypeAdapter.param("value", codeModel.ref(adapter));
+ }
// generate acessor get method for variable
JMethod method = clazz.method(JMod.PUBLIC, type, getterPrefix(javaType) +
JavaUtils.capitalize(variable));