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 ga...@apache.org on 2004/12/09 23:30:00 UTC
cvs commit: ws-axis/java/src/org/apache/axis/wsdl/symbolTable SchemaUtils.java SymbolTable.java Utils.java
gawor 2004/12/09 14:30:00
Modified: java/src/org/apache/axis/wsdl/symbolTable SchemaUtils.java
SymbolTable.java Utils.java
Log:
symbol table optimizations, including caching of dervied types suggested by someone long time ago
Revision Changes Path
1.49 +128 -135 ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SchemaUtils.java
Index: SchemaUtils.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SchemaUtils.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- SchemaUtils.java 2 Sep 2004 12:15:58 -0000 1.48
+++ SchemaUtils.java 9 Dec 2004 22:29:59 -0000 1.49
@@ -144,29 +144,31 @@
// The complex type of a wrapper element must have only sequence
// and again element declarations in the sequence.
children = node.getChildNodes();
- for (int j = 0; j < children.getLength(); j++) {
- QName subNodeKind = Utils.getNodeQName(children.item(j));
- if ((subNodeKind != null)
- && Constants.isSchemaXSD(
- subNodeKind.getNamespaceURI())) {
- if (subNodeKind.getLocalPart().equals("sequence")) {
- Node sequenceNode = children.item(j);
- NodeList sequenceChildren = sequenceNode.getChildNodes();
- for (int k = 0; k < sequenceChildren.getLength(); k++) {
- QName sequenceSubNodeKind = Utils.getNodeQName(sequenceChildren.item(k));
- if ((sequenceSubNodeKind != null)
- && Constants.isSchemaXSD(sequenceSubNodeKind.getNamespaceURI())) {
- if (!sequenceSubNodeKind.getLocalPart().equals("element")) {
+ int len = children.getLength();
+ for (int j = 0; j < len; j++) {
+ Node kid = children.item(j);
+ String localName = kid.getLocalName();
+ if (localName != null &&
+ Constants.isSchemaXSD(kid.getNamespaceURI())) {
+ if (localName.equals("sequence")) {
+ Node sequenceNode = kid;
+ NodeList sequenceChildren = sequenceNode.getChildNodes();
+ int sequenceLen = sequenceChildren.getLength();
+ for (int k = 0; k < sequenceLen; k++) {
+ Node sequenceKid = sequenceChildren.item(k);
+ String sequenceLocalName = sequenceKid.getLocalName();
+ if (sequenceLocalName != null &&
+ Constants.isSchemaXSD(sequenceKid.getNamespaceURI())) {
+ if (!sequenceLocalName.equals("element")) {
+ return false;
+ }
+ }
+ }
+ return true;
+ } else {
return false;
- }
}
- }
- return true;
}
- else {
- return false;
- }
- }
}
}
// allows void type
@@ -252,19 +254,17 @@
if (simpleContent != null) {
children = simpleContent.getChildNodes();
+ int len = children.getLength();
for (int j = 0;
- (j < children.getLength()) && (extension == null);
+ (j < len) && (extension == null);
j++) {
- QName extensionOrRestrictionKind =
- Utils.getNodeQName(children.item(j));
-
- if ((extensionOrRestrictionKind != null)
- && (extensionOrRestrictionKind.getLocalPart().equals(
- "extension") || extensionOrRestrictionKind.getLocalPart().equals(
- "restriction"))
- && Constants.isSchemaXSD(
- extensionOrRestrictionKind.getNamespaceURI())) {
+ Node kid = children.item(j);
+ String localName = kid.getLocalName();
+ if ((localName != null)
+ && (localName.equals("extension") || localName.equals("restriction"))
+ && Constants.isSchemaXSD(kid.getNamespaceURI())) {
+
// get the type of the extension/restriction from the "base" attribute
QName extendsOrRestrictsType =
Utils.getTypeQName(children.item(j),
@@ -290,24 +290,20 @@
children = node.getChildNodes();
Vector v = new Vector();
-
- for (int j = 0; j < children.getLength(); j++) {
- QName subNodeKind = Utils.getNodeQName(children.item(j));
-
- if ((subNodeKind != null)
- && Constants.isSchemaXSD(
- subNodeKind.getNamespaceURI())) {
- if (subNodeKind.getLocalPart().equals("sequence")) {
- v.addAll(processSequenceNode(children.item(j),
- symbolTable));
- } else if (subNodeKind.getLocalPart().equals("all")) {
- v.addAll(processAllNode(children.item(j), symbolTable));
- } else if (subNodeKind.getLocalPart().equals("choice")) {
- v.addAll(processChoiceNode(children.item(j),
- symbolTable));
- } else if (subNodeKind.getLocalPart().equals("group")) {
- v.addAll(processGroupNode(children.item(j),
- symbolTable));
+ int len = children.getLength();
+ for (int j = 0; j < len; j++) {
+ Node kid = children.item(j);
+ String localName = kid.getLocalName();
+ if (localName != null &&
+ Constants.isSchemaXSD(kid.getNamespaceURI())) {
+ if (localName.equals("sequence")) {
+ v.addAll(processSequenceNode(kid, symbolTable));
+ } else if (localName.equals("all")) {
+ v.addAll(processAllNode(kid, symbolTable));
+ } else if (localName.equals("choice")) {
+ v.addAll(processChoiceNode(kid, symbolTable));
+ } else if (localName.equals("group")) {
+ v.addAll(processGroupNode(kid, symbolTable));
}
}
}
@@ -316,19 +312,18 @@
} else if (isXSDNode(node, "group")) {
NodeList children = node.getChildNodes();
Vector v = new Vector();
- for (int j = 0; j < children.getLength(); j++) {
- QName subNodeKind = Utils.getNodeQName(children.item(j));
- if ((subNodeKind != null)
- && Constants.isSchemaXSD(
- subNodeKind.getNamespaceURI())) {
- if (subNodeKind.getLocalPart().equals("sequence")) {
- v.addAll(processSequenceNode(children.item(j),
- symbolTable));
- } else if (subNodeKind.getLocalPart().equals("all")) {
- v.addAll(processAllNode(children.item(j), symbolTable));
- } else if (subNodeKind.getLocalPart().equals("choice")) {
- v.addAll(processChoiceNode(children.item(j),
- symbolTable));
+ int len = children.getLength();
+ for (int j = 0; j < len; j++) {
+ Node kid = children.item(j);
+ String localName = kid.getLocalName();
+ if (localName != null &&
+ Constants.isSchemaXSD(kid.getNamespaceURI())) {
+ if (localName.equals("sequence")) {
+ v.addAll(processSequenceNode(kid, symbolTable));
+ } else if (localName.equals("all")) {
+ v.addAll(processAllNode(kid, symbolTable));
+ } else if (localName.equals("choice")) {
+ v.addAll(processChoiceNode(kid, symbolTable));
}
}
}
@@ -381,23 +376,22 @@
Vector v = new Vector();
NodeList children = choiceNode.getChildNodes();
-
- for (int j = 0; j < children.getLength(); j++) {
- QName subNodeKind = Utils.getNodeQName(children.item(j));
-
- if ((subNodeKind != null)
- && Constants.isSchemaXSD(subNodeKind.getNamespaceURI())) {
- if (subNodeKind.getLocalPart().equals("choice")) {
- v.addAll(processChoiceNode(children.item(j), symbolTable));
- } else if (subNodeKind.getLocalPart().equals("sequence")) {
- v.addAll(processSequenceNode(children.item(j),
- symbolTable));
- } else if (subNodeKind.getLocalPart().equals("group")) {
- v.addAll(processGroupNode(children.item(j), symbolTable));
- } else if (subNodeKind.getLocalPart().equals("element")) {
- ElementDecl elem = processChildElementNode(children.item(j),
- symbolTable);
-
+ int len = children.getLength();
+ for (int j = 0; j < len; j++) {
+ Node kid = children.item(j);
+ String localName = kid.getLocalName();
+ if (localName != null &&
+ Constants.isSchemaXSD(kid.getNamespaceURI())) {
+ if (localName.equals("choice")) {
+ v.addAll(processChoiceNode(kid, symbolTable));
+ } else if (localName.equals("sequence")) {
+ v.addAll(processSequenceNode(kid, symbolTable));
+ } else if (localName.equals("group")) {
+ v.addAll(processGroupNode(kid, symbolTable));
+ } else if (localName.equals("element")) {
+ ElementDecl elem = processChildElementNode(kid,
+ symbolTable);
+
if (elem != null) {
v.add(elem);
}
@@ -527,21 +521,21 @@
Vector v = new Vector();
NodeList children = sequenceNode.getChildNodes();
+ int len = children.getLength();
+ for (int j = 0; j < len; j++) {
+ Node kid = children.item(j);
+ String localName = kid.getLocalName();
- for (int j = 0; j < children.getLength(); j++) {
- QName subNodeKind = Utils.getNodeQName(children.item(j));
-
- if ((subNodeKind != null)
- && Constants.isSchemaXSD(subNodeKind.getNamespaceURI())) {
- if (subNodeKind.getLocalPart().equals("choice")) {
- v.addAll(processChoiceNode(children.item(j), symbolTable));
- } else if (subNodeKind.getLocalPart().equals("sequence")) {
- v.addAll(processSequenceNode(children.item(j),
- symbolTable));
- } else if (subNodeKind.getLocalPart().equals("group")) {
- v.addAll(processGroupNode(children.item(j), symbolTable));
- } else if (subNodeKind.getLocalPart().equals("any")) {
-
+ if (localName != null &&
+ Constants.isSchemaXSD(kid.getNamespaceURI())) {
+ if (localName.equals("choice")) {
+ v.addAll(processChoiceNode(kid, symbolTable));
+ } else if (localName.equals("sequence")) {
+ v.addAll(processSequenceNode(kid, symbolTable));
+ } else if (localName.equals("group")) {
+ v.addAll(processGroupNode(kid, symbolTable));
+ } else if (localName.equals("any")) {
+
// Represent this as an element named any of type any type.
// This will cause it to be serialized with the element
// serializer.
@@ -552,10 +546,10 @@
elem.setAnyElement(true);
v.add(elem);
- } else if (subNodeKind.getLocalPart().equals("element")) {
- ElementDecl elem = processChildElementNode(children.item(j),
- symbolTable);
-
+ } else if (localName.equals("element")) {
+ ElementDecl elem = processChildElementNode(kid,
+ symbolTable);
+
if (elem != null) {
v.add(elem);
}
@@ -581,18 +575,18 @@
Vector v = new Vector();
if (groupNode.getAttributes().getNamedItem("ref") == null) {
NodeList children = groupNode.getChildNodes();
- for (int j = 0; j < children.getLength(); j++) {
- QName subNodeKind = Utils.getNodeQName(children.item(j));
-
- if ((subNodeKind != null)
- && Constants.isSchemaXSD(subNodeKind.getNamespaceURI())) {
- if (subNodeKind.getLocalPart().equals("choice")) {
- v.addAll(processChoiceNode(children.item(j), symbolTable));
- } else if (subNodeKind.getLocalPart().equals("sequence")) {
- v.addAll(processSequenceNode(children.item(j),
- symbolTable));
- } else if (subNodeKind.getLocalPart().equals("all")) {
- v.addAll(processAllNode(children.item(j), symbolTable));
+ int len = children.getLength();
+ for (int j = 0; j < len; j++) {
+ Node kid = children.item(j);
+ String localName = kid.getLocalName();
+ if (localName != null &&
+ Constants.isSchemaXSD(kid.getNamespaceURI())) {
+ if (localName.equals("choice")) {
+ v.addAll(processChoiceNode(kid, symbolTable));
+ } else if (localName.equals("sequence")) {
+ v.addAll(processSequenceNode(kid, symbolTable));
+ } else if (localName.equals("all")) {
+ v.addAll(processAllNode(kid, symbolTable));
}
}
}
@@ -850,14 +844,15 @@
* @return true if the node is matches the name in the schema namespace.
*/
private static boolean isXSDNode(Node node, String schemaLocalName) {
-
- if ((node != null) && Constants.isSchemaXSD(node.getNamespaceURI())) {
- String localName = node.getLocalName();
-
- return ((localName != null) && localName.equals(schemaLocalName));
+ if (node == null) {
+ return false;
}
-
- return false;
+ String localName = node.getLocalName();
+ if (localName == null) {
+ return false;
+ }
+ return (localName.equals(schemaLocalName) &&
+ Constants.isSchemaXSD(node.getNamespaceURI()));
}
/**
@@ -1722,8 +1717,8 @@
// If the node kind is an element, dive into it.
if (isXSDNode(node, "element")) {
NodeList children = node.getChildNodes();
-
- for (int j = 0; j < children.getLength(); j++) {
+ int len = children.getLength();
+ for (int j = 0; j < len; j++) {
Node kid = children.item(j);
if (isXSDNode(kid, "complexType")) {
@@ -1741,8 +1736,8 @@
// and extension elements if this is a derived type. Skip over these.
NodeList children = node.getChildNodes();
Node content = null;
-
- for (int j = 0; j < children.getLength(); j++) {
+ int len = children.getLength();
+ for (int j = 0; j < len; j++) {
Node kid = children.item(j);
if (isXSDNode(kid, "complexContent")
@@ -1756,8 +1751,8 @@
// Check for extensions or restrictions
if (content != null) {
children = content.getChildNodes();
-
- for (int j = 0; j < children.getLength(); j++) {
+ len = children.getLength();
+ for (int j = 0; j < len; j++) {
Node kid = children.item(j);
if (isXSDNode(kid, "extension")
@@ -1771,27 +1766,25 @@
// examine children of the node for <attribute> elements
children = node.getChildNodes();
-
- for (int i = 0; i < children.getLength(); i++) {
+ len = children.getLength();
+ for (int i = 0; i < len; i++) {
Node child = children.item(i);
- if (!isXSDNode(child, "attribute") &&
- !isXSDNode(child, "anyAttribute") &&
- !isXSDNode(child, "attributeGroup")) {
- continue;
- }
-
- // we have an attribute or attributeGroup node
- if (v == null) {
- v = new Vector();
- }
-
if (isXSDNode(child, "attributeGroup")) {
+ if (v == null) {
+ v = new Vector();
+ }
addAttributeGroupToVector(v, child, symbolTable);
} else if (isXSDNode(child, "anyAttribute")) {
// do nothing right now
- } else {
+ if (v == null) {
+ v = new Vector();
+ }
+ } else if (isXSDNode(child, "attribute")) {
// we have an attribute
+ if (v == null) {
+ v = new Vector();
+ }
addAttributeToVector(v, child, symbolTable);
}
}
1.111 +9 -7 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.110
retrieving revision 1.111
diff -u -r1.110 -r1.111
--- SymbolTable.java 18 Nov 2004 15:26:16 -0000 1.110
+++ SymbolTable.java 9 Dec 2004 22:29:59 -0000 1.111
@@ -89,6 +89,9 @@
*/
public class SymbolTable {
+ // used to cache dervied types
+ protected HashMap derivedTypes = new HashMap();
+
// Should the contents of imported files be added to the symbol table?
/** Field addImports */
@@ -932,12 +935,11 @@
}
// Get the kind of node (complexType, wsdl:part, etc.)
- QName nodeKind = Utils.getNodeQName(node);
+ String localPart = node.getLocalName();
- if (nodeKind != null) {
- String localPart = nodeKind.getLocalPart();
+ if (localPart != null) {
boolean isXSD =
- Constants.isSchemaXSD(nodeKind.getNamespaceURI());
+ Constants.isSchemaXSD(node.getNamespaceURI());
if (((isXSD && localPart.equals("complexType"))
|| localPart.equals("simpleType"))) {
@@ -1039,7 +1041,7 @@
symbolTablePut(type);
}
} else if (localPart.equals("part")
- && Constants.isWSDL(nodeKind.getNamespaceURI())) {
+ && Constants.isWSDL(node.getNamespaceURI())) {
// This is a wsdl part. Create an TypeEntry representing the reference
createTypeFromRef(node);
@@ -1077,8 +1079,8 @@
}
if (level == ABOVE_SCHEMA_LEVEL) {
- if ((nodeKind != null)
- && nodeKind.getLocalPart().equals("schema")) {
+ if ((localPart != null)
+ && localPart.equals("schema")) {
level = SCHEMA_LEVEL;
}
} else {
1.42 +25 -17 ws-axis/java/src/org/apache/axis/wsdl/symbolTable/Utils.java
Index: Utils.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/Utils.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- Utils.java 22 Aug 2004 03:06:59 -0000 1.41
+++ Utils.java 9 Dec 2004 22:30:00 -0000 1.42
@@ -225,17 +225,17 @@
Node search = node.getParentNode();
while (search != null) {
- QName kind = getNodeQName(search);
+ String ln = search.getLocalName();
- if (kind.getLocalPart().equals("schema")) {
+ if (ln.equals("schema")) {
search = null;
- } else if (kind.getLocalPart().equals("element")
- || kind.getLocalPart().equals("attribute")) {
+ } else if (ln.equals("element")
+ || ln.equals("attribute")) {
localName = SymbolTable.ANON_TOKEN
+ getNodeNameQName(search).getLocalPart();
search = null;
- } else if (kind.getLocalPart().equals("complexType")
- || kind.getLocalPart().equals("simpleType")) {
+ } else if (ln.equals("complexType")
+ || ln.equals("simpleType")) {
localName = getNodeNameQName(search).getLocalPart()
+ SymbolTable.ANON_TOKEN + localName;
search = null;
@@ -296,13 +296,13 @@
// If not successful, try using the ref attribute.
if (qName == null) {
- QName nodeKind = getNodeQName(node);
+ String localName = node.getLocalName();
// bug 23145: support attributeGroup (Brook Richan)
// a ref can be for an element or attributeGroup
- if ((nodeKind != null)
- && !(nodeKind.getLocalPart().equals("attributeGroup") ||
- nodeKind.getLocalPart().equals("group"))) {
+ if ((localName != null)
+ && !(localName.equals("attributeGroup") ||
+ localName.equals("group"))) {
forElement.value = true;
}
@@ -440,12 +440,12 @@
}
// Try returning anyType
- QName nodeName = getNodeQName(node);
-
- if ((nodeName != null)
- && Constants.isSchemaXSD(nodeName.getNamespaceURI())
- && (nodeName.getLocalPart().equals("element")
- || nodeName.getLocalPart().equals("attribute"))) {
+ String localName = node.getLocalName();
+
+ if ((localName != null)
+ && Constants.isSchemaXSD(node.getNamespaceURI())
+ && (localName.equals("element") ||
+ localName.equals("attribute"))) {
return Constants.XSD_ANYTYPE;
}
}
@@ -508,7 +508,15 @@
public static HashSet getDerivedTypes(TypeEntry type,
SymbolTable symbolTable) {
- HashSet types = new HashSet();
+ HashSet types = (HashSet)symbolTable.derivedTypes.get(type);
+
+ if (types != null) {
+ return types;
+ }
+
+ types = new HashSet();
+
+ symbolTable.derivedTypes.put(type, types);
if ((type != null) && (type.getNode() != null)) {
getDerivedTypes(type, types, symbolTable);