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 gd...@apache.org on 2003/12/10 03:52:28 UTC
cvs commit: ws-axis/java/test/wsdl/primitiveWrappers TypeWrapper_BindingImpl.java TypeWrapper_ServiceTestCase.java build.xml primitiveWrappers.wsdl readme.txt
gdaniels 2003/12/09 18:52:27
Modified: java/src/org/apache/axis/wsdl/symbolTable Parameter.java
SymbolTable.java
java/src/org/apache/axis/wsdl/toJava JavaBeanWriter.java
JavaImplWriter.java JavaStubWriter.java
JavaTestCaseWriter.java Utils.java
Added: java/test/wsdl/primitiveWrappers
TypeWrapper_BindingImpl.java
TypeWrapper_ServiceTestCase.java build.xml
primitiveWrappers.wsdl readme.txt
Log:
Fix bug 25348.
Carry "omittable" information around in Parameter descriptors, and use
that (and the equivalent in ElementDecl) when determining types for
code generation. This means if we find <element name="foo"
type="xsd:int" minOccurs="0"/> somewhere we'll map it to
java.lang.Integer and not int.
Also check in test case, including readme.txt.
Revision Changes Path
1.9 +11 -0 ws-axis/java/src/org/apache/axis/wsdl/symbolTable/Parameter.java
Index: Parameter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/Parameter.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Parameter.java 29 Oct 2003 20:46:24 -0000 1.8
+++ Parameter.java 10 Dec 2003 02:52:27 -0000 1.9
@@ -102,6 +102,9 @@
/** Field outHeader */
private boolean outHeader = false;
+
+ /** Is this an omittable param? */
+ private boolean omittable = false;
/**
* Method toString
@@ -266,4 +269,12 @@
public void setOutHeader(boolean outHeader) {
this.outHeader = outHeader;
} // setOutHeader
+
+ public boolean isOmittable() {
+ return omittable;
+ }
+
+ public void setOmittable(boolean omittable) {
+ this.omittable = omittable;
+ }
} // class Parameter
1.83 +10 -5 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.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- SymbolTable.java 26 Nov 2003 04:04:53 -0000 1.82
+++ SymbolTable.java 10 Dec 2003 02:52:27 -0000 1.83
@@ -1850,9 +1850,9 @@
TypeEntry paramEntry = p.getType();
TypeEntry outParamEntry = outParam.getType();
- String paramLastLocalPart = Utils.getLastLocalPart(paramEntry.getQName().getLocalPart());
- String outParamLastLocalPart = Utils.getLastLocalPart(outParamEntry.getQName().getLocalPart());
- if (p.getType().equals(outParam.getType())) {
+// String paramLastLocalPart = Utils.getLastLocalPart(paramEntry.getQName().getLocalPart());
+// String outParamLastLocalPart = Utils.getLastLocalPart(outParamEntry.getQName().getLocalPart());
+ if (paramEntry.equals(outParamEntry)) {
outputs.remove(outdex);
p.setMode(Parameter.INOUT);
@@ -1962,13 +1962,17 @@
* @param bindingEntry
* @throws IOException
*/
- public void getParametersFromParts(
- Vector v, Collection parts, boolean literal, String opName, BindingEntry bindingEntry)
+ public void getParametersFromParts(Vector v,
+ Collection parts,
+ boolean literal,
+ String opName,
+ BindingEntry bindingEntry)
throws IOException {
// HACK ALERT! This whole method is waaaay too complex.
// It needs rewriting (for instance, we sometimes new up
// a Parameter, then ignore it in favor of another we new up.)
+
// Determine if there's only one element. For wrapped
// style, we normally only have 1 part which is an
// element. But with MIME we could have any number of
@@ -2132,6 +2136,7 @@
p.setQName(elem.getName());
p.setType(elem.getType());
+ p.setOmittable(elem.getMinOccursIs0());
fillParamInfo(p, bindingEntry, opName, partName);
v.add(p);
}
1.52 +6 -2 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java
Index: JavaBeanWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- JavaBeanWriter.java 28 Nov 2003 17:08:13 -0000 1.51
+++ JavaBeanWriter.java 10 Dec 2003 02:52:27 -0000 1.52
@@ -300,6 +300,10 @@
} else {
String elemName = Utils.getLastLocalPart(elem.getName().getLocalPart());
variableName = Utils.xmlNameToJava(elemName);
+
+ if (elem.getMinOccursIs0()) {
+ typeName = Utils.getWrapperType(typeName);
+ }
}
names.add(typeName);
@@ -442,7 +446,7 @@
{
if (elements != null && i < (elements.size()*2))
{
- ElementDecl elem = (ElementDecl)elements.get((int)i/2);
+ ElementDecl elem = (ElementDecl)elements.get(i/2);
comments = elem.getDocumentation();
}
}
@@ -830,7 +834,7 @@
{
if (elements != null && i < (elements.size()*2))
{
- ElementDecl elem = (ElementDecl)elements.get((int)i/2);
+ ElementDecl elem = (ElementDecl)elements.get(i/2);
documentation = elem.getDocumentation();
}
}
1.34 +5 -3 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaImplWriter.java
Index: JavaImplWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaImplWriter.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- JavaImplWriter.java 29 Oct 2003 20:46:26 -0000 1.33
+++ JavaImplWriter.java 10 Dec 2003 02:52:27 -0000 1.34
@@ -185,12 +185,14 @@
}
// Print the return statement
- if (parms.returnParam != null) {
- TypeEntry returnType = parms.returnParam.getType();
+ Parameter returnParam = parms.returnParam;
+ if (returnParam != null) {
+ TypeEntry returnType = returnParam.getType();
pw.print(" return ");
- if (Utils.isPrimitiveType(returnType)) {
+ if (!returnParam.isOmittable() &&
+ Utils.isPrimitiveType(returnType)) {
String returnString = returnType.getName();
if ("boolean".equals(returnString)) {
1.123 +28 -22 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java
Index: JavaStubWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -r1.122 -r1.123
--- JavaStubWriter.java 30 Nov 2003 06:01:21 -0000 1.122
+++ JavaStubWriter.java 10 Dec 2003 02:52:27 -0000 1.123
@@ -1166,7 +1166,7 @@
javifiedName += ".value";
}
- if (p.getMIMEInfo() == null) {
+ if (p.getMIMEInfo() == null && !p.isOmittable()) {
javifiedName = Utils.wrapPrimitiveType(p.getType(),
javifiedName);
}
@@ -1197,8 +1197,7 @@
if (allOuts == 1) {
if (parms.returnParam != null) {
writeOutputAssign(pw, "return ",
- parms.returnParam.getType(),
- parms.returnParam.getMIMEInfo(), "_resp");
+ parms.returnParam, "_resp");
} else {
// The resp object must go into a holder
@@ -1215,9 +1214,10 @@
pw.println(" java.util.Map _output;");
pw.println(
" _output = _call.getOutputParams();");
- writeOutputAssign(pw, javifiedName + ".value = ",
- p.getType(), p.getMIMEInfo(),
- "_output.get(" + qnameName + ")");
+ writeOutputAssign(pw,
+ javifiedName + ".value = ",
+ p,
+ "_output.get(" + qnameName + ")");
}
} else {
@@ -1228,19 +1228,22 @@
for (int i = 0; i < parms.list.size(); ++i) {
Parameter p = (Parameter) parms.list.get(i);
String javifiedName = Utils.xmlNameToJava(p.getName());
- String qnameName = Utils.getNewQNameWithLastLocalPart(p.getQName());
+ String qnameName =
+ Utils.getNewQNameWithLastLocalPart(p.getQName());
if (p.getMode() != Parameter.IN) {
- writeOutputAssign(pw, javifiedName + ".value = ",
- p.getType(), p.getMIMEInfo(),
- "_output.get(" + qnameName + ")");
+ writeOutputAssign(pw,
+ javifiedName + ".value = ",
+ p,
+ "_output.get(" + qnameName + ")");
}
}
if (parms.returnParam != null) {
- writeOutputAssign(pw, "return ",
- parms.returnParam.getType(),
- parms.returnParam.getMIMEInfo(), "_resp");
+ writeOutputAssign(pw,
+ "return ",
+ parms.returnParam,
+ "_resp");
}
}
@@ -1255,33 +1258,36 @@
*
* @param pw
* @param target (either "return" or "something ="
- * @param type (source TypeEntry)
- * @param mimeInfo
* @param source (source String)
*/
private void writeOutputAssign(PrintWriter pw, String target,
- TypeEntry type, MimeInfo mimeInfo,
+ Parameter param,
String source) {
+ TypeEntry type = param.getType();
+
if ((type != null) && (type.getName() != null)) {
+ String typeName = type.getName();
+ if (param.isOmittable()) {
+ typeName = Utils.getWrapperType(type.getName());
+ }
// Try casting the output to the expected output.
// If that fails, use JavaUtils.convert()
pw.println(" try {");
pw.println(" " + target
- + Utils.getResponseString(type, mimeInfo, source));
+ + Utils.getResponseString(param, source));
pw.println(
" } catch (java.lang.Exception _exception) {");
pw.println(
" " + target
- + Utils.getResponseString(
- type, mimeInfo,
- "org.apache.axis.utils.JavaUtils.convert(" + source + ", "
- + type.getName() + ".class)"));
+ + Utils.getResponseString(param,
+ "org.apache.axis.utils.JavaUtils.convert(" +
+ source + ", " + typeName + ".class)"));
pw.println(" }");
} else {
pw.println(" " + target
- + Utils.getResponseString(type, mimeInfo, source));
+ + Utils.getResponseString(param, source));
}
}
} // class JavaStubWriter
1.52 +8 -6 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaTestCaseWriter.java
Index: JavaTestCaseWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaTestCaseWriter.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- JavaTestCaseWriter.java 29 Oct 2003 20:46:26 -0000 1.51
+++ JavaTestCaseWriter.java 10 Dec 2003 02:52:27 -0000 1.52
@@ -223,15 +223,17 @@
indent = " ";
}
- if (params.returnParam != null) {
- TypeEntry returnType = params.returnParam.getType();
+ Parameter returnParam = params.returnParam;
+ if (returnParam != null) {
+ TypeEntry returnType = returnParam.getType();
pw.print(" " + indent);
- pw.print(Utils.getParameterTypeName(params.returnParam));
+ pw.print(Utils.getParameterTypeName(returnParam));
pw.print(" value = ");
- if ((params.returnParam.getMIMEInfo() == null)
- && Utils.isPrimitiveType(returnType)) {
+ if ((returnParam.getMIMEInfo() == null) &&
+ !returnParam.isOmittable() &&
+ Utils.isPrimitiveType(returnType)) {
if ("boolean".equals(returnType.getName())) {
pw.println("false;");
} else {
@@ -244,7 +246,7 @@
pw.print(" " + indent);
- if (params.returnParam != null) {
+ if (returnParam != null) {
pw.print("value = ");
}
1.81 +40 -13 ws-axis/java/src/org/apache/axis/wsdl/toJava/Utils.java
Index: Utils.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/Utils.java,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -r1.80 -r1.81
--- Utils.java 3 Dec 2003 17:19:19 -0000 1.80
+++ Utils.java 10 Dec 2003 02:52:27 -0000 1.81
@@ -702,14 +702,17 @@
* Return the Object variable 'var' cast to the appropriate type
* doing the right thing for the primitive types.
*
- * @param type
- * @param mimeInfo
* @param var
* @return
*/
- public static String getResponseString(TypeEntry type, MimeInfo mimeInfo,
+ public static String getResponseString(Parameter param,
String var) {
-
+ if (param.getType() == null) {
+ return ";";
+ }
+ String typeName = param.getType().getName();
+ MimeInfo mimeInfo = param.getMIMEInfo();
+
String mimeType = (mimeInfo == null)
? null
: mimeInfo.getType();
@@ -717,9 +720,7 @@
? ""
: mimeInfo.getDimensions();
- if (type == null) {
- return ";";
- } else if (mimeType != null) {
+ if (mimeType != null) {
if (mimeType.equals("image/jpeg")) {
return "(java.awt.Image" + mimeDimensions + ") " + var + ";";
} else if (mimeType.equals("text/plain")) {
@@ -738,16 +739,20 @@
return "(javax.activation.DataHandler" + mimeDimensions + ") "
+ var + ";";
}
- } else {
- String objType = (String) TYPES.get(type.getName());
+ }
- if (objType != null) {
- return "((" + objType + ") " + var + ")." + type.getName()
- + "Value();";
+ String objType = (String) TYPES.get(typeName);
+
+ if (objType != null) {
+ if (param.isOmittable()) {
+ typeName = objType;
} else {
- return "(" + type.getName() + ") " + var + ";";
+ return "((" + objType + ") " + var + ")." + typeName +
+ "Value();";
}
}
+
+ return "(" + typeName + ") " + var + ";";
} // getResponseString
/**
@@ -759,6 +764,20 @@
public static boolean isPrimitiveType(TypeEntry type) {
return TYPES.get(type.getName()) != null;
} // isPrimitiveType
+
+ /**
+ * Return a "wrapper" type for the given type name. In other words,
+ * if it's a primitive type ("int") return the java wrapper class
+ * ("java.lang.Integer"). Otherwise return the type name itself.
+ *
+ * @param type
+ * @return the name of a java wrapper class for the type, or the type's
+ * name if it's not primitive.
+ */
+ public static String getWrapperType(String type) {
+ String ret = (String)TYPES.get(type);
+ return (ret == null) ? type : ret;
+ }
/**
* Return the operation QName. The namespace is determined from
@@ -914,6 +933,11 @@
if (parm.getMIMEInfo() == null) {
ret = parm.getType().getName();
+ if (parm.isOmittable()) {
+ String wrapped = (String)TYPES.get(ret);
+ if (wrapped != null)
+ ret = wrapped;
+ }
} else {
String mime = parm.getMIMEInfo().getType();
@@ -1153,6 +1177,9 @@
BooleanHolder bThrow) {
String paramType = param.getType().getName();
+ if (param.isOmittable()) {
+ paramType = Utils.getWrapperType(paramType);
+ }
String mimeType = (param.getMIMEInfo() == null)
? null
: param.getMIMEInfo().getType();
1.1 ws-axis/java/test/wsdl/primitiveWrappers/TypeWrapper_BindingImpl.java
Index: TypeWrapper_BindingImpl.java
===================================================================
/**
* TypeWrapper_BindingImpl.java
*
* This file was auto-generated from WSDL
* by the Apache Axis #axisVersion# #today# WSDL2Java emitter.
*/
package test.wsdl.primitiveWrappers;
public class TypeWrapper_BindingImpl implements test.wsdl.primitiveWrappers.TypeWrapper_Port{
public java.lang.Integer testWrapping(java.lang.Integer testWrappingInputInteger, test.wsdl.primitiveWrappers.Bean testWrappingInputBean) throws java.rmi.RemoteException {
return testWrappingInputInteger;
}
}
1.1 ws-axis/java/test/wsdl/primitiveWrappers/TypeWrapper_ServiceTestCase.java
Index: TypeWrapper_ServiceTestCase.java
===================================================================
/**
* TypeWrapper_ServiceTestCase.java
*
* This file was auto-generated from WSDL
* by the Apache Axis #axisVersion# #today# WSDL2Java emitter.
*/
package test.wsdl.primitiveWrappers;
public class TypeWrapper_ServiceTestCase extends junit.framework.TestCase {
public TypeWrapper_ServiceTestCase(java.lang.String name) {
super(name);
}
public void test1TypeWrapperTestWrapping() throws Exception {
test.wsdl.primitiveWrappers.TypeWrapper_BindingStub binding;
try {
binding = (test.wsdl.primitiveWrappers.TypeWrapper_BindingStub)
new test.wsdl.primitiveWrappers.TypeWrapper_ServiceLocator().getTypeWrapper();
}
catch (javax.xml.rpc.ServiceException jre) {
if(jre.getLinkedCause()!=null)
jre.getLinkedCause().printStackTrace();
throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
}
assertNotNull("binding is null", binding);
// Time out after a minute
binding.setTimeout(60000);
// Test operation
java.lang.Integer value = null;
Bean bean = new test.wsdl.primitiveWrappers.Bean();
bean.setPrimitive(5);
bean.setWrapped(null); // Since this is null it won't appear on the
// wire. We should check that at some point!
value = binding.testWrapping(new java.lang.Integer(5), bean);
assertEquals("Wrong result from service", value, new Integer(5));
}
}
1.1 ws-axis/java/test/wsdl/primitiveWrappers/build.xml
Index: build.xml
===================================================================
<?xml version="1.0" ?>
<!DOCTYPE project [
<!ENTITY properties SYSTEM "file:../../../xmls/properties.xml">
<!ENTITY paths SYSTEM "file:../../../xmls/path_refs.xml">
<!ENTITY taskdefs SYSTEM "file:../../../xmls/taskdefs.xml">
<!ENTITY taskdefs_post_compile SYSTEM "file:../../../xmls/taskdefs_post_compile.xml">
<!ENTITY targets SYSTEM "file:../../../xmls/targets.xml">
]>
<!-- ===================================================================
<description>
Test/Sample Component file for Axis
Notes:
This is a build file for use with the Jakarta Ant build tool.
Prerequisites:
jakarta-ant from http://jakarta.apache.org
Build Instructions:
To compile
ant compile
To execute
ant run
Author:
Matt Seibert mseibert@us.ibm.com
Copyright:
Copyright (c) 2002-2003 Apache Software Foundation.
</description>
==================================================================== -->
<project default="compile">
<property name="axis.home" location="../../.." />
<property name="componentName" value="test/wsdl/primitiveWrappers" />
&properties;
&paths;
&taskdefs;
&taskdefs_post_compile;
&targets;
<target name="clean">
<echo message="Removing ${build.dir}/classes/${componentName} and ${build.dir}/work/${componentName}" />
<delete dir="${build.dir}/classes/${componentName}"/>
<delete dir="${build.dir}/work/${componentName}"/>
</target>
<target name="copy" depends="setenv"/>
<target name="compile" depends="copy">
<echo message="Compiling test.wsdl.primitiveWrappers"/>
<!-- ArrayTest Test -->
<wsdl2java url="${axis.home}/test/wsdl/primitiveWrappers/primitiveWrappers.wsdl"
output="${axis.home}/build/work"
serverSide="yes"
noimports="no"
verbose="no"
testcase="yes">
</wsdl2java>
<copy todir="${build.dir}/work/test/wsdl/primitiveWrappers" overwrite="yes">
<fileset dir="${axis.home}/test/wsdl/primitiveWrappers">
<include name="*TestCase.java"/>
<include name="*Impl.java"/>
</fileset>
</copy>
<javac srcdir="${build.dir}/work" destdir="${build.dest}" fork="${javac.fork}"
debug="${debug}">
<classpath refid="classpath" />
<include name="test/wsdl/primitiveWrappers/**/*.java" />
</javac>
</target>
<target name="run" >
<antcall target="execute-Component" />
</target>
</project>
1.1 ws-axis/java/test/wsdl/primitiveWrappers/primitiveWrappers.wsdl
Index: primitiveWrappers.wsdl
===================================================================
<?xml version="1.0" encoding="utf-8"?>
<definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:s0="http://primitiveWrappers.wsdl.test/"
targetNamespace="http://primitiveWrappers.wsdl.test/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<s:schema targetNamespace="http://primitiveWrappers.wsdl.test/">
<s:complexType name="bean">
<s:sequence>
<!-- This should remain a java int -->
<s:element name="primitive" type="s:int"/>
<!-- This one, since it's minOccurs="0", should turn into an Integer -->
<s:element name="wrapped" type="s:int" minOccurs="0" maxOccurs="1"/>
</s:sequence>
</s:complexType>
<s:element name="testWrapping">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="inputInteger" type="s:int" />
<s:element name="inputBean" type="s0:bean"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="testWrappingResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="return" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</types>
<message name="testWrappingSoapIn">
<part name="parameters" element="s0:testWrapping" />
</message>
<message name="testWrappingSoapOut">
<part name="parameters" element="s0:testWrappingResponse" />
</message>
<portType name="TypeWrapper">
<operation name="testWrapping">
<input message="s0:testWrappingSoapIn" />
<output message="s0:testWrappingSoapOut" />
</operation>
</portType>
<binding name="TypeWrapper" type="s0:TypeWrapper">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<operation name="testWrapping">
<soap:operation style="document" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="TypeWrapper">
<port name="TypeWrapper" binding="s0:TypeWrapper">
<soap:address location="http://localhost:8080/axis/services/TypeWrapper" />
</port>
</service>
</definitions>
1.1 ws-axis/java/test/wsdl/primitiveWrappers/readme.txt
Index: readme.txt
===================================================================
This tests whether we correctly process element declarations which are of
types (i.e. xsd:int) which would normally map to Java primitives, but have
minOccurs="0", meaning they should in fact map to the Java wrapper classes
(i.e. java.lang.Integer). The WSDL contains both a bean containing field
declarations and a wrapped method with parameter declarations with
minOccurs="0".
Author : Glen Daniels (gdaniels@apache.org)