gdaniels 02/03/19 12:15:29 Modified: java/src/org/apache/axis/utils resources.properties java/src/org/apache/axis/wsdl/toJava JavaComplexTypeWriter.java JavaFaultWriter.java JavaImplWriter.java JavaSkelWriter.java JavaStubWriter.java JavaTestCaseWriter.java JavaTypeWriter.java JavaWriterFactory.java Parameter.java SchemaUtils.java SymbolTable.java Utils.java java/test/wsdl Wsdl2javaTestSuite.xml java/test/wsdl/literal SalesRankNPrice_ServiceTestCase.java Added: java/src/org/apache/axis/wsdl/toJava ElementDecl.java Log: Merge changes from Beta1 over to HEAD. Revision Changes Path 1.76 +3 -0 xml-axis/java/src/org/apache/axis/utils/resources.properties Index: resources.properties =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/resources.properties,v retrieving revision 1.75 retrieving revision 1.76 diff -u -r1.75 -r1.76 --- resources.properties 19 Mar 2002 17:48:29 -0000 1.75 +++ resources.properties 19 Mar 2002 20:15:28 -0000 1.76 @@ -772,3 +772,6 @@ # NOTE: in mustSpecifyReturnType and mustSpecifyParms, do not translate "addParameter()" and "setReturnType()" mustSpecifyReturnType=No returnType was specified to the Call object! You must call setReturnType() if you have called addParameter(). mustSpecifyParms=No parameters specified to the Call object! You must call addParameter() for all parameters if you have called setReturnType(). +noElemOrType=Error: Message part {0} of operation {1} should have either an element or a type attribute +badTypeNode=Error: Missing type resolution for element {2}, in WSDL message part {0} of operation {1} + 1.24 +35 -32 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaComplexTypeWriter.java Index: JavaComplexTypeWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaComplexTypeWriter.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- JavaComplexTypeWriter.java 17 Mar 2002 16:25:08 -0000 1.23 +++ JavaComplexTypeWriter.java 19 Mar 2002 20:15:28 -0000 1.24 @@ -111,9 +111,10 @@ // We are only interested in the java names of the types, so create a names list Vector names = new Vector(); - for (int i = 0; i < elements.size(); i += 2) { - TypeEntry type = (TypeEntry) elements.get(i); - String elemName = (String) elements.get(i + 1); + for (int i = 0; i < elements.size(); i++) { + ElementDecl elem = (ElementDecl)elements.get(i); + TypeEntry type = elem.getType(); + String elemName = elem.getName().getLocalPart(); String javaName = Utils.xmlNameToJava(elemName); if (!javaName.equals(elemName)) { // If we did some mangling, make sure we'll write out the XML @@ -121,7 +122,7 @@ if (elementMappings == null) elementMappings = new HashMap(); - elementMappings.put(javaName, new QName("", elemName)); + elementMappings.put(javaName, elem.getName()); } names.add(type.getName()); names.add(javaName); @@ -179,7 +180,8 @@ } pw.println(); - for (int i = 0; i < names.size(); i += 2) { + int j = 0; + for (int i = 0; i < names.size(); i += 2, j++) { String typeName = (String) names.get(i); String name = (String) names.get(i + 1); String capName = Utils.capitalizeFirstChar(name); @@ -206,33 +208,34 @@ // like the reasonable approach to take for collection types. // (It may be more efficient to handle this with an ArrayList...but // for the initial support it was easier to use an actual array.) - if (i < elements.size() && - ((TypeEntry) elements.elementAt(i)).getQName().getLocalPart().indexOf("[") > 0) { - - String compName = typeName.substring(0, typeName.lastIndexOf("[")); - - int bracketIndex = typeName.indexOf("["); - String newingName = typeName.substring(0, bracketIndex + 1); - String newingSuffix = typeName.substring(bracketIndex + 1); - - pw.println(" public " + compName + " " + get + capName + "(int i) {"); - pw.println(" return " + name + "[i];"); - pw.println(" }"); - pw.println(); - pw.println(" public void set" + capName + "(int i, " + compName + " value) {"); - pw.println(" if (this." + name + " == null ||"); - pw.println(" this." + name + ".length <= i) {"); - pw.println(" " + typeName + " a = new " + - newingName + "i + 1" + newingSuffix + ";"); - pw.println(" if (this." + name + " != null) {"); - pw.println(" for(int j = 0; j < this." + name + ".length; j++)"); - pw.println(" a[j] = this." + name + "[j];"); - pw.println(" }"); - pw.println(" this." + name + " = a;"); - pw.println(" }"); - pw.println(" this." + name + "[i] = value;"); - pw.println(" }"); - pw.println(); + if (j < elements.size()) { + ElementDecl elem = (ElementDecl)elements.get(j); + if (elem.getType().getQName().getLocalPart().indexOf("[") > 0) { + String compName = typeName.substring(0, typeName.lastIndexOf("[")); + + int bracketIndex = typeName.indexOf("["); + String newingName = typeName.substring(0, bracketIndex + 1); + String newingSuffix = typeName.substring(bracketIndex + 1); + + pw.println(" public " + compName + " " + get + capName + "(int i) {"); + pw.println(" return " + name + "[i];"); + pw.println(" }"); + pw.println(); + pw.println(" public void set" + capName + "(int i, " + compName + " value) {"); + pw.println(" if (this." + name + " == null ||"); + pw.println(" this." + name + ".length <= i) {"); + pw.println(" " + typeName + " a = new " + + newingName + "i + 1" + newingSuffix + ";"); + pw.println(" if (this." + name + " != null) {"); + pw.println(" for(int j = 0; j < this." + name + ".length; j++)"); + pw.println(" a[j] = this." + name + "[j];"); + pw.println(" }"); + pw.println(" this." + name + " = a;"); + pw.println(" }"); + pw.println(" this." + name + "[i] = value;"); + pw.println(" }"); + pw.println(); + } } } 1.6 +13 -9 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaFaultWriter.java Index: JavaFaultWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaFaultWriter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JavaFaultWriter.java 12 Feb 2002 18:33:56 -0000 1.5 +++ JavaFaultWriter.java 19 Mar 2002 20:15:28 -0000 1.6 @@ -90,16 +90,17 @@ // XXX Have to get use information (literal/encoded) for fault from // XXX BindingEntry, which we don't have the QName for - symbolTable.partStrings(params, + symbolTable.getParametersFromParts(params, fault.getMessage().getOrderedParts(null), false, fault.getName(), "unknown"); // Write data members of the exception and getter methods for them - for (int i = 0; i < params.size(); i += 2) { - String type = ((TypeEntry) params.get(i)).getName(); - String variable = (String) params.get(i + 1); + for (int i = 0; i < params.size(); i++) { + Parameter param = (Parameter)params.get(i); + String type = param.getType().getName(); + String variable = param.getName(); pw.println(" public " + type + " " + variable + ";"); pw.println(" public " + type + " get" + Utils.capitalizeFirstChar(variable) + "() {"); pw.println(" return this." + variable + ";"); @@ -115,14 +116,17 @@ // contructor that initializes data if (params.size() > 0) { pw.print(" public " + className + "("); - for (int i = 0; i < params.size(); i += 2) { + for (int i = 0; i < params.size(); i++) { if (i != 0) pw.print(", "); - pw.print(((TypeEntry) params.get(i)).getName() + " " + params.get(i + 1)); + Parameter param = (Parameter)params.get(i); + String type = param.getType().getName(); + String variable = param.getName(); + pw.print(type + " " + variable); } pw.println(") {"); - for (int i = 1; i < params.size(); i += 2) { - String variable = (String) params.get(i); - + for (int i = 0; i < params.size(); i++) { + Parameter param = (Parameter)params.get(i); + String variable = param.getName(); pw.println(" this." + variable + " = " + variable + ";"); } pw.println(" }"); 1.13 +3 -3 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaImplWriter.java Index: JavaImplWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaImplWriter.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- JavaImplWriter.java 27 Feb 2002 13:41:28 -0000 1.12 +++ JavaImplWriter.java 19 Mar 2002 20:15:28 -0000 1.13 @@ -149,14 +149,14 @@ Iterator iparam = parms.list.iterator(); while (iparam.hasNext()) { Parameter param = (Parameter) iparam.next(); - String paramType = param.type.getName(); + String paramType = param.getType().getName(); // Note that similar code is in JavaTestCaseWriter. // So please check both places if changes are made. - if (param.mode == Parameter.OUT) { + if (param.getMode() == Parameter.OUT) { pw.print(" " + Utils.xmlNameToJava(param.getName()) + ".value = "); - if ( isPrimitiveType(param.type) ) { + if ( isPrimitiveType(param.getType()) ) { if ( "boolean".equals(paramType) ) { pw.print("false"); } else if ("byte".equals(paramType)) { 1.18 +2 -2 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java Index: JavaSkelWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- JavaSkelWriter.java 13 Mar 2002 19:50:58 -0000 1.17 +++ JavaSkelWriter.java 19 Mar 2002 20:15:28 -0000 1.18 @@ -208,9 +208,9 @@ } for (int j=0; j < parameters.list.size(); j++) { Parameter p = (Parameter) parameters.list.get(j); - if (p.mode == Parameter.IN) + if (p.getMode() == Parameter.IN) pw.println(" javax.xml.rpc.ParameterMode.PARAM_MODE_IN,"); - else if (p.mode == Parameter.OUT) + else if (p.getMode() == Parameter.OUT) pw.println(" javax.xml.rpc.ParameterMode.PARAM_MODE_INOUT,"); else pw.println(" javax.xml.rpc.ParameterMode.PARAM_MODE_OUT,"); 1.47 +25 -25 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java Index: JavaStubWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- JavaStubWriter.java 18 Mar 2002 22:37:34 -0000 1.46 +++ JavaStubWriter.java 19 Mar 2002 20:15:28 -0000 1.47 @@ -341,7 +341,7 @@ // Loop over parameter types for this operation for (int i=0; i < params.list.size(); i++) { Parameter p = (Parameter) params.list.get(i); - v.add(p.type); + v.add(p.getType()); } // Add the return type @@ -501,9 +501,9 @@ Parameter p = (Parameter) parms.list.get(i); // We need to use the Qname of the actual type, not the QName of the element - QName qn = p.type.getQName(); - if (p.type instanceof DefinedElement) { - Node node = symbolTable.getTypeEntry(p.type.getQName(), true).getNode(); + QName qn = p.getType().getQName(); + if (p.getType() instanceof DefinedElement) { + Node node = symbolTable.getTypeEntry(p.getType().getQName(), true).getNode(); QName qn2 = Utils.getNodeTypeRefQName(node, "type"); if (qn2 != null) { qn = qn2; @@ -518,15 +518,15 @@ pw.println(" javax.xml.rpc.namespace.QName " + qnName + " = new javax.xml.rpc.namespace.QName(\"" + paramQName.getNamespaceURI() + "\", \"" + paramQName.getLocalPart() + "\");"); - if (p.mode == Parameter.IN) { + if (p.getMode() == Parameter.IN) { pw.println(" call.addParameter(" + qnName + ", " + typeString + ", javax.xml.rpc.ParameterMode.PARAM_MODE_IN);"); } - else if (p.mode == Parameter.INOUT) { + else if (p.getMode() == Parameter.INOUT) { pw.println(" call.addParameter(" + qnName + ", " + typeString + ", javax.xml.rpc.ParameterMode.PARAM_MODE_INOUT);"); } - else { // p.mode == Parameter.OUT + else { // p.getMode() == Parameter.OUT pw.println(" call.addParameter(" + qnName + ", " + typeString + ", javax.xml.rpc.ParameterMode.PARAM_MODE_OUT);"); } @@ -596,18 +596,18 @@ Parameter p = (Parameter) parms.list.get(i); String javifiedName = Utils.xmlNameToJava(p.getName()); - if (p.mode != Parameter.OUT) { + if (p.getMode() != Parameter.OUT) { if (needComma) { pw.print(", "); } else { needComma = true; } - if (p.mode == Parameter.IN) { - pw.print(wrapPrimitiveType(p.type, javifiedName)); + if (p.getMode() == Parameter.IN) { + pw.print(wrapPrimitiveType(p.getType(), javifiedName)); } else { - pw.print(wrapPrimitiveType(p.type, javifiedName + ".value")); + pw.print(wrapPrimitiveType(p.getType(), javifiedName + ".value")); } } } @@ -627,7 +627,7 @@ int i = 0; Parameter p = (Parameter) parms.list.get(i); - while (p.mode != Parameter.INOUT) { + while (p.getMode() != Parameter.INOUT) { p = (Parameter) parms.list.get(++i); } String javifiedName = Utils.xmlNameToJava(p.getName()); @@ -641,17 +641,17 @@ // NOTE A: // It seems that it should be the responsibility of the // Call to convert the ArrayList into the proper array. - if (p.type.getName().endsWith("[]")) { + if (p.getType().getName().endsWith("[]")) { pw.println(" // REVISIT THIS!"); pw.println(" " + javifiedName - + ".value = (" + p.type.getName() + + ".value = (" + p.getType().getName() + ") org.apache.axis.utils.JavaUtils.convert(output.get(" - + qnameName + "), " + p.type.getName() + + qnameName + "), " + p.getType().getName() + ".class);"); } else { pw.println(" " + javifiedName + ".value = " - + getResponseString(p.type, + + getResponseString(p.getType(), "output.get(" + qnameName + ")")); } } @@ -687,40 +687,40 @@ String javifiedName = Utils.xmlNameToJava(p.getName()); String qnameName = Utils.getNewQName( Utils.getAxisQName(p.getQName())); - if (p.mode != Parameter.IN) { + if (p.getMode() != Parameter.IN) { if (firstInoutIsResp) { firstInoutIsResp = false; // If expecting an array, need to call convert(..) because // the runtime stores arrays in a different form (ArrayList). // (See NOTE A) - if (p.type.getName().endsWith("[]")) { + if (p.getType().getName().endsWith("[]")) { pw.println(" // REVISIT THIS!"); pw.println (" " + javifiedName - + ".value = (" + p.type.getName() + + ".value = (" + p.getType().getName() + ") org.apache.axis.utils.JavaUtils.convert(output.get(" + qnameName + "), " - + p.type.getName() + ".class);"); + + p.getType().getName() + ".class);"); } else { pw.println (" " + javifiedName + ".value = " + - getResponseString(p.type, "output.get(" + qnameName + ")")); + getResponseString(p.getType(), "output.get(" + qnameName + ")")); } } else { // If expecting an array, need to call convert(..) because // the runtime stores arrays in a different form (ArrayList). // (See NOTE A) - if (p.type.getName().endsWith("[]")) { + if (p.getType().getName().endsWith("[]")) { pw.println(" // REVISIT THIS!"); pw.println (" " + javifiedName - + ".value = (" + p.type.getName() + + ".value = (" + p.getType().getName() + ") org.apache.axis.utils.JavaUtils.convert(" + "output.get(" + qnameName + "), " - + p.type.getName() + ".class);"); + + p.getType().getName() + ".class);"); } else { pw.println (" " + javifiedName - + ".value = " + getResponseString(p.type, + + ".value = " + getResponseString(p.getType(), "output.get(" + qnameName + ")")); } } 1.18 +6 -6 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaTestCaseWriter.java Index: JavaTestCaseWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaTestCaseWriter.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- JavaTestCaseWriter.java 16 Feb 2002 23:30:49 -0000 1.17 +++ JavaTestCaseWriter.java 19 Mar 2002 20:15:28 -0000 1.18 @@ -216,17 +216,17 @@ } Parameter param = (Parameter) iparam.next(); - String paramType = param.type.getName(); + String paramType = param.getType().getName(); String suffix = ""; - if (param.mode != Parameter.IN) { - pw.print("new " + Utils.holder(param.type, symbolTable) + if (param.getMode() != Parameter.IN) { + pw.print("new " + Utils.holder(param.getType(), symbolTable) + "("); suffix = ")"; } - if (param.mode != Parameter.OUT) { - if ( isPrimitiveType(param.type) ) { + if (param.getMode() != Parameter.OUT) { + if ( isPrimitiveType(param.getType()) ) { if ( "boolean".equals(paramType) ) { pw.print("true"); } else if ("byte".equals(paramType)) { @@ -265,7 +265,7 @@ // We have some constructed type. Vector v = SchemaUtils.getEnumerationBaseAndValues( - param.type.getNode(), symbolTable); + param.getType().getNode(), symbolTable); if (v != null) { 1.6 +1 -1 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaTypeWriter.java Index: JavaTypeWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaTypeWriter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JavaTypeWriter.java 21 Feb 2002 18:51:23 -0000 1.5 +++ JavaTypeWriter.java 19 Mar 2002 20:15:28 -0000 1.6 @@ -91,7 +91,7 @@ if (!type.getName().endsWith("[]")) { // Generate the proper class for either "complex" or "enumeration" types - Vector v = SchemaUtils.getComplexElementTypesAndNames( + Vector v = SchemaUtils.getComplexElementDeclarations( node, symbolTable); if (v != null) { typeWriter = new 1.20 +11 -8 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriterFactory.java Index: JavaWriterFactory.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriterFactory.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- JavaWriterFactory.java 18 Mar 2002 22:37:34 -0000 1.19 +++ JavaWriterFactory.java 19 Mar 2002 20:15:28 -0000 1.20 @@ -189,7 +189,9 @@ // Only consider the localName after the last '>' when // generating the java name String localName = typeQName.getLocalPart(); - localName = localName.substring(localName.lastIndexOf(SymbolTable.ANON_TOKEN)+1); + localName = + localName.substring( + localName.lastIndexOf(SymbolTable.ANON_TOKEN)+1); typeQName = new QName(typeQName.getNamespaceURI(), localName); // If there is already an existing type, there will be a // collision. If there is an existing anon type, there will be a @@ -273,7 +275,8 @@ // an anonymous type, then need to change the // java name of the anonymous type to match. QName anonQName = new QName(entry.getQName().getNamespaceURI(), - SymbolTable.ANON_TOKEN + entry.getQName().getLocalPart()); + SymbolTable.ANON_TOKEN + + entry.getQName().getLocalPart()); TypeEntry anonType = symbolTable.getType(anonQName); if (anonType != null) { anonType.setName(entry.getName()); @@ -497,11 +500,11 @@ } String javifiedName = Utils.xmlNameToJava(p.getName()); - if (p.mode == Parameter.IN) { - signature = signature + p.type.getName() + " " + javifiedName; + if (p.getMode() == Parameter.IN) { + signature = signature + p.getType().getName() + " " + javifiedName; } else { - signature = signature + Utils.holder(p.type, symbolTable) + " " + signature = signature + Utils.holder(p.getType(), symbolTable) + " " + javifiedName; } } @@ -537,15 +540,15 @@ // If the given parameter is an inout or out parameter, then // set a HOLDER_IS_NEEDED flag using the dynamicVar design. - if (p.mode != Parameter.IN) { - p.type.setDynamicVar( + if (p.getMode() != Parameter.IN) { + p.getType().setDynamicVar( JavaTypeWriter.HOLDER_IS_NEEDED, new Boolean(true)); // If the type is a DefinedElement, need to // set HOLDER_IS_NEEDED on the anonymous type. QName anonQName = SchemaUtils. - getElementAnonQName(p.type.getNode()); + getElementAnonQName(p.getType().getNode()); if (anonQName != null) { TypeEntry anonType = symbolTable.getType(anonQName); 1.4 +35 -8 xml-axis/java/src/org/apache/axis/wsdl/toJava/Parameter.java Index: Parameter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/Parameter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Parameter.java 27 Feb 2002 13:41:28 -0000 1.3 +++ Parameter.java 19 Mar 2002 20:15:28 -0000 1.4 @@ -67,9 +67,15 @@ public static final byte OUT = 2; public static final byte INOUT = 3; - private QName name; - public TypeEntry type; - public byte mode = IN; + // The QName of the element associated with this param. Defaults to + // null, which means it'll be new QName("", name) + private QName qname; + + // The part name of this parameter, just a string. + private String name; + + private TypeEntry type; + private byte mode = IN; public String toString() { return "(" + type + ", " + getName() + ", " @@ -77,18 +83,39 @@ } // toString public QName getQName() { - return name; + return qname; } public String getName() { - return name.getLocalPart(); + if (name == null && qname != null) { + return qname.getLocalPart(); + } + return name; } public void setName(String name) { - this.name = new QName("", name); + this.name = name; + if (qname == null) + this.qname = new QName("", name); } - public void setQName(QName name) { - this.name = name; + public void setQName(QName qname) { + this.qname = qname; + } + + public TypeEntry getType() { + return type; + } + + public void setType(TypeEntry type) { + this.type = type; + } + + public byte getMode() { + return mode; + } + + public void setMode(byte mode) { + this.mode = mode; } } // class Parameter 1.15 +46 -26 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.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- SchemaUtils.java 13 Mar 2002 15:19:27 -0000 1.14 +++ SchemaUtils.java 19 Mar 2002 20:15:28 -0000 1.15 @@ -83,13 +83,13 @@ /** * If the specified node represents a supported JAX-RPC complexType/element, - * a Vector is returned which contains the child element types and - * child element names. The even indices are the element types (TypeEntry) and - * the odd indices are the corresponding names (Strings). + * a Vector is returned which contains ElementDecls for the child + * elements. + * * If the specified node is not a supported JAX-RPC complexType/element * null is returned. */ - public static Vector getComplexElementTypesAndNames(Node node, SymbolTable symbolTable) { + public static Vector getComplexElementDeclarations(Node node, SymbolTable symbolTable) { if (node == null) { return null; } @@ -156,17 +156,21 @@ QName extendsType = Utils.getNodeTypeRefQName(children.item(j), "base"); - Vector v = new Vector(); - v.add(symbolTable.getTypeEntry(extendsType, false)); - v.add("value"); // A fixed, implementation specific name - // done + // Return an element declaration with a fixed name + // ("value") and the correct type. + + Vector v = new Vector(); + ElementDecl elem = new ElementDecl(); + elem.setType(symbolTable.getTypeEntry(extendsType, false)); + elem.setName(new javax.xml.rpc.namespace.QName("", "value")); + v.add(elem); return v; } } - } + if (extension != null) { node = extension; // Skip over complexContent and extension } @@ -188,8 +192,8 @@ // didn't find anything return new Vector(); } - if (groupNode != null) { + if (groupNode != null) { // Process each of the choice or element nodes under the sequence/all node Vector v = new Vector(); NodeList elements = groupNode.getChildNodes(); @@ -198,7 +202,11 @@ if (elementKind != null && Constants.isSchemaXSD(elementKind.getNamespaceURI())) { if ( elementKind.getLocalPart().equals("element")) { - v.addAll(processChildElementNode(elements.item(i), symbolTable)); + ElementDecl elem = + processChildElementNode(elements.item(i), + symbolTable); + if (elem != null) + v.add(elem); } else if (elementKind.getLocalPart().equals("choice")) { Vector choiceElems = processChoiceNode(elements.item(i), symbolTable); v.addAll(choiceElems); @@ -215,7 +223,8 @@ * Invoked by getComplexElementTypesAndNames to get the child element types * and child element names underneath a Choice Node */ - private static Vector processChoiceNode(Node choiceNode, SymbolTable symbolTable) { + private static Vector processChoiceNode(Node choiceNode, + SymbolTable symbolTable) { Vector v = new Vector(); NodeList children = choiceNode.getChildNodes(); for (int j = 0; j < children.getLength(); j++) { @@ -229,7 +238,11 @@ } else if (subNodeKind.getLocalPart().equals("group")) { v.addAll(processGroupNode(children.item(j), symbolTable)); } else if (subNodeKind.getLocalPart().equals("element")) { - v.addAll(processChildElementNode(children.item(j), symbolTable)); + ElementDecl elem = + processChildElementNode(children.item(j), + symbolTable); + if (elem != null) + v.add(elem); } } } @@ -240,7 +253,8 @@ * Invoked by getComplexElementTypesAndNames to get the child element types * and child element names underneath a Sequence Node */ - private static Vector processSequenceNode(Node sequenceNode, SymbolTable symbolTable) { + private static Vector processSequenceNode(Node sequenceNode, + SymbolTable symbolTable) { Vector v = new Vector(); NodeList children = sequenceNode.getChildNodes(); for (int j = 0; j < children.getLength(); j++) { @@ -254,7 +268,11 @@ } else if (subNodeKind.getLocalPart().equals("group")) { v.addAll(processGroupNode(children.item(j), symbolTable)); } else if (subNodeKind.getLocalPart().equals("element")) { - v.addAll(processChildElementNode(children.item(j), symbolTable)); + ElementDecl elem = + processChildElementNode(children.item(j), + symbolTable); + if (elem != null) + v.add(elem); } } } @@ -298,7 +316,11 @@ if (subNodeKind != null && Constants.isSchemaXSD(subNodeKind.getNamespaceURI())) { if (subNodeKind.getLocalPart().equals("element")) { - v.addAll(processChildElementNode(children.item(j), symbolTable)); + ElementDecl elem = + processChildElementNode(children.item(j), + symbolTable); + if (elem != null) + v.add(elem); } } } @@ -311,14 +333,11 @@ * and child element name for a child element node. * * If the specified node represents a supported JAX-RPC child element, - * a Vector is returned which contains the child element type and - * child element name. The 0th index is the element types (TypeEntry) and - * the 1st index is the corresponding name (Strings). + * we return an ElementDecl containing the child element name and type. */ - private static Vector processChildElementNode(Node elementNode, SymbolTable symbolTable) { - Vector v = new Vector(); + private static ElementDecl processChildElementNode(Node elementNode, + SymbolTable symbolTable) { // Get the name and type qnames. - // The name of the element is the local part of the name's qname. // The type qname is used to locate the TypeEntry, which is then // used to retrieve the proper java name of the type. QName nodeName = Utils.getNodeNameQName(elementNode); @@ -329,12 +348,13 @@ forElement.value = false; } - TypeEntry type = (TypeEntry) symbolTable.getTypeEntry(nodeType, forElement.value); + TypeEntry type = (TypeEntry)symbolTable.getTypeEntry(nodeType, + forElement.value); if (type != null) { - v.add(type); - v.add(nodeName.getLocalPart()); + return new ElementDecl(type, Utils.getAxisQName(nodeName)); } - return v; + + return null; } /** 1.46 +125 -76 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.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- SymbolTable.java 18 Mar 2002 22:37:34 -0000 1.45 +++ SymbolTable.java 19 Mar 2002 20:15:29 -0000 1.46 @@ -866,8 +866,7 @@ BindingEntry bindingEntry) throws IOException { Parameters parameters = new Parameters(); - // The input and output Vectors, when filled in, will be of the form: - // {<parmType0>, <parmName0>, <parmType1>, <parmName1>, ..., <parmTypeN>, <parmNameN>} + // The input and output Vectors of Parameters Vector inputs = new Vector(); Vector outputs = new Vector(); @@ -903,17 +902,17 @@ // Collect all the input parameters Input input = operation.getInput(); if (input != null) { - partStrings(inputs, - input.getMessage().getOrderedParts(null), - literalInput, operation.getName(), bindingName); + getParametersFromParts(inputs, + input.getMessage().getOrderedParts(null), + literalInput, operation.getName(), bindingName); } // Collect all the output parameters Output output = operation.getOutput(); if (output != null) { - partStrings(outputs, - output.getMessage().getOrderedParts(null), - literalOutput, operation.getName(), bindingName); + getParametersFromParts(outputs, + output.getMessage().getOrderedParts(null), + literalOutput, operation.getName(), bindingName); } if (parameterOrder != null) { @@ -928,11 +927,11 @@ // index in the outputs Vector of the given name, -1 if it doesn't exist. int outdex = getPartIndex(name, outputs); - if (index > 0) { + if (index >= 0) { // The mode of this parameter is either in or inout addInishParm(inputs, outputs, index, outdex, parameters, true); } - else if (outdex > 0) { + else if (outdex >= 0) { addOutParm(outputs, outdex, parameters, true); } else { @@ -941,32 +940,34 @@ } } - // Get the mode info about those parts that aren't in the parameterOrder list. - // Since they're not in the parameterOrder list, the order is, first all in (and - // inout) parameters, then all out parameters, in the order they appear in the - // messages. - for (int i = 1; i < inputs.size(); i += 2) { - int outdex = getPartIndex((String) inputs.get(i), outputs); + // Get the mode info about those parts that aren't in the + // parameterOrder list. Since they're not in the parameterOrder list, + // the order is, first all in (and inout) parameters, then all out + // parameters, in the order they appear in the messages. + for (int i = 0; i < inputs.size(); i++) { + Parameter p = (Parameter)inputs.get(i); + int outdex = getPartIndex(p.getName(), outputs); addInishParm(inputs, outputs, i, outdex, parameters, false); } - // Now that the remaining in and inout parameters are collected, determine the status of - // outputs. If there is only 1, then it is the return value. If there are more than 1, - // then they are out parameters. - if (outputs.size() == 2) { - parameters.returnType = (TypeEntry) outputs.get(0); + // Now that the remaining in and inout parameters are collected, + // determine the status of outputs. If there is only 1, then it + // is the return value. If there are more than 1, then they are + // out parameters. + if (outputs.size() == 1) { + Parameter returnParam = (Parameter)outputs.get(0); + parameters.returnType = returnParam.getType(); if (parameters.returnType instanceof DefinedElement) { parameters.returnName = Utils.getAxisQName( ((DefinedElement)parameters.returnType).getQName()); } else { parameters.returnName = - new javax.xml.rpc.namespace.QName(null, - (String)outputs.get(1)); + Utils.getAxisQName(returnParam.getQName()); } ++parameters.outputs; } else { - for (int i = 1; i < outputs.size(); i += 2) { + for (int i = 0; i < outputs.size(); i++) { addOutParm(outputs, i, parameters, false); } } @@ -990,8 +991,8 @@ * Return the index of the given name in the given Vector, -1 if it doesn't exist. */ private int getPartIndex(String name, Vector v) { - for (int i = 1; i < v.size(); i += 2) { - if (name.equals(v.get(i))) { + for (int i = 0; i < v.size(); i++) { + if (name.equals(((Parameter)v.get(i)).getName())) { return i; } } @@ -1001,71 +1002,84 @@ /** * Add an in or inout parameter to the parameters object. */ - private void addInishParm(Vector inputs, Vector outputs, int index, int outdex, Parameters parameters, boolean trimInput) { - Parameter p = new Parameter(); - p.type = (TypeEntry) inputs.get(index - 1); + private void addInishParm(Vector inputs, + Vector outputs, + int index, + int outdex, + Parameters parameters, + boolean trimInput) { + Parameter p = (Parameter)inputs.get(index); // If this is an element, we want the XML to reflect the element name // not the part name. - if (p.type instanceof DefinedElement) { - DefinedElement de = (DefinedElement)p.type; + if (p.getType() instanceof DefinedElement) { + DefinedElement de = (DefinedElement)p.getType(); p.setQName(de.getQName()); - } else { - p.setName((String) inputs.get(index)); } // Should we remove the given parameter type/name entries from the Vector? if (trimInput) { inputs.remove(index); - inputs.remove(index - 1); } // At this point we know the name and type of the parameter, and that it's at least an // in parameter. Now check to see whether it's also in the outputs Vector. If it is, // then it's an inout parameter. - if (outdex > 0 && p.type.equals(outputs.get(outdex - 1))) { - outputs.remove(outdex); - outputs.remove(outdex - 1); - p.mode = Parameter.INOUT; - ++parameters.inouts; - } - else { + if (outdex >= 0) { + Parameter outParam = (Parameter)outputs.get(outdex); + if (p.getType().equals(outParam.getType())) { + outputs.remove(outdex); + p.setMode(Parameter.INOUT); + ++parameters.inouts; + } else { + // If we're here, we have both an input and an output + // part with the same name but different types.... guess + // it's not really an inout.... + ++parameters.inputs; // Is this OK?? + } + } else { ++parameters.inputs; } + parameters.list.add(p); } // addInishParm /** * Add an output parameter to the parameters object. */ - private void addOutParm(Vector outputs, int outdex, Parameters parameters, boolean trim) { - Parameter p = new Parameter(); - p.type = (TypeEntry) outputs.get(outdex - 1); + private void addOutParm(Vector outputs, + int outdex, + Parameters parameters, + boolean trim) { + Parameter p = (Parameter)outputs.get(outdex); - if (p.type instanceof DefinedElement) { - DefinedElement de = (DefinedElement)p.type; + if (p.getType() instanceof DefinedElement) { + DefinedElement de = (DefinedElement)p.getType(); p.setQName(de.getQName()); - } else { - p.setName((String) outputs.get(outdex)); } if (trim) { outputs.remove(outdex); - outputs.remove(outdex - 1); } - p.mode = Parameter.OUT; + + p.setMode(Parameter.OUT); ++parameters.outputs; parameters.list.add(p); } // addOutParm /** - * This method returns a vector containing the Java types (even indices) and - * names (odd indices) of the parts. + * This method returns a vector containing Parameters which represent + * each Part (shouldn't we call these "Parts" or something?) */ - protected void partStrings(Vector v, Collection parts, boolean literal, String opName, String bindingName) + protected void getParametersFromParts(Vector v, + Collection parts, + boolean literal, + String opName, + String bindingName) throws IOException { Iterator i = parts.iterator(); while (i.hasNext()) { + Parameter param = new Parameter(); Part part = (Part) i.next(); QName elementName = part.getElementName(); QName typeName = part.getTypeName(); @@ -1076,27 +1090,32 @@ wrapped = true; if (!literal || !wrapped) { - // not doing literal use, add this type or element name + // We're either RPC or literal + not wrapped. + + param.setName(partName); + + // Add this type or element name if (typeName != null) { - v.add(getType(typeName)); - v.add(partName); + param.setType(getType(typeName)); } else if (elementName != null) { // Just an FYI: The WSDL spec says that for use=encoded // that parts reference an abstract type using the type attr // but we kinda do the right thing here, so let it go. - v.add(getElement(elementName)); - v.add(partName); + param.setType(getElement(elementName)); } + + v.add(param); + continue; // next part } - // flow to here means literal use (no encoding) + // flow to here means literal + wrapped! // See if we can map all the XML types to java types // if we can, we use these as the types Node node = null; Element e; - if (typeName != null && elementName == null) { + if (typeName != null) { // Since we can't (yet?) make the Axis engine generate the right // XML for literal parts that specify the type attribute, // abort processing with an error if we encounter this case @@ -1109,34 +1128,65 @@ bindingName})); } - if (elementName != null) { - node = getTypeEntry(elementName, true).getNode(); - // Check if this element is of the form: - // <element name="foo" type="tns:foo_type"/> - QName type = Utils.getNodeTypeRefQName(node, "type"); - if (type != null) - node = getTypeEntry(type, false).getNode(); + if (elementName == null) { + throw new IOException( + JavaUtils.getMessage("noElemOrType", + partName, + opName)); + } + + // Get the node which corresponds to the type entry for this + // element. i.e.: + // <part name="part" element="foo:bar"/> + // ... + // <schema targetNamespace="foo"> + // <element name="bar"...> <--- This one + node = getTypeEntry(elementName, true).getNode(); + + // Check if this element is of the form: + // <element name="foo" type="tns:foo_type"/> + QName type = Utils.getNodeTypeRefQName(node, "type"); + if (type != null) { + // If in fact we have such a type, go get the node that + // corresponds to THAT definition. + node = getTypeEntry(type, false).getNode(); } - if (node == null) - continue; // ??? Skip this part, something is wrong + // If we have nothing at this point, we're in trouble. + if (node == null) { + throw new IOException( + JavaUtils.getMessage("badTypeNode", + new String[] { + partName, + opName, + elementName.toString()})); + } // Get the nested type entries. Vector vTypes = - SchemaUtils.getComplexElementTypesAndNames(node, this); + SchemaUtils.getComplexElementDeclarations(node, this); if (vTypes != null) { // add the elements in this list - v.addAll(vTypes); + for (int j = 0; j < vTypes.size(); j++) { + ElementDecl elem = (ElementDecl) vTypes.elementAt(j); + Parameter p = new Parameter(); + p.setQName(Utils.getWSDLQName(elem.getName())); + p.setType(elem.getType()); + v.add(p); + } } else { // XXX - This should be a SOAPElement/SOAPBodyElement + Parameter p = new Parameter(); + p.setName(partName); + if (typeName != null) { - v.add(getType(typeName)); - v.add(partName); + p.setType(getType(typeName)); } else if (elementName != null) { - v.add(getElement(elementName)); - v.add(partName); + p.setType(getElement(elementName)); } + + v.add(p); } } // while @@ -1592,7 +1642,6 @@ QName name = entry.getQName(); if (get(name, entry.getClass()) == null) { // An entry of the given qname of the given type doesn't exist yet. - if (entry instanceof Type && get(name, UndefinedType.class) != null) { 1.21 +16 -8 xml-axis/java/src/org/apache/axis/wsdl/toJava/Utils.java Index: Utils.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/Utils.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- Utils.java 18 Mar 2002 22:37:34 -0000 1.20 +++ Utils.java 19 Mar 2002 20:15:29 -0000 1.21 @@ -247,7 +247,8 @@ if (kind.getLocalPart().equals("schema")) { search = null; } else if (kind.getLocalPart().equals("element")) { - localName = SymbolTable.ANON_TOKEN + getNodeNameQName(search).getLocalPart(); + localName = SymbolTable.ANON_TOKEN + + getNodeNameQName(search).getLocalPart(); search = search.getParentNode(); } else if (kind.getLocalPart().equals("complexType") || kind.getLocalPart().equals("simpleType")) { @@ -613,15 +614,17 @@ } // getNestedTypes private static void getNestedTypes( - Node type, HashSet types,SymbolTable symbolTable) { + Node type, HashSet types, SymbolTable symbolTable) { // Process types declared in this type - Vector v = SchemaUtils.getComplexElementTypesAndNames(type, symbolTable); + Vector v = SchemaUtils.getComplexElementDeclarations(type, symbolTable); if (v != null) { - for (int i = 0; i < v.size(); i+=2) { - if (!types.contains(v.get(i))) { - types.add(v.get(i)); - getNestedTypes( - ((TypeEntry) v.get(i)).getNode(), types, symbolTable); + for (int i = 0; i < v.size(); i++) { + ElementDecl elem = (ElementDecl)v.get(i); + if (!types.contains(elem.getType())) { + types.add(elem.getType()); + getNestedTypes(elem.getType().getNode(), + types, + symbolTable); } } } @@ -703,6 +706,11 @@ { return new javax.xml.rpc.namespace.QName(qname.getNamespaceURI(), qname.getLocalPart()); + } + + public static QName getWSDLQName(javax.xml.rpc.namespace.QName qname) + { + return new QName(qname.getNamespaceURI(), qname.getLocalPart()); } } 1.2 +94 -0 xml-axis/java/src/org/apache/axis/wsdl/toJava/ElementDecl.java 1.88 +2 -2 xml-axis/java/test/wsdl/Wsdl2javaTestSuite.xml Index: Wsdl2javaTestSuite.xml =================================================================== RCS file: /home/cvs/xml-axis/java/test/wsdl/Wsdl2javaTestSuite.xml,v retrieving revision 1.87 retrieving revision 1.88 diff -u -r1.87 -r1.88 --- Wsdl2javaTestSuite.xml 12 Mar 2002 16:13:37 -0000 1.87 +++ Wsdl2javaTestSuite.xml 19 Mar 2002 20:15:29 -0000 1.88 @@ -719,9 +719,9 @@ <!-- This tests .NET document/literal WSDL. We get this WSDL file from the internet on purpose, file is only for reference. - --> - <!-- <wsdl2java url="http://www.perfectxml.net/WebServices/SalesRankNPrice/BookService.asmx?WSDL" --> <wsdl2java url="test/wsdl/literal/SalesRankNPrice.wsdl" + --> + <wsdl2java url="http://www.perfectxml.net/WebServices/SalesRankNPrice/BookService.asmx?WSDL" output="build/work" verbose="no" serverSide="no" 1.6 +30 -13 xml-axis/java/test/wsdl/literal/SalesRankNPrice_ServiceTestCase.java Index: SalesRankNPrice_ServiceTestCase.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/wsdl/literal/SalesRankNPrice_ServiceTestCase.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SalesRankNPrice_ServiceTestCase.java 19 Feb 2002 15:37:12 -0000 1.5 +++ SalesRankNPrice_ServiceTestCase.java 19 Mar 2002 20:15:29 -0000 1.6 @@ -13,18 +13,21 @@ import org.apache.axis.AxisFault; import java.io.IOException; import java.io.File; +import java.net.URL; public class SalesRankNPrice_ServiceTestCase extends junit.framework.TestCase { + + public static URL url; + public SalesRankNPrice_ServiceTestCase(String name) { super(name); } -/* private void printit(String result) { System.out.println("Result: " + result); } - private void printit(SalesRankNPrice_Type r) { + private void printit(SalesRankNPrice1 r) { System.out.println("price: " + r.getPrice()); System.out.println("rank: " + r.getSalesRank()); } @@ -52,13 +55,14 @@ // List of files which should be generated private static String[] shouldExist= new String[] { - "All.java", + "SalesRankNPrice1.java", + "SalesRanks.java", "Prices.java", - "SalesRankNPrice_Service.java", - "SalesRankNPrice_Type.java", + "All.java", "SalesRankNPriceSoap.java", "SalesRankNPriceSoapStub.java", - "SalesRanks.java" + "SalesRankNPrice.java", + "SalesRankNPriceLocator.java" }; @@ -106,18 +110,20 @@ assertTrue("File exist (and it should NOT): " + shouldNotExist[i], !f.exists()); } } -*/ public void testSalesRankNPriceSoap() { -/* - // This is the book to look up - java.lang.String ISBN = "1861005466"; + // This is the book to look up... + // "Building Web Services With Java" :) + java.lang.String ISBN = "0672321815"; boolean debug = true; SalesRankNPriceSoap binding; try { - binding = new SalesRankNPrice_ServiceLocator().getSalesRankNPriceSoap(); + if (url != null) + binding = new SalesRankNPriceLocator().getSalesRankNPriceSoap(url); + else + binding = new SalesRankNPriceLocator().getSalesRankNPriceSoap(); } catch (javax.xml.rpc.ServiceException jre) { throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre ); } @@ -127,7 +133,7 @@ try { printit(binding.getAmazonSalesRank(ISBN)); printit(binding.getAmazonUKSalesRank(ISBN)); - printit(binding.getBNSalesRank(ISBN)); + //printit(binding.getBNSalesRank(ISBN)); printit(binding.getAmazonPrice(ISBN)); printit(binding.getAmazonUKPrice(ISBN)); printit(binding.getBNPrice(ISBN)); @@ -145,6 +151,17 @@ printit("Connect failure caused some of SalesRankNPrice_ServiceTestCase to be skipped."); } } -*/ } + + public static void main(String[] args) { + if (args.length == 1) { + try { + url = new URL(args[0]); + } catch (Exception e) { + } + } + + junit.textui.TestRunner.run(new junit.framework.TestSuite(SalesRankNPrice_ServiceTestCase.class)); + } // main + }