butek 02/05/20 13:07:29
Modified: java/src/org/apache/axis/wsdl/toJava JavaBindingWriter.java
JavaImplWriter.java JavaStubWriter.java
JavaTestCaseWriter.java JavaWriter.java Utils.java
Log:
JavaWriter has become too brittle for good extensibility. It assumes that
each extension writes ONE file (extensions may not write any file at all);
it's geared toward writing .java files and gets ugly when we write other
things (like deploy.wsdd).
This is only the first step in cleaning up JavaWriter. In this step, I simply
move the utility-like methods from JavaWriter to Utils so future work isn't
cluttered and confused by this stuff:
fileExists,
isPrimitiveType,
getResponseString,
wrapPrimitiveType.
A future step will place more behavior on extensions. Right now
JavaWriter places a very simple behavior on extensions: it calls
writeFileHeader and writeFileBody. That's it. This is not sufficient (though
I'm still trying to figure out what is). I'll probably pull a lot of the ugliness
out of constructor calls into another method. And revamp some of the
javaisms (should JavaWriter really have the variables: classname?
packageName? qname? type?)
Revision Changes Path
1.11 +3 -3
xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBindingWriter.java
Index: JavaBindingWriter.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBindingWriter.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- JavaBindingWriter.java 17 May 2002 02:22:40 -0000 1.10
+++ JavaBindingWriter.java 20 May 2002 20:07:28 -0000 1.11
@@ -183,9 +183,9 @@
String fileName = Utils.getJavaLocalName(bEntry.getName())
+ "Impl.java";
try {
- // NOTE: Where does the fileExists method really belong?
- if (!((JavaWriter) stubWriter).fileExists (fileName,
- binding.getQName().getNamespaceURI())) {
+ if (!Utils.fileExists(fileName,
+ binding.getQName().getNamespaceURI(),
+ emitter.getNamespaces())) {
implWriter = getJavaImplWriter(
emitter, bEntry, symbolTable);
}
1.22 +2 -2
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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- JavaImplWriter.java 17 May 2002 19:09:32 -0000 1.21
+++ JavaImplWriter.java 20 May 2002 20:07:28 -0000 1.22
@@ -176,7 +176,7 @@
if (param.getMode() == Parameter.OUT) {
pw.print(" " + Utils.xmlNameToJava(param.getName())
+ ".value = ");
- if ( isPrimitiveType(param.getType()) ) {
+ if ( Utils.isPrimitiveType(param.getType()) ) {
if ( "boolean".equals(paramType) ) {
pw.print("false");
} else if ("byte".equals(paramType)) {
@@ -239,7 +239,7 @@
if (parms.returnType != null) {
pw.print(" return ");
- if (isPrimitiveType(parms.returnType)) {
+ if (Utils.isPrimitiveType(parms.returnType)) {
String returnType = parms.returnType.getName();
if ("boolean".equals(returnType)) {
pw.println("false;");
1.61 +8 -5
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.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- JavaStubWriter.java 17 May 2002 19:09:33 -0000 1.60
+++ JavaStubWriter.java 20 May 2002 20:07:28 -0000 1.61
@@ -607,10 +607,13 @@
needComma = true;
}
if (p.getMode() == Parameter.IN) {
- pw.print(wrapPrimitiveType(p.getType(), javifiedName));
+ pw.print(Utils.wrapPrimitiveType(p.getType(),
+ javifiedName));
}
else {
- pw.print(wrapPrimitiveType(p.getType(), javifiedName +
".value"));
+ pw.print(
+ Utils.wrapPrimitiveType(p.getType(),
+ javifiedName + ".value"));
}
}
}
@@ -693,17 +696,17 @@
// If that fails, use JavaUtils.convert()
pw.println(" try {");
pw.println(" " + target +
- getResponseString(type, source));
+ Utils.getResponseString(type, source));
pw.println(" } catch (java.lang.Exception e) {");
pw.println(" " + target +
- getResponseString(type,
+ Utils.getResponseString(type,
"org.apache.axis.utils.JavaUtils.convert("
+
source + ", " +
type.getName() + ".class)"));
pw.println(" }");
} else {
pw.println(" " + target +
- getResponseString(type, source));
+ Utils.getResponseString(type, source));
}
}
} // class JavaStubWriter
1.27 +2 -2
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.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- JavaTestCaseWriter.java 16 May 2002 19:34:17 -0000 1.26
+++ JavaTestCaseWriter.java 20 May 2002 20:07:29 -0000 1.27
@@ -188,7 +188,7 @@
pw.print(params.returnType.getName());
pw.print(" value = ");
- if ( isPrimitiveType( params.returnType ) ) {
+ if ( Utils.isPrimitiveType( params.returnType ) ) {
if ( "boolean".equals( params.returnType.getName() ) ) {
pw.println("false;");
} else {
@@ -230,7 +230,7 @@
}
if (param.getMode() != Parameter.OUT) {
- if ( isPrimitiveType(param.getType()) ) {
+ if ( Utils.isPrimitiveType(param.getType()) ) {
if ( "boolean".equals(paramType) ) {
pw.print("true");
} else if ("byte".equals(paramType)) {
1.13 +0 -67 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriter.java
Index: JavaWriter.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriter.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- JavaWriter.java 10 May 2002 13:30:35 -0000 1.12
+++ JavaWriter.java 20 May 2002 20:07:29 -0000 1.13
@@ -59,8 +59,6 @@
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.HashMap;
-
import javax.wsdl.QName;
import org.apache.axis.utils.JavaUtils;
@@ -263,61 +261,6 @@
} // writeComment
/**
- * A simple map of the primitive types and their holder objects
- */
- private static HashMap TYPES = new HashMap(7);
-
- static {
- TYPES.put("int", "Integer");
- TYPES.put("float", "Float");
- TYPES.put("boolean", "Boolean");
- TYPES.put("double", "Double");
- TYPES.put("byte", "Byte");
- TYPES.put("short", "Short");
- TYPES.put("long", "Long");
- }
-
- /**
- * Return a string with "var" wrapped as an Object type if needed
- */
- protected String wrapPrimitiveType(TypeEntry type, String var) {
- String objType = type == null ? null : (String) TYPES.get(type.getName());
- if (objType != null) {
- return "new " + objType + "(" + var + ")";
- } else if (type != null &&
- type.getName().equals("byte[]") &&
- type.getQName().getLocalPart().equals("hexBinary")) {
- // Need to wrap byte[] in special Hex object to get the correct
serialization
- return "new org.apache.axis.encoding.Hex(" + var + ")";
- } else {
- return var;
- }
- } // wrapPrimitiveType
-
- /**
- * Return the Object variable 'var' cast to the appropriate type
- * doing the right thing for the primitive types.
- */
- protected String getResponseString(TypeEntry type, String var) {
- if (type == null) {
- return ";";
- }
- else {
- String objType = (String) TYPES.get(type.getName());
- if (objType != null) {
- return "((" + objType + ") " + var + ")." + type.getName() +
"Value();";
- }
- else {
- return "(" + type.getName() + ") " + var + ";";
- }
- }
- } // getResponseString
-
- protected boolean isPrimitiveType(TypeEntry type) {
- return TYPES.get(type.getName()) != null;
- }
-
- /**
* Initialize the deployment document, spit out preamble comments
* and opening tag.
*/
@@ -356,16 +299,6 @@
pw.println(" xmlns=\"" + Constants.URI_WSDD +"\">");
}
} // initializeDeploymentDoc
-
- /**
- * Does the given file already exist?
- */
- protected boolean fileExists (String name, String namespace) throws IOException
- {
- String packageName = emitter.getNamespaces().getAsDir(namespace);
- String fullName = packageName + name;
- return new File (fullName).exists();
- } // fileExists
/**
* Write the body of the file. This is what extenders of this class must
1.31 +70 -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.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- Utils.java 14 May 2002 23:46:34 -0000 1.30
+++ Utils.java 20 May 2002 20:07:29 -0000 1.31
@@ -54,9 +54,13 @@
*/
package org.apache.axis.wsdl.toJava;
+import java.io.File;
+import java.io.IOException;
+
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -378,5 +382,71 @@
return "";
}
} // getJavaPackageName
+
+ /**
+ * Does the given file already exist in the given namespace?
+ */
+ public static boolean fileExists(String name, String namespace,
+ Namespaces namespaces) throws IOException
+ {
+ String packageName = namespaces.getAsDir(namespace);
+ String fullName = packageName + name;
+ return new File (fullName).exists();
+ } // fileExists
+
+ /**
+ * A simple map of the primitive types and their holder objects
+ */
+ private static HashMap TYPES = new HashMap(7);
+
+ static {
+ TYPES.put("int", "Integer");
+ TYPES.put("float", "Float");
+ TYPES.put("boolean", "Boolean");
+ TYPES.put("double", "Double");
+ TYPES.put("byte", "Byte");
+ TYPES.put("short", "Short");
+ TYPES.put("long", "Long");
+ }
+
+ /**
+ * Return a string with "var" wrapped as an Object type if needed
+ */
+ public static String wrapPrimitiveType(TypeEntry type, String var) {
+ String objType = type == null ? null : (String) TYPES.get(type.getName());
+ if (objType != null) {
+ return "new " + objType + "(" + var + ")";
+ } else if (type != null &&
+ type.getName().equals("byte[]") &&
+ type.getQName().getLocalPart().equals("hexBinary")) {
+ // Need to wrap byte[] in special Hex object to get the correct
serialization
+ return "new org.apache.axis.encoding.Hex(" + var + ")";
+ } else {
+ return var;
+ }
+ } // wrapPrimitiveType
+
+ /**
+ * Return the Object variable 'var' cast to the appropriate type
+ * doing the right thing for the primitive types.
+ */
+ public static String getResponseString(TypeEntry type, String var) {
+ if (type == null) {
+ return ";";
+ }
+ else {
+ String objType = (String) TYPES.get(type.getName());
+ if (objType != null) {
+ return "((" + objType + ") " + var + ")." + type.getName() +
"Value();";
+ }
+ else {
+ return "(" + type.getName() + ") " + var + ";";
+ }
+ }
+ } // getResponseString
+
+ public static boolean isPrimitiveType(TypeEntry type) {
+ return TYPES.get(type.getName()) != null;
+ } // isPrimitiveType
} // class Utils