scheu 02/02/05 14:42:36
Modified: java/src/org/apache/axis/wsdl/toJava SchemaUtils.java
SymbolTable.java TypeEntry.java
java/test/wsdl/types ComprehensiveTypes.wsdl
Log:
Added support for simple simpleTypes.
The emitter uses the base name as described in the notes on axis-dev.
Here is an example of a simple simpleType. References to "foo"
will be treated as references to "xsd:string"
<simpleType name="foo" >
<restriction base="xsd:string" />
</simpleType>
I made sure that this new stuff works well with forward references.
Added simpleTypes to the comprehensive test to validate.
Revision Changes Path
1.7 +138 -0 xml-axis/java/src/org/apache/axis/wsdl/toJava/SchemaUtils.java
Index: SchemaUtils.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/SchemaUtils.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SchemaUtils.java 31 Dec 2001 18:31:41 -0000 1.6
+++ SchemaUtils.java 5 Feb 2002 22:42:35 -0000 1.7
@@ -364,6 +364,144 @@
}
/**
+ * If the specified node represents a 'normal' non-enumeration simpleType,
+ * the QName of the simpleType base is returned.
+ */
+ public static QName getSimpleTypeBase(Node node, SymbolTable symbolTable) {
+ QName baseQName = null;
+
+ if (node == null) {
+ return null;
+ }
+
+ // If the node kind is an element, dive into it.
+ QName nodeKind = Utils.getNodeQName(node);
+ if (nodeKind != null &&
+ nodeKind.getLocalPart().equals("element") &&
+ Constants.isSchemaXSD(nodeKind.getNamespaceURI())) {
+ NodeList children = node.getChildNodes();
+ Node simpleNode = null;
+ for (int j = 0; j < children.getLength() && simpleNode == null; j++) {
+ QName simpleKind = Utils.getNodeQName(children.item(j));
+ if (simpleKind != null &&
+ simpleKind.getLocalPart().equals("simpleType") &&
+ Constants.isSchemaXSD(simpleKind.getNamespaceURI())) {
+ simpleNode = children.item(j);
+ node = simpleNode;
+ }
+ }
+ }
+ // Get the node kind, expecting a schema simpleType
+ nodeKind = Utils.getNodeQName(node);
+ if (nodeKind != null &&
+ nodeKind.getLocalPart().equals("simpleType") &&
+ Constants.isSchemaXSD(nodeKind.getNamespaceURI())) {
+
+ // Under the simpleType there should be a restriction.
+ // (There may be other #text nodes, which we will ignore).
+ NodeList children = node.getChildNodes();
+ Node restrictionNode = null;
+ for (int j = 0; j < children.getLength() && restrictionNode == null;
j++) {
+ QName restrictionKind = Utils.getNodeQName(children.item(j));
+ if (restrictionKind != null &&
+ restrictionKind.getLocalPart().equals("restriction") &&
+ Constants.isSchemaXSD(restrictionKind.getNamespaceURI()))
+ restrictionNode = children.item(j);
+ }
+
+ // The restriction node indicates the type being restricted
+ // (the base attribute contains this type).
+
+ if (restrictionNode != null) {
+ baseQName = Utils.getNodeTypeRefQName(restrictionNode, "base");
+ }
+
+ // Look for enumeration elements underneath the restriction node
+ if (baseQName != null && restrictionNode != null) {
+ NodeList enums = restrictionNode.getChildNodes();
+ for (int i=0; i < enums.getLength(); i++) {
+ QName enumKind = Utils.getNodeQName(enums.item(i));
+ if (enumKind != null &&
+ enumKind.getLocalPart().equals("enumeration") &&
+ Constants.isSchemaXSD(enumKind.getNamespaceURI())) {
+
+ // Found an enumeration, this isn't a
+ // 'normal' simple type.
+ return null;
+ }
+ }
+ }
+ }
+ return baseQName;
+ }
+
+ /**
+ * Returns the contained restriction or extension node underneath
+ * the specified node. Returns null if not found
+ */
+ public static Node getRestrictionOrExtensionNode(Node node) {
+ Node re = null;
+ if (node == null) {
+ return re;
+ }
+
+ // If the node kind is an element, dive into it.
+ QName nodeKind = Utils.getNodeQName(node);
+ if (nodeKind != null &&
+ nodeKind.getLocalPart().equals("element") &&
+ Constants.isSchemaXSD(nodeKind.getNamespaceURI())) {
+ NodeList children = node.getChildNodes();
+ Node node2 = null;
+ for (int j = 0; j < children.getLength() && node2 == null; j++) {
+ QName kind2 = Utils.getNodeQName(children.item(j));
+ if (kind2 != null &&
+ (kind2.getLocalPart().equals("simpleType") ||
+ kind2.getLocalPart().equals("complexType")) &&
+ Constants.isSchemaXSD(kind2.getNamespaceURI())) {
+ node2 = children.item(j);
+ node = node2;
+ }
+ }
+ }
+ // Get the node kind, expecting a schema simpleType
+ nodeKind = Utils.getNodeQName(node);
+ if (nodeKind != null &&
+ (nodeKind.getLocalPart().equals("simpleType") ||
+ nodeKind.getLocalPart().equals("complexType")) &&
+ Constants.isSchemaXSD(nodeKind.getNamespaceURI())) {
+
+ // Under the complexType there could be a complexContent.
+ NodeList children = node.getChildNodes();
+ Node complexContent = null;
+ Node extension = null;
+ if (nodeKind.getLocalPart().equals("complexType")) {
+ for (int j = 0; j < children.getLength() && complexContent == null;
j++) {
+ QName complexContentKind = Utils.getNodeQName(children.item(j));
+ if (complexContentKind != null &&
+ complexContentKind.getLocalPart().equals("complexContent")
&&
+ Constants.isSchemaXSD(complexContentKind.getNamespaceURI()))
+ complexContent = children.item(j);
+ }
+ node = complexContent;
+ }
+ // Now get the extension or restriction node
+ if (node != null) {
+ children = node.getChildNodes();
+ for (int j = 0; j < children.getLength() && re == null; j++) {
+ QName reKind = Utils.getNodeQName(children.item(j));
+ if (reKind != null &&
+ (reKind.getLocalPart().equals("extension") ||
+ reKind.getLocalPart().equals("restriction")) &&
+ Constants.isSchemaXSD(reKind.getNamespaceURI()))
+ re = children.item(j);
+ }
+ }
+ }
+
+ return re;
+ }
+
+ /**
* If the specified node represents an array encoding of one of the following
* forms, then return the qname repesenting the element type of the array.
*/
1.24 +44 -37 xml-axis/java/src/org/apache/axis/wsdl/toJava/SymbolTable.java
Index: SymbolTable.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/SymbolTable.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- SymbolTable.java 1 Feb 2002 18:04:08 -0000 1.23
+++ SymbolTable.java 5 Feb 2002 22:42:35 -0000 1.24
@@ -495,30 +495,22 @@
QName nodeKind = Utils.getNodeQName(node);
if (nodeKind != null) {
- if (nodeKind.getLocalPart().equals("complexType") &&
+ if ((nodeKind.getLocalPart().equals("complexType") ||
+ nodeKind.getLocalPart().equals("simpleType")) &&
Constants.isSchemaXSD(nodeKind.getNamespaceURI())) {
- // This is a definition of a complex type.
- // Create a Type.
- createTypeFromDef(node, false, false);
- }
- if (nodeKind.getLocalPart().equals("simpleType") &&
- Constants.isSchemaXSD(nodeKind.getNamespaceURI())) {
+ // If an extension or restriction is present,
+ // create a type for the reference
+ Node re = SchemaUtils.getRestrictionOrExtensionNode(node);
+ if (re != null &&
+ Utils.getAttribute(re, "base") != null) {
+ createTypeFromRef(re);
+ }
- // This is a definition of a simple type, which could be an enum
+ // This is a definition of a complex type.
// Create a Type.
createTypeFromDef(node, false, false);
}
- if (nodeKind.getLocalPart().equals("restriction") ||
- nodeKind.getLocalPart().equals("extension") &&
- Constants.isSchemaXSD(nodeKind.getNamespaceURI())) {
-
- // The restriction or extension could be used for a number of
different
- // constructs (enumeration, inheritance, arrays, etc.)
- if (Utils.getAttribute(node, "base") != null) {
- createTypeFromRef(node);
- }
- }
else if (nodeKind.getLocalPart().equals("element") &&
Constants.isSchemaXSD(nodeKind.getNamespaceURI())) {
// If the element has a type/ref attribute, create
@@ -528,6 +520,14 @@
createTypeFromRef(node);
}
+ // If an extension or restriction is present,
+ // create a type for the reference
+ Node re = SchemaUtils.getRestrictionOrExtensionNode(node);
+ if (re != null &&
+ Utils.getAttribute(re, "base") != null) {
+ createTypeFromRef(re);
+ }
+
// Create a type representing an element. (This may
// seem like overkill, but is necessary to support ref=
// and element=.
@@ -583,12 +583,11 @@
// qname representing the type
BooleanHolder forElement = new BooleanHolder();
QName refQName = Utils.getNodeTypeRefQName(node, forElement);
- if (refQName != null) {
+ if (refQName != null) {
// Now get the TypeEntry
TypeEntry refType = getTypeEntry(refQName, forElement.value);
- // Create a type from the referenced TypeEntry
if (!belowSchemaLevel) {
symbolTablePut(new DefinedElement(qName, refType, node, ""));
}
@@ -596,36 +595,44 @@
else {
// Flow to here indicates no type= or ref= attribute.
- // See if this is an array definition.
+ // See if this is an array or simple type definition.
QName arrayEQName = SchemaUtils.getArrayElementQName(node);
- if (arrayEQName != null) {
- // Get the TypeEntry for the array element type
- TypeEntry arrayEType = getTypeEntry(arrayEQName, false);
- if (arrayEType == null) {
- // Array Element Type not defined yet, add one
- String baseJavaName = Utils.getBaseJavaName(arrayEQName);
+ QName simpleQName = SchemaUtils.getSimpleTypeBase(node, this);
+
+ if (arrayEQName != null || simpleQName != null) {
+ // Get the TypeEntry for the array element/simple type
+ refQName = (arrayEQName != null ? arrayEQName : simpleQName);
+ TypeEntry refType = getTypeEntry(refQName, false);
+ if (refType == null) {
+ // Not defined yet, add one
+ String baseJavaName = Utils.getBaseJavaName(refQName);
if (baseJavaName != null)
- arrayEType = new BaseJavaType(arrayEQName);
+ refType = new BaseJavaType(refQName);
else
- arrayEType = new UndefinedType(arrayEQName);
- symbolTablePut(arrayEType);
+ refType = new UndefinedType(refQName);
+ symbolTablePut(refType);
}
- // Create a defined type or element array of arrayEType.
- TypeEntry arrayType = null;
+ // Create a defined type or element that references refType
+ String dims = "";
+ if (arrayEQName != null) {
+ dims = "[]";
+ }
+ TypeEntry defType = null;
if (isElement) {
if (!belowSchemaLevel) {
- arrayType = new DefinedElement(qName, arrayEType, node,
"[]");
+ defType = new DefinedElement(qName, refType, node,
dims);
}
} else {
- arrayType = new DefinedType(qName, arrayEType, node, "[]");
+ defType = new DefinedType(qName, refType, node, dims);
}
- if (arrayType != null) {
- symbolTablePut(arrayType);
+ if (defType != null) {
+ symbolTablePut(defType);
}
}
else {
- // Create a TypeEntry representing this non-array type/element
+
+ // Create a TypeEntry representing this type/element
String baseJavaName = Utils.getBaseJavaName(qName);
if (baseJavaName != null) {
symbolTablePut(new BaseJavaType(qName));
1.7 +3 -3 xml-axis/java/src/org/apache/axis/wsdl/toJava/TypeEntry.java
Index: TypeEntry.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/TypeEntry.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TypeEntry.java 23 Jan 2002 17:53:05 -0000 1.6
+++ TypeEntry.java 5 Feb 2002 22:42:35 -0000 1.7
@@ -115,7 +115,7 @@
protected TypeEntry refType; // Some TypeEntries refer to other types.
- protected String dims; // If refType is an element, dims indicates
+ protected String dims =""; // If refType is an element, dims indicates
// the array dims (for example "[]").
protected boolean undefined; // If refType is an Undefined type
@@ -150,7 +150,7 @@
}
((Undefined)uType).register(this);
} else {
- isBaseType = (refType.getBaseType() != null && dims.equals(""));
+ isBaseType = (refType.isBaseType && refType.dims.equals("") &&
dims.equals(""));
}
//System.out.println(toString());
@@ -271,7 +271,7 @@
if (refType != null && undefined && refType.undefined==false) {
undefined = false;
changedState = true;
- isBaseType = (refType.getBaseType() != null && dims.equals(""));
+ isBaseType = (refType.isBaseType && refType.dims.equals("") &&
dims.equals(""));
}
return changedState;
}
1.14 +10 -2 xml-axis/java/test/wsdl/types/ComprehensiveTypes.wsdl
Index: ComprehensiveTypes.wsdl
===================================================================
RCS file: /home/cvs/xml-axis/java/test/wsdl/types/ComprehensiveTypes.wsdl,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ComprehensiveTypes.wsdl 30 Jan 2002 18:26:50 -0000 1.13
+++ ComprehensiveTypes.wsdl 5 Feb 2002 22:42:36 -0000 1.14
@@ -18,6 +18,10 @@
targetNamespace="urn:comprehensive-types.types.wsdl.test"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
+ <xsd:simpleType name="simple">
+ <xsd:restriction base="xsd:string" />
+ </xsd:simpleType>
+
<xsd:simpleType name="enum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="one"/>
@@ -53,7 +57,7 @@
<xsd:element name="elemWComplex">
<xsd:complexType>
<xsd:all>
- <xsd:element name="one" type="xsd:string"/>
+ <xsd:element name="one" type="typens:simple"/> <!-- Ref to a simple
type -->
<xsd:element name="two" type="typens2:fwd"/> <!-- Forward type use to
dif namespace -->
<xsd:element ref="typens2:three"/> <!-- Forward ref use to a
dif namespace -->
<xsd:element name="enum1" type="typens:enumString"/>
@@ -73,7 +77,8 @@
<xsd:element name="stock_quote">
<xsd:complexType>
<xsd:sequence>
- <xsd:element name="symbol" type="xsd:string"/>
+ <!-- forward simple type ref -->
+ <xsd:element name="symbol" type="typens:simpleFwd"/>
<xsd:element name="time" type="xsd:string"/>
<xsd:element name="last" type="xsd:string"/>
<xsd:element name="change" type="xsd:string"/>
@@ -87,6 +92,9 @@
</xsd:sequence>
</xsd:complexType>
+ <xsd:simpleType name="simpleFwd">
+ <xsd:restriction base="typens:simple" />
+ </xsd:simpleType>
<!-- The following definitions validate forward refs -->
<xsd:complexType name="arrayM">