gdaniels 2002/11/04 09:01:29
Modified: java/samples/encoding DataSer.java
java/src/org/apache/axis/encoding Serializer.java
java/src/org/apache/axis/encoding/ser ArraySerializer.java
Base64Serializer.java BeanSerializer.java
CalendarSerializer.java DateSerializer.java
ElementSerializer.java EnumSerializer.java
HexSerializer.java JAFDataHandlerSerializer.java
MapSerializer.java QNameSerializer.java
SimpleSerializer.java VectorSerializer.java
java/src/org/apache/axis/encoding/ser/castor
CastorSerializer.java
java/src/org/apache/axis/i18n resource.properties
java/src/org/apache/axis/utils Admin.java
java/src/org/apache/axis/wsdl/fromJava Emitter.java
Namespaces.java Types.java
java/test/encoding DataSer.java
Log:
Support anonymous types when generating WSDL.
This involved some surgery, because the way it used to be relied on the
fact that the serializers would write out <complexType name=""> types
into the <schema> sections, and there was no way to get your hands on
those elements (to embed them) or make them unnamed.
The big change is that Serializer's writeSchema now returns an Element
and DOES NOT write the complex type into the <schema> itself. Instead,
we rely on the context in which we're generating the type to know what
to do about it. This logic is mostly in Types.makeTypeElement(), whose
Javadoc explains how it works.
There was also the usual bits of random cleanup of unused imports, etc.
Revision Changes Path
1.18 +3 -11 xml-axis/java/samples/encoding/DataSer.java
Index: DataSer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/samples/encoding/DataSer.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- DataSer.java 22 Jul 2002 20:10:05 -0000 1.17
+++ DataSer.java 4 Nov 2002 17:01:26 -0000 1.18
@@ -8,6 +8,7 @@
import org.xml.sax.SAXException;
import org.apache.axis.Constants;
import org.apache.axis.wsdl.fromJava.Types;
+import org.w3c.dom.Element;
import javax.xml.namespace.QName;
import java.io.IOException;
@@ -46,16 +47,7 @@
}
public String getMechanismType() { return Constants.AXIS_SAX; }
- /**
- * Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
- *
- * @param types the Java2WSDL Types object which holds the context
- * for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
- * @see org.apache.axis.wsdl.fromJava.Types
- */
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
}
}
1.17 +5 -4 xml-axis/java/src/org/apache/axis/encoding/Serializer.java
Index: Serializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/Serializer.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Serializer.java 11 Jun 2002 14:53:54 -0000 1.16
+++ Serializer.java 4 Nov 2002 17:01:26 -0000 1.17
@@ -58,7 +58,6 @@
import org.xml.sax.Attributes;
import org.w3c.dom.Element;
-import org.w3c.dom.Document;
import org.apache.axis.wsdl.fromJava.Types;
import javax.xml.namespace.QName;
@@ -92,14 +91,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception;
+ public Element writeSchema(Class javaType, Types types) throws Exception;
}
1.38 +33 -12
xml-axis/java/src/org/apache/axis/encoding/ser/ArraySerializer.java
Index: ArraySerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/ArraySerializer.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- ArraySerializer.java 30 Sep 2002 20:05:24 -0000 1.37
+++ ArraySerializer.java 4 Nov 2002 17:01:27 -0000 1.38
@@ -70,6 +70,7 @@
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
+import org.w3c.dom.Element;
import javax.xml.namespace.QName;
@@ -144,7 +145,7 @@
dims += "[]";
}
- // Get the QName of the componentType.
+ // Get the QName of the componentType.
// If not found, look at the super classes
QName componentQName = context.getQNameForClass(componentType);
if (componentQName == null) {
@@ -183,7 +184,7 @@
// way to determine whether the arrays are multi-referenced.
// Thus the code is currently disabled (see enable2Dim below).
//
- // Currently the support is ENABLED because it is necessary for
+ // Currently the support is ENABLED because it is necessary for
// interoperability (echo2DStringArray). It is 'safe' for now
// because Axis treats arrays as non multi-ref (see the note
// in SerializationContextImpl.isPrimitive(...) )
@@ -251,10 +252,10 @@
//
// There are two choices here:
// Force the type to type=SOAP_ARRAY
- // Pros: More interop test successes.
- // Cons: Since we have specific type information it
+ // Pros: More interop test successes.
+ // Cons: Since we have specific type information it
// is more correct to use it. Plus the specific
- // type information may be important on the
+ // type information may be important on the
// server side to disambiguate overloaded operations.
// Use the specific type information:
// Pros: The specific type information is more correct
@@ -264,10 +265,10 @@
int typeI = attrs.getIndex(schema.getXsiURI(),
"type");
if (typeI != -1) {
- String qname =
+ String qname =
context.getPrefixForURI(schema.getXsiURI(),
"xsi") + ":type";
- attrs.setAttribute(typeI,
+ attrs.setAttribute(typeI,
schema.getXsiURI(),
"type",
qname,
@@ -302,7 +303,7 @@
}
} else {
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
- Object aValue = (Object)iterator.next();
+ Object aValue = iterator.next();
// Serialize the element.
context.serialize(elementName, serializeAttr, aValue,
@@ -330,14 +331,34 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ // If an array the component type should be processed first
+ String componentTypeName = null;
+ Class componentType = null;
+ if (javaType.isArray()) {
+ String dimString = "[]";
+ componentType = javaType.getComponentType();
+ if (componentType.isArray()) {
+ while (componentType.isArray()) {
+ dimString += "[]";
+ componentType = componentType.getComponentType();
+ }
+ }
+ componentTypeName =
+ types.getQNameString(types.getTypeQName(componentType)) +
+ dimString;
+ }
+
+ // Use Types helper method to actually create the complexType
+ return types.createArrayElement(componentTypeName);
}
}
1.9 +6 -12
xml-axis/java/src/org/apache/axis/encoding/ser/Base64Serializer.java
Index: Base64Serializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/Base64Serializer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Base64Serializer.java 16 Aug 2002 11:07:09 -0000 1.8
+++ Base64Serializer.java 4 Nov 2002 17:01:27 -0000 1.9
@@ -56,7 +56,6 @@
package org.apache.axis.encoding.ser;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
import javax.xml.namespace.QName;
@@ -64,17 +63,10 @@
import org.apache.axis.Constants;
import org.apache.axis.wsdl.fromJava.Types;
-import org.apache.axis.encoding.Serializer;
-import org.apache.axis.encoding.SerializerFactory;
import org.apache.axis.encoding.SerializationContext;
-import org.apache.axis.encoding.Deserializer;
-import org.apache.axis.encoding.DeserializerFactory;
-import org.apache.axis.encoding.DeserializationContext;
-import org.apache.axis.encoding.Deserializer;
import org.apache.axis.encoding.Base64;
import org.apache.axis.encoding.SimpleValueSerializer;
import org.w3c.dom.Element;
-import org.w3c.dom.Document;
/**
* Serializer for Base64
@@ -124,14 +116,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
}
}
1.60 +49 -30
xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java
Index: BeanSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- BeanSerializer.java 26 Sep 2002 19:21:27 -0000 1.59
+++ BeanSerializer.java 4 Nov 2002 17:01:27 -0000 1.60
@@ -191,7 +191,6 @@
if (qname == null) {
// Use the default...
- propName = propName;
qname = new QName("", propName);
}
@@ -275,19 +274,19 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
+ public Element writeSchema(Class javaType, Types types) throws Exception {
// ComplexType representation of bean class
Element complexType = types.createElement("complexType");
- types.writeSchemaElement(xmlType, complexType);
- complexType.setAttribute("name", xmlType.getLocalPart());
// See if there is a super class, stop if we hit a stop class
Element e = null;
@@ -334,6 +333,7 @@
if (Modifier.isAbstract(javaType.getModifiers())) {
complexType.setAttribute("abstract", "true");
}
+
// Serialize each property
for (int i=0; i<propertyDescriptor.length; i++) {
String propName = propertyDescriptor[i].getName();
@@ -357,6 +357,8 @@
continue;
}
+ Class fieldType = propertyDescriptor[i].getType();
+
// If we have type metadata, check to see what we're doing
// with this field. If it's an attribute, skip it. If it's
// an element, use whatever qname is in there. If we can't
@@ -364,8 +366,12 @@
if (typeDesc != null) {
FieldDesc field = typeDesc.getFieldByName(propName);
+
if (field != null) {
QName qname = field.getXmlName();
+ QName fieldXmlType = field.getXmlType();
+ boolean isAnonymous =
fieldXmlType.getLocalPart().startsWith(">");
+
if (qname != null) {
// FIXME!
// Check to see if this is in the right namespace -
@@ -378,32 +384,33 @@
if (!field.isElement()) {
writeAttribute(types,
propName,
- propertyDescriptor[i].getType(),
+ fieldType,
+ field.getXmlType(),
complexType);
} else {
writeField(types,
propName,
- propertyDescriptor[i].getType(),
+ fieldType,
propertyDescriptor[i].isIndexed(),
field.isMinOccursIs0(),
- all);
+ all, isAnonymous);
}
} else {
writeField(types,
propName,
- propertyDescriptor[i].getType(),
- propertyDescriptor[i].isIndexed(), false, all);
+ fieldType,
+ propertyDescriptor[i].isIndexed(), false, all,
false);
}
} else {
writeField(types,
propName,
- propertyDescriptor[i].getType(),
- propertyDescriptor[i].isIndexed(), false, all);
+ fieldType,
+ propertyDescriptor[i].isIndexed(), false, all, false);
}
}
// done
- return true;
+ return complexType;
}
/**
@@ -416,24 +423,36 @@
* @throws Exception
*/
protected void writeField(Types types, String fieldName,
- Class fieldType,
- boolean isUnbounded,
- boolean isOmittable, Element where) throws Exception {
- String elementType = types.writeType(fieldType);
- if (elementType == null) {
- // If writeType returns null, then emit an anytype in such situations.
- QName anyQN = Constants.XSD_ANYTYPE;
- String prefix =
types.getNamespaces().getCreatePrefix(anyQN.getNamespaceURI());
- elementType = prefix + ":" + anyQN.getLocalPart();
+ Class fieldType,
+ boolean isUnbounded,
+ boolean isOmittable,
+ Element where,
+ boolean isAnonymous) throws Exception {
+ Element elem;
+ if (isAnonymous) {
+ elem = types.createElementWithAnonymousType(fieldName,
+ fieldType, isOmittable, where.getOwnerDocument());
+ } else {
+ String elementType = types.writeType(fieldType);
+
+ if (elementType == null) {
+ // If writeType returns null, then emit an anytype in such
situations.
+ QName anyQN = Constants.XSD_ANYTYPE;
+ String prefix =
types.getNamespaces().getCreatePrefix(anyQN.getNamespaceURI());
+ elementType = prefix + ":" + anyQN.getLocalPart();
+ }
+
+ elem = types.createElement(fieldName,
+ elementType,
+ types.isNullable(fieldType),
+ isOmittable,
+ where.getOwnerDocument());
}
- Element elem = types.createElement(fieldName,
- elementType,
- types.isNullable(fieldType),
- isOmittable,
- where.getOwnerDocument());
+
if (isUnbounded) {
elem.setAttribute("maxOccurs", "unbounded");
}
+
where.appendChild(elem);
}
@@ -447,6 +466,7 @@
protected void writeAttribute(Types types,
String fieldName,
Class fieldType,
+ QName fieldXmlType,
Element where) throws Exception {
// Attribute must be a simple type.
@@ -455,9 +475,8 @@
fieldName,
fieldType.getName()));
}
- String elementType = types.writeType(fieldType);
Element elem = types.createAttributeElement(fieldName,
- elementType,
+ fieldType, fieldXmlType,
false,
where.getOwnerDocument());
where.appendChild(elem);
1.7 +7 -4
xml-axis/java/src/org/apache/axis/encoding/ser/CalendarSerializer.java
Index: CalendarSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/CalendarSerializer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CalendarSerializer.java 16 Aug 2002 11:07:09 -0000 1.6
+++ CalendarSerializer.java 4 Nov 2002 17:01:27 -0000 1.7
@@ -65,6 +65,7 @@
import org.apache.axis.wsdl.fromJava.Types;
import org.apache.axis.encoding.SerializationContext;
import org.apache.axis.encoding.SimpleValueSerializer;
+import org.w3c.dom.Element;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -115,14 +116,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
}
}
1.7 +7 -5
xml-axis/java/src/org/apache/axis/encoding/ser/DateSerializer.java
Index: DateSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/DateSerializer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DateSerializer.java 16 Aug 2002 11:07:09 -0000 1.6
+++ DateSerializer.java 4 Nov 2002 17:01:27 -0000 1.7
@@ -66,12 +66,12 @@
import org.apache.axis.encoding.Serializer;
import org.apache.axis.encoding.SerializationContext;
import org.apache.axis.encoding.SimpleValueSerializer;
+import org.w3c.dom.Element;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
-import java.util.TimeZone;
/**
* Serializer for Dates.
@@ -118,14 +118,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
}
}
1.11 +6 -4
xml-axis/java/src/org/apache/axis/encoding/ser/ElementSerializer.java
Index: ElementSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/ElementSerializer.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ElementSerializer.java 22 Sep 2002 17:26:28 -0000 1.10
+++ ElementSerializer.java 4 Nov 2002 17:01:27 -0000 1.11
@@ -95,14 +95,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
}
}
1.15 +18 -15
xml-axis/java/src/org/apache/axis/encoding/ser/EnumSerializer.java
Index: EnumSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/EnumSerializer.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- EnumSerializer.java 18 Sep 2002 16:10:35 -0000 1.14
+++ EnumSerializer.java 4 Nov 2002 17:01:27 -0000 1.15
@@ -56,31 +56,18 @@
package org.apache.axis.encoding.ser;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
import javax.xml.namespace.QName;
import java.io.IOException;
-import org.apache.axis.Constants;
-import org.apache.axis.encoding.Serializer;
-import org.apache.axis.encoding.SerializerFactory;
import org.apache.axis.encoding.SerializationContext;
-import org.apache.axis.encoding.Deserializer;
-import org.apache.axis.encoding.DeserializerFactory;
-import org.apache.axis.encoding.DeserializationContext;
-import org.apache.axis.encoding.Deserializer;
-import org.apache.axis.InternalException;
-import org.apache.axis.utils.JavaUtils;
+import org.apache.axis.wsdl.fromJava.Types;
import org.apache.axis.utils.Messages;
import org.apache.axis.components.logger.LogFactory;
import org.apache.commons.logging.Log;
-
-import java.io.Serializable;
-import java.lang.reflect.Method;
-import java.beans.IntrospectionException;
-
+import org.w3c.dom.Element;
/**
* Serializer for a JAX-RPC enum.
@@ -123,5 +110,21 @@
log.error(Messages.getMessage("exception00"), e);
}
return null;
+ }
+
+ /**
+ * Return XML schema for the specified type, suitable for insertion into
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
+ *
+ * @param javaType the Java Class we're writing out schema for
+ * @param types the Java2WSDL Types object which holds the context
+ * for the WSDL being generated.
+ * @return a type element containing a schema simpleType/complexType
+ * @see org.apache.axis.wsdl.fromJava.Types
+ */
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ // Use Types helper method.
+ return types.writeEnumType(xmlType, javaType);
}
}
1.9 +8 -5
xml-axis/java/src/org/apache/axis/encoding/ser/HexSerializer.java
Index: HexSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/HexSerializer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- HexSerializer.java 16 Aug 2002 11:07:09 -0000 1.8
+++ HexSerializer.java 4 Nov 2002 17:01:27 -0000 1.9
@@ -67,6 +67,7 @@
import org.apache.axis.types.HexBinary;
import org.apache.axis.encoding.SimpleValueSerializer;
import org.apache.axis.utils.JavaUtils;
+import org.w3c.dom.Element;
/**
* Serializer for hexBinary.
*
@@ -98,7 +99,7 @@
public String getValueAsString(Object value, SerializationContext context) {
value = JavaUtils.convert(value, javaType);
if (javaType == HexBinary.class) {
- return ((HexBinary) value).toString();
+ return value.toString();
} else {
return HexBinary.encode((byte[]) value);
}
@@ -108,14 +109,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
}
}
1.22 +14 -32
xml-axis/java/src/org/apache/axis/encoding/ser/JAFDataHandlerSerializer.java
Index: JAFDataHandlerSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/JAFDataHandlerSerializer.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- JAFDataHandlerSerializer.java 18 Sep 2002 16:10:35 -0000 1.21
+++ JAFDataHandlerSerializer.java 4 Nov 2002 17:01:27 -0000 1.22
@@ -55,42 +55,22 @@
package org.apache.axis.encoding.ser;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-import javax.xml.namespace.QName;
-
-import java.io.IOException;
-
import org.apache.axis.Constants;
-import org.apache.axis.encoding.Serializer;
-import org.apache.axis.encoding.SerializerFactory;
-import org.apache.axis.encoding.SerializationContext;
-import org.apache.axis.encoding.Deserializer;
-import org.apache.axis.encoding.DeserializerFactory;
-import org.apache.axis.encoding.DeserializationContext;
-import org.apache.axis.encoding.Deserializer;
-import org.apache.axis.utils.JavaUtils;
-import org.apache.axis.utils.Messages;
-
-import javax.activation.DataHandler;
import org.apache.axis.Part;
import org.apache.axis.attachments.Attachments;
-import org.apache.axis.Constants;
+import org.apache.axis.components.logger.LogFactory;
+import org.apache.axis.encoding.SerializationContext;
+import org.apache.axis.encoding.Serializer;
+import org.apache.axis.utils.Messages;
import org.apache.axis.wsdl.fromJava.Types;
+import org.apache.commons.logging.Log;
+import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.axis.components.logger.LogFactory;
-import org.apache.commons.logging.Log;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Document;
/**
* JAFDataHandler Serializer
@@ -145,14 +125,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
}
}
1.18 +6 -5
xml-axis/java/src/org/apache/axis/encoding/ser/MapSerializer.java
Index: MapSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/MapSerializer.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- MapSerializer.java 18 Sep 2002 16:10:35 -0000 1.17
+++ MapSerializer.java 4 Nov 2002 17:01:27 -0000 1.18
@@ -58,7 +58,6 @@
import org.apache.axis.Constants;
import org.apache.axis.encoding.SerializationContext;
import org.apache.axis.encoding.Serializer;
-import org.apache.axis.utils.JavaUtils;
import org.apache.axis.utils.Messages;
import org.apache.axis.wsdl.fromJava.Types;
@@ -137,14 +136,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
+ public Element writeSchema(Class javaType, Types types) throws Exception {
Element complexType = types.createElement("complexType");
complexType.setAttribute("name", "Map");
types.writeSchemaElement(Constants.SOAP_MAP, complexType);
@@ -173,6 +174,6 @@
value.setAttribute("type", "xsd:anyType");
all.appendChild(value);
- return true;
+ return complexType;
}
}
1.7 +7 -4
xml-axis/java/src/org/apache/axis/encoding/ser/QNameSerializer.java
Index: QNameSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/QNameSerializer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- QNameSerializer.java 19 Aug 2002 20:18:04 -0000 1.6
+++ QNameSerializer.java 4 Nov 2002 17:01:27 -0000 1.7
@@ -60,6 +60,7 @@
import org.apache.axis.encoding.SimpleValueSerializer;
import org.apache.axis.wsdl.fromJava.Types;
import org.xml.sax.Attributes;
+import org.w3c.dom.Element;
import javax.xml.namespace.QName;
@@ -93,14 +94,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
}
}
1.30 +9 -9
xml-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java
Index: SimpleSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- SimpleSerializer.java 24 Sep 2002 14:40:20 -0000 1.29
+++ SimpleSerializer.java 4 Nov 2002 17:01:27 -0000 1.30
@@ -65,7 +65,6 @@
import org.apache.axis.utils.BeanPropertyDescriptor;
import org.apache.axis.utils.BeanUtils;
import org.apache.axis.utils.Messages;
-import org.apache.axis.utils.XMLUtils;
import org.apache.axis.wsdl.fromJava.Types;
import org.w3c.dom.Element;
import org.xml.sax.Attributes;
@@ -237,17 +236,19 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
+ public Element writeSchema(Class javaType, Types types) throws Exception {
// Let the caller generate WSDL if this is not a SimpleType
if (!SimpleType.class.isAssignableFrom(javaType))
- return false;
+ return null;
// ComplexType representation of SimpleType bean class
Element complexType = types.createElement("complexType");
@@ -274,7 +275,6 @@
QName qname = field.getXmlName();
if (qname == null) {
// Use the default...
- propName = propName;
qname = new QName("", propName);
}
@@ -290,9 +290,9 @@
// write attribute element
// TODO the attribute name needs to be preserved from the
XML
- String elementType = types.writeType(fieldType);
Element elem = types.createAttributeElement(propName,
- elementType,
+ fieldType,
+ field.getXmlType(),
false,
extension.getOwnerDocument());
extension.appendChild(elem);
@@ -313,7 +313,7 @@
}
// done
- return true;
+ return complexType;
}
}
1.15 +6 -5
xml-axis/java/src/org/apache/axis/encoding/ser/VectorSerializer.java
Index: VectorSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/VectorSerializer.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- VectorSerializer.java 18 Sep 2002 16:10:35 -0000 1.14
+++ VectorSerializer.java 4 Nov 2002 17:01:27 -0000 1.15
@@ -65,7 +65,6 @@
import org.apache.axis.wsdl.fromJava.Types;
import org.apache.axis.encoding.Serializer;
import org.apache.axis.encoding.SerializationContext;
-import org.apache.axis.utils.JavaUtils;
import org.apache.axis.utils.Messages;
import java.io.IOException;
@@ -125,14 +124,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
+ public Element writeSchema(Class javaType, Types types) throws Exception {
Element complexType = types.createElement("complexType");
complexType.setAttribute("name", "Vector");
types.writeSchemaElement(Constants.SOAP_VECTOR, complexType);
@@ -146,6 +147,6 @@
element.setAttribute("type", "xsd:anyType");
seq.appendChild(element);
- return true;
+ return complexType;
}
}
1.2 +7 -4
xml-axis/java/src/org/apache/axis/encoding/ser/castor/CastorSerializer.java
Index: CastorSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/castor/CastorSerializer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CastorSerializer.java 17 Oct 2002 23:35:48 -0000 1.1
+++ CastorSerializer.java 4 Nov 2002 17:01:28 -0000 1.2
@@ -68,6 +68,7 @@
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
+import org.w3c.dom.Element;
import javax.xml.namespace.QName;
@@ -139,14 +140,16 @@
/**
* Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
+ * the <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
*
+ * @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
+ * @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
}
}
1.26 +3 -1 xml-axis/java/src/org/apache/axis/i18n/resource.properties
Index: resource.properties
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/i18n/resource.properties,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- resource.properties 1 Nov 2002 20:14:57 -0000 1.25
+++ resource.properties 4 Nov 2002 17:01:28 -0000 1.26
@@ -1065,4 +1065,6 @@
uuidGenFactoryException02= Exception encountered while attempting to instantiate
the specified implementation of UUIDFactory: {0} message={1}
badIdType00=Invalid Id
-badLanguage00=Invalid language
\ No newline at end of file
+badLanguage00=Invalid language
+
+noContainerForAnonymousType=makeTypeElement() was told to create a type "{0}", with
no containing element
1.127 +0 -2 xml-axis/java/src/org/apache/axis/utils/Admin.java
Index: Admin.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/Admin.java,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -r1.126 -r1.127
--- Admin.java 10 Oct 2002 19:56:45 -0000 1.126
+++ Admin.java 4 Nov 2002 17:01:28 -0000 1.127
@@ -56,7 +56,6 @@
package org.apache.axis.utils ;
import java.io.FileInputStream;
-import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.InetAddress;
@@ -83,7 +82,6 @@
import org.xml.sax.InputSource;
import java.io.FileInputStream;
-import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.InetAddress;
1.76 +16 -24 xml-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java
Index: Emitter.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -r1.75 -r1.76
--- Emitter.java 1 Nov 2002 20:14:56 -0000 1.75
+++ Emitter.java 4 Nov 2002 17:01:28 -0000 1.76
@@ -58,7 +58,6 @@
import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;
import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;
import com.ibm.wsdl.extensions.soap.SOAPBodyImpl;
-import com.ibm.wsdl.extensions.soap.SOAPFaultImpl;
import com.ibm.wsdl.extensions.soap.SOAPOperationImpl;
import com.ibm.wsdl.BindingFaultImpl;
@@ -76,6 +75,7 @@
import org.apache.axis.utils.XMLUtils;
import org.apache.axis.utils.JavaUtils;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.xml.sax.SAXException;
@@ -1231,7 +1231,7 @@
// the parameter
if (types.writeWrapperForPart(wrapperQName,
param.getName(),
- typeQName)) {
+ typeQName, javaType)) {
// If wrapper element is written
// add <part name="parameters" element=wrapper_elem />
// Really shouldn't matter what name is used, but
@@ -1250,34 +1250,26 @@
QName typeQName =
types.writeTypeForPart(javaType,
param.getTypeQName());
- types.writeElementForPart(javaType, param.getTypeQName());
+ //types.writeElementForPart(javaType, param.getTypeQName());
if (typeQName != null) {
part.setName(param.getName());
part.setTypeName(typeQName);
msg.addPart(part);
}
} else if (use == Use.LITERAL) {
- // Write the type representing the param.
- // Write the element representing the param
- // If an element was written
- // Write <part name=param_name element=param_element>
- // Else its a simple type,
- // Write <part name=param_name type=param_type>
- QName typeQName =
- types.writeTypeForPart(javaType,
- param.getTypeQName());
- QName elemQName =
- types.writeElementForPart(javaType,
- param.getTypeQName());
- if (elemQName != null) {
- part.setName(param.getName());
- part.setElementName(elemQName);
- msg.addPart(part);
- } else if (typeQName != null) {
- part.setName(param.getName());
- part.setTypeName(typeQName);
- msg.addPart(part);
- }
+ // This is doc/lit. So we should write out an element
+ // declaration whose name and type may be found in the
+ // ParameterDesc.
+ QName qname = param.getQName();
+ Element el = types.createElementDecl(qname.getLocalPart(),
+ param.getJavaType(),
+ param.getTypeQName(),
+ false, false);
+ types.writeSchemaElement(qname, el);
+
+ part.setName(param.getName());
+ part.setElementName(qname);
+ msg.addPart(part);
}
return param.getName();
}
1.6 +3 -3 xml-axis/java/src/org/apache/axis/wsdl/fromJava/Namespaces.java
Index: Namespaces.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Namespaces.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Namespaces.java 25 Oct 2002 19:10:22 -0000 1.5
+++ Namespaces.java 4 Nov 2002 17:01:28 -0000 1.6
@@ -82,7 +82,7 @@
public String getCreate(String key) {
Object value = super.get(key);
if (value == null) {
- value = makeNamespaceFromPackageName((String) key);
+ value = makeNamespaceFromPackageName(key);
put(key, value, null);
}
return (String) value;
@@ -98,7 +98,7 @@
public String getCreate(String key, String prefix) {
Object value = super.get(key);
if (value == null) {
- value = makeNamespaceFromPackageName((String) key);
+ value = makeNamespaceFromPackageName(key);
put(key, value, prefix);
}
return (String) value;
@@ -140,7 +140,7 @@
* @param namespace namespace
* @return prefix String
*/
- public String getCreatePrefix(String namespace) {
+ public String getCreatePrefix(String namespace) {
if (namespacePrefixMap.get(namespace) == null) {
namespacePrefixMap.put(namespace, "tns" + prefixCount++);
}
1.66 +262 -172 xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java
Index: Types.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- Types.java 1 Nov 2002 20:14:56 -0000 1.65
+++ Types.java 4 Nov 2002 17:01:28 -0000 1.66
@@ -64,6 +64,7 @@
import org.apache.axis.encoding.SimpleType;
import org.apache.axis.encoding.TypeMapping;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
+import org.apache.axis.encoding.ser.EnumSerializerFactory;
import org.apache.axis.utils.JavaUtils;
import org.apache.axis.utils.Messages;
import org.apache.axis.utils.XMLUtils;
@@ -88,12 +89,9 @@
import javax.wsdl.WSDLException;
import javax.xml.namespace.QName;
import javax.xml.rpc.holders.Holder;
-import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
-import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@@ -155,22 +153,22 @@
/**
* Return the namespaces object for the current context
- */
+ */
public Namespaces getNamespaces() {
return namespaces;
}
-
+
/**
* Loads the types from the input schema file.
* @param inputSchema file or URL
*/
public void loadInputSchema(String inputSchema)
- throws IOException, WSDLException, SAXException,
+ throws IOException, WSDLException, SAXException,
ParserConfigurationException
{
// Read the input wsdl file into a Document
Document doc = XMLUtils.newDocument(inputSchema);
-
+
// Ensure that the root element is xsd:schema
Element root = doc.getDocumentElement();
if (root.getLocalName().equals("schema") &&
@@ -182,33 +180,33 @@
wsdlTypesElem.appendChild(schema);
// Create a symbol table and populate it with the input types
- BaseTypeMapping btm =
+ BaseTypeMapping btm =
new BaseTypeMapping() {
public String getBaseName(QName qNameIn) {
QName qName = new QName(
- qNameIn.getNamespaceURI(),
+ qNameIn.getNamespaceURI(),
qNameIn.getLocalPart());
Class cls = defaultTM.getClassForQName(qName);
if (cls == null)
return null;
- else
+ else
return JavaUtils.getTextClassName(cls.getName());
}
- };
+ };
SymbolTable symbolTable = new SymbolTable(btm,
true, false, false);
symbolTable.populateTypes(new URL(inputSchema), doc);
- // Walk the type/element entries in the symbol table and
+ // Walk the type/element entries in the symbol table and
// add each one to the list of processed types. This prevents
// the types from being duplicated.
Vector v = symbolTable.getTypes();
for (int i=0; i < v.size(); i++) {
TypeEntry te = (TypeEntry) v.elementAt(i);
- if (te instanceof org.apache.axis.wsdl.symbolTable.Element) {
+ if (te instanceof org.apache.axis.wsdl.symbolTable.Element) {
addToElementsList(te.getQName());
} else if (te instanceof Type) {
- addToTypesList(te.getQName());
+ addToTypesList(te.getQName());
}
}
} else {
@@ -232,11 +230,11 @@
// Search for the 'types' element
NodeList elements = doc.getChildNodes();
- if (elements.getLength() > 0 &&
+ if (elements.getLength() > 0 &&
elements.item(0).getLocalName().equals("definitions")) {
elements = elements.item(0).getChildNodes();
for (int i=0;
- i < elements.getLength() && wsdlTypesElem == null;
+ i < elements.getLength() && wsdlTypesElem == null;
i++) {
Node node = elements.item(i);
if (node.getLocalName() != null &&
@@ -252,38 +250,38 @@
}
// Import the types element into the Types docHolder document
- wsdlTypesElem =
+ wsdlTypesElem =
(Element) docHolder.importNode(wsdlTypesElem, true);
docHolder.appendChild(wsdlTypesElem);
// Create a symbol table and populate it with the input wsdl document
- BaseTypeMapping btm =
+ BaseTypeMapping btm =
new BaseTypeMapping() {
public String getBaseName(QName qNameIn) {
QName qName = new QName(
- qNameIn.getNamespaceURI(),
+ qNameIn.getNamespaceURI(),
qNameIn.getLocalPart());
Class cls = defaultTM.getClassForQName(qName);
if (cls == null)
return null;
- else
+ else
return JavaUtils.getTextClassName(cls.getName());
}
- };
+ };
SymbolTable symbolTable = new SymbolTable(btm,
true, false, false);
symbolTable.populate(null, doc);
- // Walk the type/element entries in the symbol table and
+ // Walk the type/element entries in the symbol table and
// add each one to the list of processed types. This prevents
// the types from being duplicated.
Vector v = symbolTable.getTypes();
for (int i=0; i < v.size(); i++) {
TypeEntry te = (TypeEntry) v.elementAt(i);
- if (te instanceof org.apache.axis.wsdl.symbolTable.Element) {
+ if (te instanceof org.apache.axis.wsdl.symbolTable.Element) {
addToElementsList(te.getQName());
} else if (te instanceof Type) {
- addToTypesList(te.getQName());
+ addToTypesList(te.getQName());
}
}
}
@@ -315,25 +313,18 @@
type = JavaUtils.getHolderValueType(type);
}
- // Get the qname
- if (qname == null ||
+ // Get the qname
+ if (qname == null ||
(Constants.isSOAP_ENC(qname.getNamespaceURI()) &&
"Array".equals(qname.getLocalPart()))) {
qname = getTypeQName(type);
if (qname == null) {
- throw new AxisFault("Class:" + type.getName());
+ throw new AxisFault("Class:" + type.getName());
}
}
- // Make sure a types section is present
- if (wsdlTypesElem == null) {
- writeWsdlTypesElement();
- }
+ makeTypeElement(type, qname, null);
- // Write the type, if problems occur use ANYTYPE
- if (writeType(type, qname) == null) {
- qname = Constants.XSD_ANYTYPE;
- }
return qname;
}
@@ -362,13 +353,13 @@
type = JavaUtils.getHolderValueType(type);
}
- // Get the qname
- if (qname == null ||
+ // Get the qname
+ if (qname == null ||
(Constants.isSOAP_ENC(qname.getNamespaceURI()) &&
"Array".equals(qname.getLocalPart()))) {
qname = getTypeQName(type);
if (qname == null) {
- throw new AxisFault("Class:" +type.getName());
+ throw new AxisFault("Class:" +type.getName());
}
}
@@ -400,7 +391,7 @@
* @param type is the QName of the type of the element.
* @return true if the wrapperQName was created, false if it already exists.
*/
- public boolean writeWrapperForPart(QName wrapper, String name, QName type)
+ public boolean writeWrapperForPart(QName wrapper, String name, QName type,
Class javaType)
throws AxisFault {
// Make sure a types section is present
@@ -418,10 +409,10 @@
// Create a type if this is a new wrapper
if (isNew) {
// Create an <element> for the wrapper
- Element wrapperElement =
+ Element wrapperElement =
docHolder.createElement("element");
writeSchemaElement(wrapper, wrapperElement);
- wrapperElement.setAttribute("name",
+ wrapperElement.setAttribute("name",
wrapper.getLocalPart());
// Create an anonymous <complexType> for the wrapper
@@ -432,20 +423,30 @@
sequence = docHolder.createElement("sequence");
complexType.appendChild(sequence);
wrapperMap.put(wrapper, sequence);
-
+
+ }
+
+ Element childElem;
+ if (isAnonymousType(type)) {
+ childElem = createElementWithAnonymousType(name, javaType, false,
docHolder);
+ } else {
+ // Create the child <element> and add it to the wrapper <sequence>
+ childElem = docHolder.createElement("element");
+ childElem.setAttribute("name", name);
+
+ String prefix = namespaces.getCreatePrefix(type.getNamespaceURI());
+ String prefixedName = prefix+":"+type.getLocalPart();
+ childElem.setAttribute("type", prefixedName);
}
-
- // Create the child <element> and add it to the wrapper <sequence>
- Element childElem = docHolder.createElement("element");
- childElem.setAttribute("name", name);
- String prefix = namespaces.getCreatePrefix(type.getNamespaceURI());
- String prefixedName = prefix+":"+type.getLocalPart();
- childElem.setAttribute("type", prefixedName);
sequence.appendChild(childElem);
-
+
return isNew;
}
+ private boolean isAnonymousType(QName type) {
+ return type.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) != -1;
+ }
+
/**
* Create a schema element for the given type
* @param type the class type
@@ -457,9 +458,10 @@
qName = getTypeQName(type);
}
QName typeQName = writeTypeNamespace(type, qName);
+
String elementType = writeType(type, qName);
if (elementType != null) {
- Element element = createElementDecl(qName, elementType,
isNullable(type));
+ Element element = createElementDecl(qName.getLocalPart(), type, qName,
isNullable(type), false);
if (element != null)
writeSchemaElement(typeQName,element);
return qName;
@@ -566,6 +568,19 @@
}
/**
+ * Return a string suitable for representing a given QName in the context
+ * of this WSDL document. If the namespace of the QName is not yet
+ * registered, we will register it up in the Definitions.
+ *
+ * @param qname a QName (typically a type)
+ * @return a String containing a standard "ns:localPart" rep of the QName
+ */
+ public String getQNameString(QName qname) {
+ String prefix = namespaces.getCreatePrefix(qname.getNamespaceURI());
+ return prefix + ":" + qname.getLocalPart();
+ }
+
+ /**
* Utility method to get the package name from a fully qualified java class name
* @param full input class name
* @return package name
@@ -628,6 +643,8 @@
Element importElem = docHolder.createElement("import");
schemaElem.appendChild(importElem);
importElem.setAttribute("namespace", Constants.URI_DEFAULT_SOAP_ENC);
+
+ writeTypeNamespace(qName);
}
schemaElem.appendChild(element);
}
@@ -676,101 +693,30 @@
qName = getTypeQName(type);
}
- // Quick return if schema type
- if (Constants.isSchemaXSD(qName.getNamespaceURI())) {
- return Constants.NS_PREFIX_SCHEMA_XSD + ":" +
- qName.getLocalPart();
- } else if (Constants.isSOAP_ENC(qName.getNamespaceURI()) &&
- !"Array".equals(qName.getLocalPart())) {
- return Constants.NS_PREFIX_SOAP_ENC + ":" +
- qName.getLocalPart();
- }
-
- // look up the serializer in the TypeMappingRegistry
- Serializer ser = null;
- SerializerFactory factory = null;
- if (tm != null) {
- factory = (SerializerFactory)tm.getSerializer(type);
- } else {
- factory = (SerializerFactory)defaultTM.getSerializer(type);
- }
-
- // If no factory is found, use the BeanSerializerFactory
- // if applicable, otherwise issue errors and treat as an anyType
- if (factory == null) {
- if (isBeanCompatible(type, true)) {
- factory = new BeanSerializerFactory(type, qName);
- } else {
- return null; // Don't return an element name
- }
- }
-
- if (factory != null) {
- ser = (Serializer)factory.getSerializerAs(Constants.AXIS_SAX);
- }
-
- // if we can't get a serializer, that is bad.
- if (ser == null) {
- throw new AxisFault(
- Messages.getMessage("NoSerializer00", type.getName()));
- }
-
- // Write the namespace
- writeTypeNamespace(type, qName);
-
- // If an array the component type should be processed first
- String componentTypeName = null;
- Class componentType = null;
- if (type.isArray()) {
- String dimString = "[]";
- componentType = type.getComponentType();
- if (componentType.isArray()) {
- while (componentType.isArray()) {
- dimString += "[]";
- componentType = componentType.getComponentType();
- }
- }
- componentTypeName = writeType(componentType, null) + dimString;
- }
+ makeTypeElement(type, qName, null);
+ return getQNameString(qName);
+ }
- String prefix = namespaces.getCreatePrefix(qName.getNamespaceURI());
- String prefixedName = prefix+":"+qName.getLocalPart();
+ public Element createArrayElement(String componentTypeName) {
+ // ComplexType representation of array
+ Element complexType = docHolder.createElement("complexType");
- // If processed before, or this is a known namespace, return
- if (!addToTypesList(qName))
- return prefixedName;
- if (type.isArray()) {
- // ComplexType representation of array
- Element complexType = docHolder.createElement("complexType");
- writeSchemaElement(qName, complexType);
- complexType.setAttribute("name", qName.getLocalPart());
+ Element complexContent = docHolder.createElement("complexContent");
+ complexType.appendChild(complexContent);
- Element complexContent = docHolder.createElement("complexContent");
- complexType.appendChild(complexContent);
+ Element restriction = docHolder.createElement("restriction");
+ complexContent.appendChild(restriction);
+ restriction.setAttribute("base",
+ Constants.NS_PREFIX_SOAP_ENC + ":Array");
+
+ Element attribute = docHolder.createElement("attribute");
+ restriction.appendChild(attribute);
+ attribute.setAttribute("ref",
+ Constants.NS_PREFIX_SOAP_ENC +":arrayType");
+ attribute.setAttribute(Constants.NS_PREFIX_WSDL +":arrayType",
+ componentTypeName);
- Element restriction = docHolder.createElement("restriction");
- complexContent.appendChild(restriction);
- restriction.setAttribute("base",
- Constants.NS_PREFIX_SOAP_ENC + ":Array");
-
- Element attribute = docHolder.createElement("attribute");
- restriction.appendChild(attribute);
- attribute.setAttribute("ref",
- Constants.NS_PREFIX_SOAP_ENC +":arrayType");
- attribute.setAttribute(Constants.NS_PREFIX_WSDL +":arrayType",
- componentTypeName );
- } else {
- try {
- if (isEnumClass(type)) {
- writeEnumType(qName, type);
- } else {
- ser.writeSchema(this);
- }
- } catch (Exception e) {
- throw new AxisFault(Messages.getMessage("writeSchemaProblem00",
type.getName()), e);
- }
- }
- return prefixedName;
+ return complexType;
}
/**
@@ -816,17 +762,18 @@
* @param qName QName of type.
* @param cls class of type
*/
- private void writeEnumType(QName qName, Class cls)
+ public Element writeEnumType(QName qName, Class cls)
throws NoSuchMethodException, IllegalAccessException, AxisFault {
+
if (!isEnumClass(cls))
- return;
+ return null;
+
// Get the base type of the enum class
java.lang.reflect.Method m = cls.getMethod("getValue", null);
Class base = m.getReturnType();
// Create simpleType, restriction elements
Element simpleType = docHolder.createElement("simpleType");
- writeSchemaElement(qName, simpleType);
simpleType.setAttribute("name", qName.getLocalPart());
Element restriction = docHolder.createElement("restriction");
simpleType.appendChild(restriction);
@@ -849,33 +796,38 @@
Element enumeration = docHolder.createElement("enumeration");
enumeration.setAttribute("value", field.get(null).toString());
restriction.appendChild(enumeration);
-
}
}
+ return simpleType;
}
/**
* Create Element
- * @param qName the namespace of the created element
- * @param elementType schema type representation of the element
- * @param nullable nillable attribute of the element
+ * @param nillable nillable attribute of the element
* @return the created Element
*/
- private Element createElementDecl(QName qName,
- String elementType,
- boolean nullable) {
- if (!addToElementsList(qName))
- return null;
-
+ public Element createElementDecl(String name,
+ Class javaType,
+ QName typeQName,
+ boolean nillable,
+ boolean omittable) throws AxisFault {
Element element = docHolder.createElement("element");
- //Generate an element name that matches the type.
+ // Generate an element name that matches the type.
- element.setAttribute("name", qName.getLocalPart());
- if (nullable)
+ element.setAttribute("name", name);
+
+ if (nillable)
element.setAttribute("nillable", "true");
- element.setAttribute("type", elementType);
+ if (omittable) {
+ element.setAttribute("minOccurs", "0");
+ element.setAttribute("maxOccurs", "1");
+ }
+
+ // Write the type for this element, handling anonymous or named
+ // types appropriately.
+ makeTypeElement(javaType, typeQName, element);
return element;
}
@@ -899,7 +851,8 @@
element.setAttribute("minOccurs", "0");
element.setAttribute("maxOccurs", "1");
}
- element.setAttribute("type", elementType);
+ if (elementType != null)
+ element.setAttribute("type", elementType);
return element;
}
@@ -907,19 +860,20 @@
/**
* Create Attribute Element with a given name and type
* @param elementName the name of the created element
- * @param elementType schema type representation of the element
* @param nullable nullable attribute of the element
* @return the created Element
*/
public Element createAttributeElement(String elementName,
- String elementType,
+ Class javaType,
+ QName xmlType,
boolean nullable,
- Document docHolder) {
+ Document docHolder) throws AxisFault {
Element element = docHolder.createElement("attribute");
element.setAttribute("name", elementName);
if (nullable)
element.setAttribute("nillable", "true");
- element.setAttribute("type", elementType);
+
+ makeTypeElement(javaType, xmlType, element);
return element;
}
@@ -998,6 +952,16 @@
private boolean addToTypesList (QName qName) {
boolean added = false;
ArrayList types = (ArrayList)schemaTypes.get(qName.getNamespaceURI());
+
+ // Quick return if schema type (will never add these ourselves)
+ if (Constants.isSchemaXSD(qName.getNamespaceURI()) ||
+ (Constants.isSOAP_ENC(qName.getNamespaceURI()) &&
+ !"Array".equals(qName.getLocalPart()))) {
+ // Make sure we do have the namespace declared, though...
+ writeTypeNamespace(qName);
+ return false;
+ }
+
if (types == null) {
types = new ArrayList();
types.add(qName.getLocalPart());
@@ -1122,7 +1086,7 @@
{
return docHolder.createElement(elementName);
}
-
+
/**
* isBeanCompatible
* @param javaType Class
@@ -1136,7 +1100,7 @@
// Must be a non-primitive and non array
if (javaType.isArray() ||
javaType.isPrimitive()) {
- if (issueErrors &&
+ if (issueErrors &&
!beanCompatErrs.contains(javaType)) {
log.warn(Messages.getMessage("beanCompatType00",
javaType.getName()));
@@ -1144,12 +1108,12 @@
}
return false;
}
-
+
// Anything in the java or javax package that
// does not have a defined mapping is excluded.
if (javaType.getName().startsWith("java.") ||
javaType.getName().startsWith("javax.")) {
- if (issueErrors &&
+ if (issueErrors &&
!beanCompatErrs.contains(javaType)) {
log.warn(Messages.getMessage("beanCompatPkg00",
javaType.getName()));
@@ -1162,14 +1126,14 @@
if (JavaUtils.isEnumClass(javaType)) {
return true;
}
-
+
// Must have a default public constructor if not
// Throwable
if (!java.lang.Throwable.class.isAssignableFrom(javaType)) {
try {
javaType.getConstructor(new Class[] {});
} catch (java.lang.NoSuchMethodException e) {
- if (issueErrors &&
+ if (issueErrors &&
!beanCompatErrs.contains(javaType)) {
log.warn(Messages.getMessage("beanCompatConstructor00",
javaType.getName()));
@@ -1192,7 +1156,7 @@
if (!isBeanCompatible(superClass, false)) {
- if (issueErrors &&
+ if (issueErrors &&
!beanCompatErrs.contains(javaType)) {
log.warn(Messages.getMessage("beanCompatExtends00",
javaType.getName(),
@@ -1205,5 +1169,131 @@
}
return true;
}
-
+
+ /**
+ * Write an <element> with an anonymous internal ComplexType
+ *
+ * @param elementName
+ * @param fieldType
+ * @param omittable
+ * @param ownerDocument
+ */
+ public Element createElementWithAnonymousType(String elementName,
+ Class fieldType,
+ boolean omittable,
+ Document ownerDocument) throws
AxisFault {
+ Element element = docHolder.createElement("element");
+ element.setAttribute("name", elementName);
+ if (isNullable(fieldType))
+ element.setAttribute("nillable", "true");
+ if (omittable) {
+ element.setAttribute("minOccurs", "0");
+ element.setAttribute("maxOccurs", "1");
+ }
+
+ makeTypeElement(fieldType, null, element);
+
+ return element;
+ }
+
+ /**
+ * Create a schema type element (either simpleType or complexType) for
+ * the particular type/qName combination. If the type is named, we
+ * handle inserting the new type into the appropriate <schema>
+ * in the WSDL types section. If the type is anonymous, we append the
+ * definition underneath the Element which was passed as the container
+ * (typically a field of a higher-level type or a parameter in a wrapped
+ * operation).
+ *
+ * @param type Java type to write
+ * @param qName the desired type QName
+ * @param containingElement a schema element ("element" or "attribute")
+ * which should either receive a type="" attribute decoration
+ * (for named types) or a child element defining an anonymous
+ * type
+ * @throws AxisFault
+ */
+ private void makeTypeElement(Class type,
+ QName qName,
+ Element containingElement) throws AxisFault {
+ // Get a corresponding QName if one is not provided
+ if (qName == null ||
+ Constants.equals(Constants.SOAP_ARRAY, qName)) {
+ qName = getTypeQName(type);
+ }
+
+ boolean anonymous = isAnonymousType(qName);
+
+ // Can't have an anonymous type outside of a containing element
+ if (anonymous && containingElement == null) {
+ throw new AxisFault(
+ Messages.getMessage("noContainerForAnonymousType",
+ qName.toString()));
+ }
+
+ // If we've already got this type (because it's a native type or
+ // because we've already written it), just add the type="" attribute
+ // (if appropriate) and return.
+ if (!addToTypesList(qName)) {
+ if (containingElement != null)
+ containingElement.setAttribute("type", getQNameString(qName));
+ return;
+ }
+
+ // look up the serializer in the TypeMappingRegistry
+ Serializer ser = null;
+ SerializerFactory factory = null;
+ if (tm != null) {
+ factory = (SerializerFactory)tm.getSerializer(type);
+ } else {
+ factory = (SerializerFactory)defaultTM.getSerializer(type);
+ }
+
+ // If no factory is found, use the BeanSerializerFactory
+ // if applicable, otherwise issue errors and treat as an anyType
+ if (factory == null) {
+ if (isEnumClass(type)) {
+ factory = new EnumSerializerFactory(type, qName);
+ } else if (isBeanCompatible(type, true)) {
+ factory = new BeanSerializerFactory(type, qName);
+ } else {
+ return;
+ }
+ }
+
+ if (factory != null) {
+ ser = (Serializer)factory.getSerializerAs(Constants.AXIS_SAX);
+ }
+
+ // if we can't get a serializer, that is bad.
+ if (ser == null) {
+ throw new AxisFault(
+ Messages.getMessage("NoSerializer00", type.getName()));
+ }
+
+ Element typeEl;
+ try {
+ typeEl = ser.writeSchema(type, this);
+ } catch (Exception e) {
+ throw AxisFault.makeFault(e);
+ }
+
+ // If this is an anonymous type, just make the type element a child
+ // of containingElement. If not, set the "type" attribute of
+ // containingElement to the right QName, and make sure the type is
+ // correctly written into the appropriate <schema> element.
+ if (anonymous) {
+ containingElement.appendChild(typeEl);
+ } else {
+ if (typeEl != null) {
+ typeEl.setAttribute("name", qName.getLocalPart());
+
+ // Write the type in the appropriate <schema>
+ writeSchemaElement(qName, typeEl);
+ }
+
+ if (containingElement != null)
+ containingElement.setAttribute("type", getQNameString(qName));
+ }
+ }
}
1.15 +3 -11 xml-axis/java/test/encoding/DataSer.java
Index: DataSer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/encoding/DataSer.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DataSer.java 22 Jul 2002 20:10:05 -0000 1.14
+++ DataSer.java 4 Nov 2002 17:01:29 -0000 1.15
@@ -6,6 +6,7 @@
import org.xml.sax.Attributes;
import org.apache.axis.Constants;
import org.apache.axis.wsdl.fromJava.Types;
+import org.w3c.dom.Element;
import javax.xml.namespace.QName;
import java.io.IOException;
@@ -40,16 +41,7 @@
}
public String getMechanismType() { return Constants.AXIS_SAX; }
- /**
- * Return XML schema for the specified type, suitable for insertion into
- * the <types> element of a WSDL document.
- *
- * @param types the Java2WSDL Types object which holds the context
- * for the WSDL being generated.
- * @return true if we wrote a schema, false if we didn't.
- * @see org.apache.axis.wsdl.fromJava.Types
- */
- public boolean writeSchema(Types types) throws Exception {
- return false;
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
}
}