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 sc...@apache.org on 2002/07/23 18:17:13 UTC
cvs commit: xml-axis/java/src/org/apache/axis/wsdl/toJava JavaDeployWriter.java JavaSkelWriter.java JavaStubWriter.java Utils.java
scheu 2002/07/23 09:17:12
Modified: java buildTest.xml
java/src/org/apache/axis/wsdl/toJava JavaDeployWriter.java
JavaSkelWriter.java JavaStubWriter.java Utils.java
Log:
Following changes made:
* Fix for Bugzilla 11084, Stub variable collisions.
The local variables are prepended with _.
Removed qname variables that were generated for each parameter name.
* Common code in the stub/skeleton/deploy writers for getting the
qname type is combined in the new Utils.getXSIType(TypeEntry)
method. This change eliminates a lot of code and potential flaws.
* Various minor changes to make the code more readable.
Revision Changes Path
1.4 +1 -1 xml-axis/java/buildTest.xml
Index: buildTest.xml
===================================================================
RCS file: /home/cvs/xml-axis/java/buildTest.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- buildTest.xml 23 Jul 2002 01:14:23 -0000 1.3
+++ buildTest.xml 23 Jul 2002 16:17:12 -0000 1.4
@@ -83,7 +83,7 @@
<available property="post-compile.present" file="post-compile.xml" />
<condition property="debug" value="on">
- <istrue value="${env.debug}"/>
+ <istrue value="${env.debug}" />
</condition>
</target>
1.53 +6 -33 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaDeployWriter.java
Index: JavaDeployWriter.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaDeployWriter.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- JavaDeployWriter.java 22 Jul 2002 15:17:35 -0000 1.52
+++ JavaDeployWriter.java 23 Jul 2002 16:17:12 -0000 1.53
@@ -78,9 +78,8 @@
import org.apache.axis.utils.JavaUtils;
import org.apache.axis.wsdl.symbolTable.BindingEntry;
-import org.apache.axis.wsdl.symbolTable.CollectionType;
-import org.apache.axis.wsdl.symbolTable.DefinedElement;
import org.apache.axis.wsdl.symbolTable.Element;
+import org.apache.axis.wsdl.symbolTable.CollectionType;
import org.apache.axis.wsdl.symbolTable.Parameter;
import org.apache.axis.wsdl.symbolTable.Parameters;
import org.apache.axis.wsdl.symbolTable.SymbolTable;
@@ -339,30 +338,17 @@
Parameters params =
symbolTable.getOperationParameters(operation, "", bEntry);
if (params != null) {
- QName returnQName = null;
- QName returnType = null;
// Get the operation QName
QName elementQName = Utils.getOperationQName(bindingOper);
// Get the operation's return QName
+ QName returnQName = null;
if (params.returnName != null)
returnQName = params.returnName;
- TypeEntry returnTE = params.returnType;
- if (returnTE != null &&
- returnTE instanceof DefinedElement &&
- returnTE.getRefType() != null) {
- returnTE = returnTE.getRefType();
- }
- if (returnTE != null &&
- returnTE instanceof CollectionType &&
- returnTE.getRefType() != null) {
- returnTE = returnTE.getRefType();
- }
- if (returnTE != null) {
- returnType = returnTE.getQName();
- }
+ // Get the QName representing the type
+ QName returnType = Utils.getXSIType(params.returnType);
// Write the operation metadata
writeOperation(pw, javaOperName, elementQName,
@@ -416,22 +402,9 @@
for (int i = 0; i < paramList.size(); i++) {
Parameter param = (Parameter) paramList.elementAt(i);
- // Get the typeEntry for the parameter.
- // Use the referenced type if an Element
- // Use the referenced type (the component type) if a Collection
- TypeEntry typeEntry = param.getType();
- if (typeEntry instanceof DefinedElement &&
- typeEntry.getRefType() != null) {
- typeEntry = typeEntry.getRefType();
- }
- if (typeEntry instanceof CollectionType &&
- typeEntry.getRefType() != null) {
- typeEntry = typeEntry.getRefType();
- }
-
- // Get the parameter name QName
+ // Get the parameter name QName and type QName
QName paramQName = param.getQName();
- QName paramType = typeEntry.getQName();
+ QName paramType = Utils.getXSIType(param.getType());
pw.print(" <parameter");
if (paramQName == null || "".equals(paramQName.getNamespaceURI())) {
1.37 +18 -47 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.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- JavaSkelWriter.java 22 Jul 2002 15:17:35 -0000 1.36
+++ JavaSkelWriter.java 23 Jul 2002 16:17:12 -0000 1.37
@@ -75,8 +75,6 @@
import javax.xml.namespace.QName;
import org.apache.axis.wsdl.symbolTable.BindingEntry;
-import org.apache.axis.wsdl.symbolTable.CollectionType;
-import org.apache.axis.wsdl.symbolTable.Element;
import org.apache.axis.wsdl.symbolTable.Parameter;
import org.apache.axis.wsdl.symbolTable.Parameters;
import org.apache.axis.wsdl.symbolTable.SymbolTable;
@@ -178,65 +176,38 @@
JavaUtils.getMessage("badParmMode00",
(new Byte(p.getMode())).toString()));
}
- // Construct a parameter with the parameter name,
- // mode, type qname and type javaType.
- TypeEntry paramType = p.getType();
- if (paramType instanceof Element &&
- paramType.getRefType() != null) {
- paramType = paramType.getRefType();
- }
- // For collections, set the paramType to the
- // component type QName.
- // The javaType is the type expected by the method.
- // So for example a parameter that takes a
- // collection type for
- // <element name="A" type="xsd:string" maxOccurs="unbounded"/>
- // will be
- // new ParameterDesc(<QName of A>, IN,
- // <QName of xsd:string>,
- // String[])
- if (paramType instanceof CollectionType &&
- paramType.getRefType() != null) {
- paramType = paramType.getRefType();
- }
+
+ // Get the QNames representing the parameter name and type
+ QName paramName = p.getQName();
+ QName paramType = Utils.getXSIType(p.getType());
pw.println(" " +
"new org.apache.axis.description.ParameterDesc(" +
- Utils.getNewQName(
- p.getQName()) +
- ", " + modeStr + "," +
- Utils.getNewQName(
- paramType.getQName())
- +","+
- p.getType().getName() + ".class"
- +"),");
+ Utils.getNewQName(paramName) +
+ ", " + modeStr + "," +
+ Utils.getNewQName(paramType) +
+ ","+
+ p.getType().getName() + ".class"
+ +"),");
}
pw.println(" };");
+ // Get the return name QName and type
+ QName retName = parameters.returnName;
+ QName retType = Utils.getXSIType(parameters.returnType);
+
String returnStr;
- if (parameters.returnType != null) {
+ if (retName != null) {
returnStr = Utils.getNewQName(parameters.returnName);
} else {
returnStr = "null";
}
pw.println(" _oper = new org.apache.axis.description.OperationDesc(\"" +
- javaOpName + "\", _params, " + returnStr + ");");
+ javaOpName + "\", _params, " + returnStr + ");");
- // Set the return type QName
- TypeEntry returnTE = parameters.returnType;
- if (returnTE != null &&
- returnTE instanceof Element &&
- returnTE.getRefType() != null) {
- returnTE = returnTE.getRefType();
- }
- if (returnTE != null &&
- returnTE instanceof CollectionType &&
- returnTE.getRefType() != null) {
- returnTE = returnTE.getRefType();
- }
- if (returnTE != null) {
+ if (retType != null) {
pw.println(" _oper.setReturnType(" +
- Utils.getNewQName(returnTE.getQName()) + ");");
+ Utils.getNewQName(retType) + ");");
}
// If we need to know the QName (if we have a namespace or
1.77 +62 -97 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.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- JavaStubWriter.java 20 Jul 2002 00:30:20 -0000 1.76
+++ JavaStubWriter.java 23 Jul 2002 16:17:12 -0000 1.77
@@ -179,34 +179,34 @@
pw.println();
pw.println(" private org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {");
pw.println(" try {");
- pw.println(" org.apache.axis.client.Call call =");
+ pw.println(" org.apache.axis.client.Call _call =");
pw.println(" (org.apache.axis.client.Call) super.service.createCall();");
pw.println(" if (super.maintainSessionSet) {");
- pw.println(" call.setMaintainSession(super.maintainSession);");
+ pw.println(" _call.setMaintainSession(super.maintainSession);");
pw.println(" }");
pw.println(" if (super.cachedUsername != null) {");
- pw.println(" call.setUsername(super.cachedUsername);");
+ pw.println(" _call.setUsername(super.cachedUsername);");
pw.println(" }");
pw.println(" if (super.cachedPassword != null) {");
- pw.println(" call.setPassword(super.cachedPassword);");
+ pw.println(" _call.setPassword(super.cachedPassword);");
pw.println(" }");
pw.println(" if (super.cachedEndpoint != null) {");
- pw.println(" call.setTargetEndpointAddress(super.cachedEndpoint);");
+ pw.println(" _call.setTargetEndpointAddress(super.cachedEndpoint);");
pw.println(" }");
pw.println(" if (super.cachedTimeout != null) {");
- pw.println(" call.setTimeout(super.cachedTimeout);");
+ pw.println(" _call.setTimeout(super.cachedTimeout);");
pw.println(" }");
pw.println(" if (super.cachedPortName != null) {");
- pw.println(" call.setPortName(super.cachedPortName);");
+ pw.println(" _call.setPortName(super.cachedPortName);");
pw.println(" }");
pw.println(" java.util.Enumeration keys = super.cachedProperties.keys();");
pw.println(" while (keys.hasMoreElements()) {");
pw.println(" String key = (String) keys.nextElement();");
- pw.println(" if(call.isPropertySupported(key))");
- pw.println(" call.setProperty(key, super.cachedProperties.get(key));");
+ pw.println(" if(_call.isPropertySupported(key))");
+ pw.println(" _call.setProperty(key, super.cachedProperties.get(key));");
pw.println(" else");
- pw.println(" call.setScopedProperty(key, super.cachedProperties.get(key));");
+ pw.println(" _call.setScopedProperty(key, super.cachedProperties.get(key));");
pw.println(" }");
if (types.size() > 0) {
pw.println(" // " + JavaUtils.getMessage("typeMap00"));
@@ -222,9 +222,9 @@
pw.println(" // "
+ JavaUtils.getMessage("mustSetStyle"));
if (bEntry.hasLiteral()) {
- pw.println(" call.setEncodingStyle(null);");
+ pw.println(" _call.setEncodingStyle(null);");
} else {
- pw.println(" call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);");
+ pw.println(" _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);");
}
pw.println(" for (int i = 0; i < cachedSerFactories.size(); ++i) {");
@@ -235,12 +235,12 @@
pw.println(" cachedSerFactories.get(i);");
pw.println(" Class df = (Class)");
pw.println(" cachedDeserFactories.get(i);");
- pw.println(" call.registerTypeMapping(cls, qName, sf, df, false);");
+ pw.println(" _call.registerTypeMapping(cls, qName, sf, df, false);");
pw.println(" }");
pw.println(" }");
pw.println(" }");
}
- pw.println(" return call;");
+ pw.println(" return _call;");
pw.println(" }");
pw.println(" catch (Throwable t) {");
pw.println(" throw new org.apache.axis.AxisFault(\""
@@ -470,31 +470,18 @@
pw.println(" if (super.cachedEndpoint == null) {");
pw.println(" throw new org.apache.axis.NoEndPointException();");
pw.println(" }");
- pw.println(" org.apache.axis.client.Call call = createCall();");
+ pw.println(" org.apache.axis.client.Call _call = createCall();");
// loop over paramters and set up in/out params
for (int i = 0; i < parms.list.size(); ++i) {
Parameter p = (Parameter) parms.list.get(i);
- // Get the TypeEntry of the actual type not the Element.
- TypeEntry type = p.getType();
- if (type instanceof DefinedElement &&
- type.getRefType() != null) {
- type = type.getRefType();
- }
- // Set the javaType to the name of the type
- String javaType = type.getName();
+ // Get the QNames representing the parameter name and type
+ QName paramName = p.getQName();
+ QName paramType = Utils.getXSIType(p.getType());
- // If the TypeEntry is a collectionType then
- // set use the QName of the componentType.
- // So for example if the following is the expected parameter:
- // <element name="A" type="xsd:string" maxOccurs="unbounded"/>
- // then the QName type is "xsd:string" and the javaType=String[]
- if (type instanceof CollectionType &&
- type.getRefType() != null) {
- type = type.getRefType();
- }
- QName qn = type.getQName();
+ // Set the javaType to the name of the type
+ String javaType = p.getType().getName();
if (javaType != null) {
javaType += ".class, ";
@@ -502,86 +489,64 @@
javaType = "";
}
- String typeString = "new javax.xml.namespace.QName(\"" +
- qn.getNamespaceURI() + "\", \"" +
- qn.getLocalPart() + "\")";
- QName paramQName = p.getQName();
- String qnName = "p" + i + "QName";
- pw.println(" javax.xml.namespace.QName " + qnName + " = new javax.xml.namespace.QName(\"" +
- paramQName.getNamespaceURI() + "\", \"" +
- paramQName.getLocalPart() + "\");");
+ // Get the text representing newing a QName for the name and type
+ String paramNameText = Utils.getNewQName(paramName);
+ String paramTypeText = Utils.getNewQName(paramType);
+
+ // Generate the addParameter call with the
+ // name qname, typeQName, optional javaType, and mode
if (p.getMode() == Parameter.IN) {
- pw.println(" call.addParameter(" + qnName + ", "
- + typeString + ", "
+ pw.println(" _call.addParameter(" + paramNameText + ", "
+ + paramTypeText + ", "
+ javaType + "javax.xml.rpc.ParameterMode.IN);");
}
else if (p.getMode() == Parameter.INOUT) {
- pw.println(" call.addParameter(" + qnName + ", "
- + typeString + ", "
+ pw.println(" _call.addParameter(" + paramNameText + ", "
+ + paramTypeText + ", "
+ javaType + "javax.xml.rpc.ParameterMode.INOUT);");
}
else { // p.getMode() == Parameter.OUT
- pw.println(" call.addParameter(" + qnName + ", "
- + typeString + ", "
+ pw.println(" _call.addParameter(" + paramNameText + ", "
+ + paramTypeText + ", "
+ javaType + "javax.xml.rpc.ParameterMode.OUT);");
}
}
// set output type
if (parms.returnType != null) {
- // Get the TypeEntry of the actual type not the Element.
- TypeEntry returnTE = parms.returnType;
- if (returnTE instanceof DefinedElement &&
- returnTE.getRefType() != null) {
- returnTE = returnTE.getRefType();
- }
- // Set the javaType to the name of the type
- String javaType = returnTE.getName();
-
- // If the return TypeEntry is a collectionType then
- // set the use the QName of the componentType.
- // So for example if the following is the expected return:
- // <element name="A" type="xsd:string" maxOccurs="unbounded"/>
- // this is generated:
- // setReturnType(<QName of xsd:string>, String[]);
- if (returnTE instanceof CollectionType &&
- returnTE.getRefType() != null) {
- returnTE = returnTE.getRefType();
- }
+ // Get the QName for the return Type
+ QName returnType = Utils.getXSIType(parms.returnType);
- // Get the QName and Java Class name
- QName qn = returnTE.getQName();
-
- String outputType = "new javax.xml.namespace.QName(\"" +
- qn.getNamespaceURI() + "\", \"" +
- qn.getLocalPart() + "\")";
+ // Get the javaType
+ String javaType = parms.returnType.getName();
if (javaType == null) {
- pw.println(" call.setReturnType(" +
- outputType + ");");
+ pw.println(" _call.setReturnType(" +
+ Utils.getNewQName(returnType) + ");");
} else {
- pw.println(" call.setReturnType(" +
- outputType + "," + javaType + ".class);");
+ pw.println(" _call.setReturnType(" +
+ Utils.getNewQName(returnType) +
+ "," + javaType + ".class);");
}
}
else {
- pw.println(" call.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);");
+ pw.println(" _call.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);");
}
// SoapAction
if (soapAction != null) {
- pw.println(" call.setUseSOAPAction(true);");
- pw.println(" call.setSOAPActionURI(\"" + soapAction + "\");");
+ pw.println(" _call.setUseSOAPAction(true);");
+ pw.println(" _call.setSOAPActionURI(\"" + soapAction + "\");");
}
// Encoding: literal or encoded use.
int use = bEntry.getInputBodyType(operation.getOperation());
if (use == BindingEntry.USE_LITERAL) {
// Turn off encoding
- pw.println(" call.setEncodingStyle(null);");
+ pw.println(" _call.setEncodingStyle(null);");
// turn off multirefs
- pw.println(" call.setScopedProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);");
+ pw.println(" _call.setScopedProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);");
// turn off XSI types
- pw.println(" call.setScopedProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);");
+ pw.println(" _call.setScopedProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);");
}
// Style: document, RPC, or wrapped
@@ -594,7 +559,7 @@
styleStr = "document";
}
}
- pw.println(" call.setOperationStyle(\"" + styleStr + "\");");
+ pw.println(" _call.setOperationStyle(\"" + styleStr + "\");");
// Operation name
if (styleStr.equals("wrapped")) {
@@ -604,18 +569,18 @@
Map partsMap = operation.getOperation().getInput().getMessage().getParts();
Part p = (Part)partsMap.values().iterator().next();
QName q = p.getElementName();
- pw.println(" call.setOperationName(new javax.xml.namespace.QName(\"" + q.getNamespaceURI() + "\", \"" + q.getLocalPart() + "\"));" );
+ pw.println(" _call.setOperationName(new javax.xml.namespace.QName(\"" + q.getNamespaceURI() + "\", \"" + q.getLocalPart() + "\"));" );
} else {
QName elementQName = Utils.getOperationQName(operation);
if (elementQName != null) {
- pw.println(" call.setOperationName(" +
+ pw.println(" _call.setOperationName(" +
Utils.getNewQName(elementQName) + ");" );
}
}
// Invoke the operation
pw.println();
- pw.print(" Object resp = call.invoke(");
+ pw.print(" Object _resp = _call.invoke(");
pw.print("new Object[] {");
// Write the input and inout parameter list
@@ -644,8 +609,8 @@
}
pw.println("});");
pw.println();
- pw.println(" if (resp instanceof java.rmi.RemoteException) {");
- pw.println(" throw (java.rmi.RemoteException)resp;");
+ pw.println(" if (_resp instanceof java.rmi.RemoteException) {");
+ pw.println(" throw (java.rmi.RemoteException)_resp;");
pw.println(" }");
int allOuts = parms.outputs + parms.inouts;
@@ -654,7 +619,7 @@
if (allOuts == 1) {
if (parms.returnType != null) {
writeOutputAssign(pw, "return ",
- parms.returnType, "resp");
+ parms.returnType, "_resp");
}
else {
// The resp object must go into a holder
@@ -667,17 +632,17 @@
String javifiedName = Utils.xmlNameToJava(p.getName());
String qnameName = Utils.getNewQName(p.getQName());
- pw.println(" java.util.Map output;");
- pw.println(" output = call.getOutputParams();");
+ pw.println(" java.util.Map _output;");
+ pw.println(" _output = _call.getOutputParams();");
writeOutputAssign(pw, javifiedName + ".value =",
p.getType(),
- "output.get(" + qnameName + ")");
+ "_output.get(" + qnameName + ")");
}
}
else {
// There is more than 1 output. Get the outputs from getOutputParams.
- pw.println(" java.util.Map output;");
- pw.println(" output = call.getOutputParams();");
+ pw.println(" java.util.Map _output;");
+ pw.println(" _output = _call.getOutputParams();");
for (int i = 0; i < parms.list.size (); ++i) {
Parameter p = (Parameter) parms.list.get (i);
String javifiedName = Utils.xmlNameToJava(p.getName());
@@ -685,13 +650,13 @@
if (p.getMode() != Parameter.IN) {
writeOutputAssign(pw, javifiedName + ".value =",
p.getType(),
- "output.get(" + qnameName + ")");
+ "_output.get(" + qnameName + ")");
}
}
if (parms.returnType != null) {
writeOutputAssign(pw, "return ",
parms.returnType,
- "resp");
+ "_resp");
}
}
@@ -717,7 +682,7 @@
pw.println(" try {");
pw.println(" " + target +
Utils.getResponseString(type, source));
- pw.println(" } catch (java.lang.Exception e) {");
+ pw.println(" } catch (java.lang.Exception _exception) {");
pw.println(" " + target +
Utils.getResponseString(type,
"org.apache.axis.utils.JavaUtils.convert(" +
1.41 +39 -0 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.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- Utils.java 25 Jun 2002 14:45:56 -0000 1.40
+++ Utils.java 23 Jul 2002 16:17:12 -0000 1.41
@@ -56,6 +56,8 @@
import org.apache.axis.Constants;
import org.apache.axis.utils.JavaUtils;
+import org.apache.axis.wsdl.symbolTable.CollectionType;
+import org.apache.axis.wsdl.symbolTable.Element;
import org.apache.axis.wsdl.symbolTable.MessageEntry;
import org.apache.axis.wsdl.symbolTable.SymbolTable;
import org.apache.axis.wsdl.symbolTable.TypeEntry;
@@ -546,6 +548,43 @@
return "new javax.xml.namespace.QName(\"" +
qname.getNamespaceURI() + "\", \"" +
qname.getLocalPart() + "\")";
+ }
+
+ /**
+ * Get the QName that could be used in the xsi:type
+ * when serializing an object for this parameter/return
+ * @param te is the typeEntry from the Parameters object,
+ * which represents the parameter
+ * @return the QName of the type
+ */
+ public static QName getXSIType(TypeEntry te) {
+ QName xmlType = null;
+
+ // If the TypeEntry describes an Element, get
+ // the referenced Type.
+ if (te != null &&
+ te instanceof Element &&
+ te.getRefType() != null) {
+ te = te.getRefType();
+ }
+ // If the TypeEntry is a CollectionType, use
+ // the TypeEntry representing the component Type
+ // So for example a parameter that takes a
+ // collection type for
+ // <element name="A" type="xsd:string" maxOccurs="unbounded"/>
+ // will be
+ // new ParameterDesc(<QName of A>, IN,
+ // <QName of xsd:string>,
+ // String[])
+ if (te != null &&
+ te instanceof CollectionType &&
+ te.getRefType() != null) {
+ te = te.getRefType();
+ }
+ if (te != null) {
+ xmlType = te.getQName();
+ }
+ return xmlType;
}
} // class Utils