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 bu...@apache.org on 2001/10/10 15:45:04 UTC
cvs commit: xml-axis/java/src/org/apache/axis/wsdl WsdlAttributes.java Utils.java TypeFactory.java Type.java Emitter.java
butek 01/10/10 06:45:04
Modified: java/src/org/apache/axis/wsdl WsdlAttributes.java Utils.java
TypeFactory.java Type.java Emitter.java
Log:
Here are most of the Wsdl2java additions from Davanum Srinivas (dims@yahoo.com).
- Change some member variables to private.
- Changed some methods to private
- restrictionNode should be used instead of children.item(1)
- Removed some unnecessary variables.
- faultMapIter.next() changed to bFault. (We skip one BindingFault otherwise).
- Check if the parameters are java keywords.
I also found some new lines that all ended in tabs. This made it appear in my editor
as if there were blank lines following each of these new ones. I got rid of those tabs.
Revision Changes Path
1.5 +1 -1 xml-axis/java/src/org/apache/axis/wsdl/WsdlAttributes.java
Index: WsdlAttributes.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/WsdlAttributes.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WsdlAttributes.java 2001/10/04 19:37:26 1.4
+++ WsdlAttributes.java 2001/10/10 13:45:03 1.5
@@ -294,7 +294,7 @@
int faultBodyType = USE_ENCODED;
Iterator faultIter =
- ((BindingFault)faultMapIter.next()).getExtensibilityElements().iterator();
+ bFault.getExtensibilityElements().iterator();
for (; faultIter.hasNext();) {
Object obj = faultIter.next();
if (obj instanceof SOAPBody) {
1.4 +46 -4 xml-axis/java/src/org/apache/axis/wsdl/Utils.java
Index: Utils.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Utils.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Utils.java 2001/10/05 21:57:34 1.3
+++ Utils.java 2001/10/10 13:45:03 1.4
@@ -57,6 +57,12 @@
import org.w3c.dom.Node;
import javax.wsdl.QName;
+
+import java.text.Collator;
+
+import java.util.Arrays;
+import java.util.Locale;
+
/**
* This class contains static utility methods for the emitter.
*
@@ -95,8 +101,6 @@
return null;
}
- String nameValue = null;
-
Node attrNode = node.getAttributes().getNamedItem(attr);
if (attrNode != null) {
return attrNode.getNodeValue();
@@ -115,8 +119,6 @@
return null;
}
- String nameValue = null;
-
Node attrNode = node.getAttributes().getNamedItem(attr);
if (attrNode != null) {
return attrNode.getNodeValue();
@@ -225,6 +227,46 @@
public static boolean isSoapEncodingNS(String s) {
return (s.equals("http://www.w3.org/2001/06/soap-encoding"));
}
+
+ /**
+ * These are java keywords as specified at the following URL (sorted alphabetically).
+ * http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#229308
+ */
+ static final String keywords[] =
+ {
+ "abstract", "boolean", "break", "byte", "case",
+ "catch", "char", "class", "const", "continue",
+ "default", "do", "double", "else", "extends",
+ "final", "finally", "float", "for", "goto",
+ "if", "implements", "import", "instanceof", "int",
+ "interface", "long", "native", "new", "package",
+ "private", "protected", "public", "return", "short",
+ "static", "strictfp", "super", "switch", "synchronized",
+ "this", "throw", "throws", "transient", "try",
+ "void", "volatile", "while"
+ };
+
+ /** Collator for comparing the strings */
+ static final Collator englishCollator = Collator.getInstance(Locale.ENGLISH);
+
+ /** Use this character as suffix */
+ static final char keywordSuffix = '_';
+
+ /**
+ * checks if the input string is a valid java keyword.
+ * @return boolean true/false
+ */
+ public static boolean isJavaKeyword(String keyword) {
+ return (Arrays.binarySearch(keywords, keyword, englishCollator) >= 0);
+ }
+
+ /**
+ * Turn a java keyword string into a non-Java keyword string. (Right now
+ * this simply means appending an underscore.)
+ */
+ public static String makeNonJavaKeyword(String keyword){
+ return keyword + keywordSuffix;
+ }
}
1.4 +3 -3 xml-axis/java/src/org/apache/axis/wsdl/TypeFactory.java
Index: TypeFactory.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/TypeFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TypeFactory.java 2001/10/05 18:58:04 1.3
+++ TypeFactory.java 2001/10/10 13:45:04 1.4
@@ -85,7 +85,7 @@
/**
* Invoke this method to associate a namespace URI with a particular Java Package
*/
- public void map (String namespace, String pkg) {
+ private void map (String namespace, String pkg) {
mapNamespaceToPackage.put(namespace, pkg);
}
@@ -257,11 +257,11 @@
}
// Process the enumeration elements underneath the restriction node
- if (baseEType != null) {
+ if (baseEType != null && restrictionNode != null) {
Vector v = new Vector();
v.add(baseEType);
- NodeList enums = children.item(1).getChildNodes();
+ NodeList enums = restrictionNode.getChildNodes();
for (int i=0; i < enums.getLength(); i++) {
QName enumKind = Utils.getNodeQName(enums.item(i));
if (enumKind != null &&
1.5 +2 -0 xml-axis/java/src/org/apache/axis/wsdl/Type.java
Index: Type.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Type.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Type.java 2001/10/05 18:58:04 1.4
+++ Type.java 2001/10/10 13:45:04 1.5
@@ -185,6 +185,8 @@
return "java.util.Date";
} else if (localName.equals("base64Binary")) {
return "byte[]";
+ } else if (localName.equals("hexBinary")) {
+ return "byte[]";
} else if (localName.equals("date")) {
return "java.util.Date";
} else if (localName.equals("void")) {
1.44 +110 -86 xml-axis/java/src/org/apache/axis/wsdl/Emitter.java
Index: Emitter.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Emitter.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- Emitter.java 2001/10/09 18:54:49 1.43
+++ Emitter.java 2001/10/10 13:45:04 1.44
@@ -79,14 +79,26 @@
import javax.wsdl.QName;
import javax.wsdl.Service;
import javax.wsdl.WSDLException;
+
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
+
import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.*;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
/**
* This class produces java files for stubs, skeletons, and types from a
* WSDL document.
@@ -112,11 +124,11 @@
private boolean bVerbose = false;
private boolean bGeneratePackageName = false;
private boolean bGenerateImports = true;
- String packageName = null;
- String packageDirName = "";
- String outputDir = null;
- byte scope = NO_EXPLICIT_SCOPE;
- private ArrayList classList = new ArrayList();
+ private String packageName = null;
+ private String packageDirName = "";
+ private String outputDir = null;
+ private byte scope = NO_EXPLICIT_SCOPE;
+ private ArrayList classList = new ArrayList();
private ArrayList fileList = new ArrayList();
private TypeFactory emitFactory = null;
@@ -217,8 +229,8 @@
// Collect information about ports and operations
wsdlAttr = new WsdlAttributes(def, new HashMap());
- // output interfaces for portTypes
- portTypesInfo = writePortTypes();
+ // Output interfaces for portTypes - fill in the portTypesInfo HashMap
+ writePortTypes(portTypesInfo);
// Output Stub classes for bindings
writeBindings(portTypesInfo);
@@ -346,20 +358,20 @@
//
// Implementation
//
-
- /**
- * This method returns a list of all generated class names.
- */
- public List getGeneratedClassNames() {
- return this.classList;
- }
-
- /**
- * This method returns a list of all generated file names.
- */
- public List getGeneratedFileNames() {
- return this.fileList;
- }
+
+ /**
+ * This method returns a list of all generated class names.
+ */
+ public List getGeneratedClassNames() {
+ return this.classList;
+ }
+
+ /**
+ * This method returns a list of all generated file names.
+ */
+ public List getGeneratedFileNames() {
+ return this.fileList;
+ }
/**
* This method returns a set of all the Types in a given PortType.
@@ -459,12 +471,11 @@
} // getNestedTypes
/**
- * Generate the bindings for all port types.
+ * Generate the bindings for all port types, and fill in the portTypesInfo HashMap.
*/
- private HashMap writePortTypes() throws IOException {
+ private void writePortTypes(HashMap portTypesInfo) throws IOException {
Map portTypes = def.getPortTypes();
Iterator i = portTypes.values().iterator();
- HashMap portTypesInfo = new HashMap();
while (i.hasNext()) {
PortType portType = (PortType) i.next();
@@ -482,7 +493,6 @@
portTypesInfo.put(portType, portTypeInfo);
}
- return portTypesInfo;
} // writePortTypes
/**
@@ -490,10 +500,10 @@
*/
private HashMap writePortType(PortType portType) throws IOException {
String nameValue = xmlNameToJava(portType.getQName().getLocalPart());
- String fileName = nameValue + ".java";
-
- this.fileList.add(fileName);
- this.classList.add(nameValue);
+ String fileName = nameValue + ".java";
+
+ this.fileList.add(fileName);
+ this.classList.add(nameValue);
PrintWriter interfacePW = printWriter (fileName);
if (bVerbose)
@@ -523,11 +533,11 @@
*/
private void writeAxisPortType(PortType portType) throws IOException {
String nameValue = xmlNameToJava(portType.getQName().getLocalPart()) + "Axis";
- String fileName = nameValue + ".java";
-
- this.classList.add(nameValue);
- this.fileList.add(fileName);
+ String fileName = nameValue + ".java";
+ this.classList.add(nameValue);
+ this.fileList.add(fileName);
+
PrintWriter interfacePW = printWriter(fileName);
if (bVerbose)
System.out.println("Generating server-side PortType interface: " + fileName);
@@ -831,7 +841,7 @@
if (literal) {
QName elementName = part.getElementName();
if (elementName != null) {
- v.add(elementName.getLocalPart());
+ v.add(Utils.capitalize(elementName.getLocalPart()));
v.add(part.getName());
}
} else {
@@ -901,10 +911,10 @@
*/
private String fault(Fault operation) throws IOException {
String exceptionName = Utils.capitalize(xmlNameToJava(operation.getName()));
- String fileName = exceptionName + ".java";
-
- this.classList.add(exceptionName);
- this.fileList.add(fileName);
+ String fileName = exceptionName + ".java";
+
+ this.classList.add(exceptionName);
+ this.fileList.add(fileName);
PrintWriter pw = printWriter(fileName);
@@ -981,11 +991,11 @@
}
String stubName = name + "Stub";
- String stubFileName = stubName + ".java";
-
- this.classList.add(stubName);
- this.fileList.add(stubFileName);
+ String stubFileName = stubName + ".java";
+ this.classList.add(stubName);
+ this.fileList.add(stubFileName);
+
PrintWriter stubPW = printWriter(stubFileName);
if (bVerbose)
System.out.println("Generating client-side stub: " + stubFileName);
@@ -1051,14 +1061,14 @@
if (bEmitSkeleton) {
String skelName = name + "Skeleton";
- String skelFileName = skelName + ".java";
-
- this.classList.add(skelName);
- this.fileList.add(skelFileName);
+ String skelFileName = skelName + ".java";
+
+ this.classList.add(skelName);
+ this.fileList.add(skelFileName);
skelPW = printWriter(skelFileName);
String implType = portTypeName + " impl";
- String implName = name + "Impl";
+ String implName = name + "Impl";
if (bVerbose)
System.out.println("Generating server-side skeleton: " + skelFileName);
@@ -1079,11 +1089,11 @@
skelPW.println(" }");
skelPW.println();
- String implFileName = implName + ".java";
-
- this.classList.add(implName);
- this.fileList.add(implFileName);
+ String implFileName = implName + ".java";
+ this.classList.add(implName);
+ this.fileList.add(implFileName);
+
if (!fileExists (implFileName)) {
implPW = printWriter(implFileName);
if (bVerbose)
@@ -1430,10 +1440,10 @@
*/
private void writeService(Service service) throws IOException {
String serviceName = xmlNameToJava(service.getQName().getLocalPart());
- String fileName = serviceName + ".java";
-
- this.classList.add(serviceName);
- this.fileList.add(fileName);
+ String fileName = serviceName + ".java";
+
+ this.classList.add(serviceName);
+ this.fileList.add(fileName);
PrintWriter servicePW = printWriter(fileName);
TestCaseEmitter testFactory = null;
@@ -1441,13 +1451,13 @@
if (this.bVerbose) {
System.out.println("Generating service class: " + fileName);
}
+
+ if (this.bEmitTestCase) {
+ String testCase = serviceName + "TestCase";
+ String testCaseFileName = testCase + ".java";
- if (this.bEmitTestCase) {
- String testCase = serviceName + "TestCase";
- String testCaseFileName = testCase + ".java";
-
- this.classList.add(testCase);
- this.fileList.add(testCaseFileName);
+ this.classList.add(testCase);
+ this.fileList.add(testCaseFileName);
testFactory = new TestCaseEmitter(this.printWriter(testCaseFileName),
this.packageName,
@@ -1568,15 +1578,15 @@
*/
private void writeDeploymentXML() {
try {
- PrintWriter deployPW = printWriter("deploy.xml");
- this.fileList.add("deploy.xml");
+ PrintWriter deployPW = printWriter("deploy.xml");
+ this.fileList.add("deploy.xml");
if (bVerbose) {
System.out.println("Generating deployment document: deploy.xml");
}
initializeDeploymentDoc(deployPW, "deploy");
- PrintWriter undeployPW = printWriter("undeploy.xml");
- this.fileList.add("undeploy.xml");
+ PrintWriter undeployPW = printWriter("undeploy.xml");
+ this.fileList.add("undeploy.xml");
if (bVerbose) {
System.out.println("Generating deployment document: undeploy.xml");
@@ -1804,11 +1814,11 @@
String javaName = type.getJavaLocalName();
- String fileName = javaName + ".java";
-
- this.classList.add(javaName);
- this.fileList.add(fileName);
+ String fileName = javaName + ".java";
+ this.classList.add(javaName);
+ this.fileList.add(fileName);
+
PrintWriter typePW = printWriter(fileName);
if (bVerbose)
System.out.println("Generating type implementation: " + fileName);
@@ -1816,8 +1826,13 @@
writeFileHeader(fileName, typePW);
typePW.println("public class " + javaName + " implements java.io.Serializable {");
- for (int i = 0; i < elements.size(); i += 2)
- typePW.println(" private " + elements.get(i) + " " + elements.get(i + 1) + ";");
+ for (int i = 0; i < elements.size(); i += 2) {
+ String variable = (String) elements.get(i + 1);
+ if (Utils.isJavaKeyword(variable)) {
+ variable = Utils.makeNonJavaKeyword(variable);
+ }
+ typePW.println(" private " + elements.get(i) + " " + variable + ";");
+ }
typePW.println();
typePW.println(" public " + javaName + "() {");
@@ -1827,12 +1842,18 @@
typePW.print(" public " + javaName + "(");
for (int i = 0; i < elements.size(); i += 2) {
if (i != 0) typePW.print(", ");
- typePW.print((String) elements.get(i) + " " + elements.get(i + 1));
+ String variable = (String) elements.get(i + 1);
+ if (Utils.isJavaKeyword(variable)) {
+ variable = Utils.makeNonJavaKeyword(variable);
+ }
+ typePW.print((String) elements.get(i) + " " + variable);
}
typePW.println(") {");
for (int i = 1; i < elements.size(); i += 2) {
String variable = (String) elements.get(i);
-
+ if (Utils.isJavaKeyword(variable)) {
+ variable = Utils.makeNonJavaKeyword(variable);
+ }
typePW.println(" this." + variable + " = " + variable + ";");
}
typePW.println(" }");
@@ -1843,6 +1864,9 @@
String name = (String) elements.get(i + 1);
String capName = Utils.capitalize(name);
+ if (Utils.isJavaKeyword(name)) {
+ name = Utils.makeNonJavaKeyword(name);
+ }
typePW.println(" public " + typeName + " get" + capName + "() {");
typePW.println(" return " + name + ";");
typePW.println(" }");
@@ -1870,11 +1894,11 @@
String javaName = eType.getJavaLocalName();
- String fileName = javaName + ".java";
-
- this.classList.add(javaName);
- this.fileList.add(fileName);
+ String fileName = javaName + ".java";
+ this.classList.add(javaName);
+ this.fileList.add(fileName);
+
PrintWriter typePW = printWriter(fileName);
if (bVerbose)
System.out.println("Generating enum type implementation: " + fileName);
@@ -1896,11 +1920,11 @@
private void writeHolder(Type type) throws IOException {
Node node = type.getNode();
String javaName = type.getJavaLocalName();
+
+ String fileName = javaName + "Holder.java";
- String fileName = javaName + "Holder.java";
-
- this.classList.add(javaName);
- this.fileList.add(fileName);
+ this.classList.add(javaName);
+ this.fileList.add(fileName);
PrintWriter pw = printWriter(fileName);
if (bVerbose)
@@ -2141,8 +2165,8 @@
}
setPackageName(sb.toString());
}
-
- protected boolean isPrimitiveType(String type) {
- return TYPES.get(type) != null;
+
+ protected boolean isPrimitiveType(String type) {
+ return TYPES.get(type) != null;
}
}