You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by to...@apache.org on 2004/11/18 16:26:16 UTC
cvs commit: ws-axis/java/src/org/apache/axis/wsdl/symbolTable SymbolTable.java TypeEntry.java
tomj 2004/11/18 07:26:16
Modified: java/src/org/apache/axis/encoding/ser ArrayDeserializer.java
ArraySerializer.java ArraySerializerFactory.java
java/src/org/apache/axis/wsdl/toJava JavaStubWriter.java
java/src/org/apache/axis/wsdl/symbolTable SymbolTable.java
TypeEntry.java
Log:
Fix interop regression with .NET rpc/encoded arrays.
Change the way we do array serialization to keep track of the array type
specified in WSDL and use it when serializing an array.
Example Schema from a .NET rpc/encoded array:
<s:complexType name="ArrayOfString">
<s:complexContent mixed="false">
<s:restriction base="soapenc:Array">
<s:attribute d7p1:arrayType="xsd:string[]" ref="soapenc:arrayType"/>
</s:restriction>
</s:complexContent>
</s:complexType>
We will now remember the xsd:string type and use it instead of defaulting
to a soapenc:string, which .NET doesn't like and doesn't follow the WSDL.
Details:
- Fix a problem unconvered in the ArrayDeserailizer with array dimensions:
If the class of the component specifies dimensions, don't add them back
in again.
- ArraySerializer now has a special constructor that takes a component type
argument. The component type from this constructor is checked first before
the context, the type mapping and the super class type mappings.
- ArraySerializerFactory can now be created to produce ArraySerializers with
the component type set.
- JavaStubWriter will emit code to register a factory for arrays with the
component type as specified in the WSDL.
- Add componentType to the TypeEntry class with getter and setter.
- Set the component type for an array type that we create from WSD so we can
use it in JavaStubWriter.
Revision Changes Path
1.45 +10 -4 ws-axis/java/src/org/apache/axis/encoding/ser/ArrayDeserializer.java
Index: ArrayDeserializer.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/ArrayDeserializer.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- ArrayDeserializer.java 29 Jul 2004 21:40:26 -0000 1.44
+++ ArrayDeserializer.java 18 Nov 2004 15:26:15 -0000 1.45
@@ -239,16 +239,22 @@
offset ++;
}
} else {
- dims += innerDimString;
+ // This might not be right because the arrayItemClass below
+ // is going to have dimensions too..
+ dims += innerDimString;
}
}
- arrayItemClass = context.getTypeMapping().
- getClassForQName(compQName);
+ arrayItemClass = context.getTypeMapping().getClassForQName(compQName);
if (arrayItemClass != null) {
try {
+ final String name = arrayItemClass.getName();
+ if (name.indexOf('[') != -1) {
+ // Just add a single dimension
+ dims = "[]";
+ }
String loadableArrayClassName = JavaUtils.getLoadableClassName(
- JavaUtils.getTextClassName(arrayItemClass.getName()) + dims);
+ JavaUtils.getTextClassName(name) + dims);
arrayClass = ClassUtils.forName(loadableArrayClassName,
true,
arrayItemClass.getClassLoader());
1.60 +35 -15 ws-axis/java/src/org/apache/axis/encoding/ser/ArraySerializer.java
Index: ArraySerializer.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/ArraySerializer.java,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- ArraySerializer.java 4 Nov 2004 13:23:34 -0000 1.59
+++ ArraySerializer.java 18 Nov 2004 15:26:15 -0000 1.60
@@ -53,12 +53,27 @@
{
QName xmlType;
Class javaType;
-
+ QName componentType;
+
+ /**
+ * Constructor
+ *
+ */
public ArraySerializer(Class javaType, QName xmlType) {
this.javaType = javaType;
this.xmlType = xmlType;
}
-
+
+ /**
+ * Constructor
+ * Special constructor that takes the component type of the array.
+ */
+ public ArraySerializer(Class javaType, QName xmlType, QName componentType) {
+ this.javaType = javaType;
+ this.xmlType = xmlType;
+ this.componentType = componentType;
+ }
+
protected static Log log =
LogFactory.getLog(ArraySerializer.class.getName());
@@ -98,11 +113,11 @@
}
// Get the componentType of the array/list
- Class componentType;
+ Class componentClass;
if (list == null) {
- componentType = cls.getComponentType();
+ componentClass = cls.getComponentType();
} else {
- componentType = Object.class;
+ componentClass = Object.class;
}
@@ -114,18 +129,20 @@
// This won't handle Lists of Lists or
// arrays of Lists....only arrays of arrays.
String dims = "";
- while (componentType.isArray()) {
- componentType = componentType.getComponentType();
+ while (componentClass.isArray()) {
+ componentClass = componentClass.getComponentType();
if (soap == SOAPConstants.SOAP12_CONSTANTS)
dims += "* ";
else
dims += "[]";
}
- // Get the QName of the componentType.
- // If not found, look at the super classes
- QName componentQName = null;
- if (!encoded) {
+ // Get the QName of the componentType
+ // if it wasn't passed in from the constructor
+ QName componentQName = this.componentType;
+
+ // Try the current XML type from the context
+ if (componentQName == null) {
componentQName = context.getCurrentXMLType();
if (componentQName != null) {
if ((componentQName.equals(xmlType) ||
@@ -135,24 +152,27 @@
}
}
+ // Then check the type mapping for the class
if (componentQName == null) {
- componentQName = context.getQNameForClass(componentType);
+ componentQName = context.getQNameForClass(componentClass);
}
+ // If still not found, look at the super classes
if (componentQName == null) {
- Class searchCls = componentType;
+ Class searchCls = componentClass;
while(searchCls != null && componentQName == null) {
searchCls = searchCls.getSuperclass();
componentQName = context.getQNameForClass(searchCls);
}
if (componentQName != null) {
- componentType = searchCls;
+ componentClass = searchCls;
}
}
+ // Still can't find it? Throw an error.
if (componentQName == null) {
throw new IOException(
- Messages.getMessage("noType00", componentType.getName()));
+ Messages.getMessage("noType00", componentClass.getName()));
}
int len = (list == null) ? Array.getLength(value) : list.size();
1.11 +21 -0 ws-axis/java/src/org/apache/axis/encoding/ser/ArraySerializerFactory.java
Index: ArraySerializerFactory.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/ArraySerializerFactory.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ArraySerializerFactory.java 25 Feb 2004 14:02:36 -0000 1.10
+++ ArraySerializerFactory.java 18 Nov 2004 15:26:15 -0000 1.11
@@ -17,6 +17,7 @@
package org.apache.axis.encoding.ser;
import org.apache.axis.Constants;
+import org.apache.axis.encoding.Serializer;
import javax.xml.namespace.QName;
@@ -32,5 +33,25 @@
}
public ArraySerializerFactory(Class javaType, QName xmlType) {
super(ArraySerializer.class, xmlType, javaType);
+ }
+
+ private QName componentType;
+ public ArraySerializerFactory(QName componentType) {
+ super(ArraySerializer.class, Constants.SOAP_ARRAY, Object[].class);
+ this.componentType = componentType;
+ }
+
+ /**
+ * Obtains a serializer by invoking <constructor>(javaType, xmlType)
+ * on the serClass.
+ */
+ protected Serializer getGeneralPurpose(String mechanismType)
+ {
+ // Do something special only if we have an array component type
+
+ if (componentType == null)
+ return super.getGeneralPurpose(mechanismType);
+ else
+ return new ArraySerializer(javaType, xmlType, componentType);
}
}
1.139 +36 -5 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java
Index: JavaStubWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -r1.138 -r1.139
--- JavaStubWriter.java 28 Oct 2004 14:04:35 -0000 1.138
+++ JavaStubWriter.java 18 Nov 2004 15:26:15 -0000 1.139
@@ -352,15 +352,35 @@
pw.println(
" (javax.xml.namespace.QName) cachedSerQNames.get(i);");
pw.println(
- " java.lang.Class sf = (java.lang.Class)");
+ " Object x = cachedSerFactories.get(i);");
+ pw.println(
+ " if (x instanceof Class) {");
+ pw.println(
+ " java.lang.Class sf = (java.lang.Class)");
+ pw.println(
+ " cachedSerFactories.get(i);");
+ pw.println(
+ " java.lang.Class df = (java.lang.Class)");
+ pw.println(
+ " cachedDeserFactories.get(i);");
+ pw.println(
+ " _call.registerTypeMapping(cls, qName, sf, df, false);");
+
+ pw.println(" }");
+ pw.println(
+ " else if (x instanceof javax.xml.rpc.encoding.SerializerFactory) {");
+ pw.println(
+ " org.apache.axis.encoding.SerializerFactory sf = (org.apache.axis.encoding.SerializerFactory)");
pw.println(
" cachedSerFactories.get(i);");
pw.println(
- " java.lang.Class df = (java.lang.Class)");
+ " org.apache.axis.encoding.DeserializerFactory df = (org.apache.axis.encoding.DeserializerFactory)");
pw.println(
" cachedDeserFactories.get(i);");
pw.println(
- " _call.registerTypeMapping(cls, qName, sf, df, false);");
+ " _call.registerTypeMapping(cls, qName, sf, df, false);");
+
+ pw.println(" }");
pw.println(" }");
pw.println(" }");
pw.println(" }");
@@ -903,8 +923,19 @@
pw.println(" cachedSerFactories.add(simplelistsf);");
pw.println(" cachedDeserFactories.add(simplelistdf);");
} else {
- pw.println(" cachedSerFactories.add(arraysf);");
- pw.println(" cachedDeserFactories.add(arraydf);");
+ // We use a custom serializer if WSDL told us the component type of the array.
+ // Both factories must be an instance, so we create a ArrayDeserializerFactory
+ if (type.getComponentType() != null) {
+ QName ct = type.getComponentType();
+ pw.println(" qName = new javax.xml.namespace.QName(\""
+ + ct.getNamespaceURI() + "\", \"" + ct.getLocalPart()
+ + "\");");
+ pw.println(" cachedSerFactories.add(new org.apache.axis.encoding.ser.ArraySerializerFactory(qName));");
+ pw.println(" cachedDeserFactories.add(new org.apache.axis.encoding.ser.ArrayDeserializerFactory());");
+ } else {
+ pw.println(" cachedSerFactories.add(arraysf);");
+ pw.println(" cachedDeserFactories.add(arraydf);");
+ }
}
} else if ((type.getNode() != null) && (Utils.getEnumerationBaseAndValues(
type.getNode(), symbolTable) != null)) {
1.110 +8 -4 ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SymbolTable.java
Index: SymbolTable.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SymbolTable.java,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -r1.109 -r1.110
--- SymbolTable.java 9 Nov 2004 17:49:30 -0000 1.109
+++ SymbolTable.java 18 Nov 2004 15:26:16 -0000 1.110
@@ -1197,11 +1197,15 @@
if (isElement) {
if (!belowSchemaLevel) {
- defType = new DefinedElement(qName, refType, node,
- dims);
+ defType =
+ new DefinedElement(qName, refType, node, dims);
+ // Save component type for ArraySerializer
+ defType.setComponentType(arrayEQName);
}
} else {
defType = new DefinedType(qName, refType, node, dims);
+ // Save component type for ArraySerializer
+ defType.setComponentType(arrayEQName);
}
if (defType != null) {
@@ -1706,7 +1710,7 @@
literalInput, operation.getName(),
bindingEntry);
}
-
+
// Collect all the output parameters
if ((output != null) && (output.getMessage() != null)) {
getParametersFromParts(outputs,
@@ -1714,7 +1718,7 @@
literalOutput, operation.getName(),
bindingEntry);
}
-
+
if (parameterOrder != null && !wrapped) {
// Construct a list of the parameters in the parameterOrder list, determining the
1.17 +20 -1 ws-axis/java/src/org/apache/axis/wsdl/symbolTable/TypeEntry.java
Index: TypeEntry.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/TypeEntry.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- TypeEntry.java 22 Aug 2004 03:06:59 -0000 1.16
+++ TypeEntry.java 18 Nov 2004 15:26:16 -0000 1.17
@@ -81,7 +81,9 @@
/** Field dims */
protected String dims = ""; // If refType is an element, dims indicates
- // the array dims (for example "[]").
+ // the array dims (for example "[]").
+
+ protected QName componentType = null; // If this is an array, the component type
/** Field undefined */
protected boolean undefined; // If refType is an Undefined type
@@ -373,6 +375,23 @@
public String getDimensions() {
return dims;
} // getDimensions
+
+ /**
+ * Return the QName of the component if this is an array type
+ * @return QName of array elements or null
+ */
+ public QName getComponentType()
+ {
+ return componentType;
+ }
+
+ /**
+ * Set the QName of the component if this is an array type
+ */
+ public void setComponentType(QName componentType)
+ {
+ this.componentType = componentType;
+ }
/**
* Get string representation.