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 di...@apache.org on 2005/03/21 13:37:21 UTC
cvs commit: ws-axis/java/src/org/apache/axis/encoding TypeMappingImpl.java
dims 2005/03/21 04:37:21
Modified: java/src/org/apache/axis/utils JavaUtils.java
java/src/org/apache/axis/encoding/ser BeanSerializer.java
java/src/org/apache/axis/wsdl/fromJava Emitter.java
Types.java
java/src/org/apache/axis/wsdl/toJava Emitter.java
JavaBeanWriter.java JavaBindingWriter.java
JavaDeployWriter.java JavaEnumTypeWriter.java
JavaGeneratorFactory.java JavaHolderWriter.java
JavaServiceWriter.java
java/src/org/apache/axis/wsdl Java2WSDL.java
java/tools/org/apache/axis/tools/ant/wsdl
Java2WsdlAntTask.java
java/src/org/apache/axis/i18n resource.properties
java/src/org/apache/axis/encoding TypeMappingImpl.java
Added: java/src/org/apache/axis/utils ArrayUtil.java
Log:
Fix for AXIS-1891 - Expanding Java2wsdl to support the starting-from-java wrapped style web service
from Jongjin Choi
URL: http://issues.apache.org/jira/browse/AXIS-1891
Revision Changes Path
1.115 +27 -0 ws-axis/java/src/org/apache/axis/utils/JavaUtils.java
Index: JavaUtils.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/utils/JavaUtils.java,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -r1.114 -r1.115
--- JavaUtils.java 21 Nov 2004 21:05:51 -0000 1.114
+++ JavaUtils.java 21 Mar 2005 12:37:19 -0000 1.115
@@ -313,6 +313,20 @@
return array;
}
+ // in case destClass is array and arg is ArrayOfT class. (ArrayOfT -> T[])
+ if (arg != null && destClass.isArray()) {
+ Object newArg = ArrayUtil.convertObjectToArray(arg, destClass);
+ if (newArg != null && newArg != arg)
+ return newArg;
+ }
+
+ // in case arg is ArrayOfT and destClass is an array. (T[] -> ArrayOfT)
+ if (arg != null && arg.getClass().isArray()) {
+ Object newArg = ArrayUtil.convertArrayToObject(arg, destClass);
+ if (newArg != null)
+ return newArg;
+ }
+
// Return if no conversion is available
if (!(arg instanceof Collection ||
(arg != null && arg.getClass().isArray())) &&
@@ -581,6 +595,19 @@
if (src.isPrimitive()) {
return isConvertable(getWrapperClass(src),dest);
}
+
+ // ArrayOfT -> T[] ?
+ if (dest.isArray()) {
+ if (ArrayUtil.isConvertable(src, dest) == true)
+ return true;
+ }
+
+ // T[] -> ArrayOfT ?
+ if (src.isArray()) {
+ if (ArrayUtil.isConvertable(src, dest) == true)
+ return true;
+ }
+
return false;
}
1.1 ws-axis/java/src/org/apache/axis/utils/ArrayUtil.java
Index: ArrayUtil.java
===================================================================
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.axis.utils;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
public class ArrayUtil {
private static class ArrayInfo {
public Class componentType;
public Class arrayType;
public int dimension;
}
/**
* Convert ArrayOfT to T[].
* @param obj the object of type ArrayOfT to convert
* @param arrayType the destination array type
* @return returns the converted array object.
* If not convertable the original obj argument is returned.
* If the obj is not type of ArrayOfT, null is returned.
*/
public static Object convertObjectToArray(Object obj, Class arrayType) {
try {
ArrayInfo arri = new ArrayInfo();
boolean rc = internalIsConvertable(obj.getClass(), arri, arrayType);
if (rc == false) {
return obj;
}
BeanPropertyDescriptor pd = null;
pd = getArrayComponentPD(obj.getClass());
if (pd == null) {
return null;
}
Object comp = pd.get(obj);
int arraylen = 0;
if (comp.getClass().isArray()) {
arraylen = Array.getLength(comp);
} else {
return comp;
}
int[] dims = new int[arri.dimension];
dims[0] = arraylen;
Object targetArray = Array.newInstance(arri.componentType, dims);
for (int i = 0; i < arraylen; i++) {
Object subarray = Array.get(comp, i);
Class subarrayClass = arrayType.getComponentType();
Array.set(targetArray, i, convertObjectToArray(subarray, subarrayClass));
}
return targetArray;
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
/**
* Check if the clazz(perhaps ArrayOfT class) can be converted to T[].
* @param clazz a class of ArrayOfT
* @param arrayType an array class (T[])
* @return true if converable, false if not
*/
public static boolean isConvertable(Class clazz, Class arrayType) {
ArrayInfo arrInfo = new ArrayInfo();
return internalIsConvertable(clazz, arrInfo, arrayType);
}
/**
* Check if the clazz(perhaps ArrayOfT class) can be converted to T[].
* @param clazz a class of ArrayOfT
* @param arri convert result information
* @param arrayType an array class (T[])
* @return true if converable, false if not
*/
private static boolean internalIsConvertable(Class clazz, ArrayInfo arri, Class arrayType) {
BeanPropertyDescriptor pd = null, oldPd = null;
if (!arrayType.isArray())
return false;
Class destArrCompType = arrayType.getComponentType();
Class src = clazz;
int depth = 0;
while (true) {
pd = getArrayComponentPD(src);
if (pd == null)
break;
depth++;
src = pd.getType();
oldPd = pd;
if (destArrCompType.isAssignableFrom(src))
break;
}
if (depth == 0 || oldPd.getType() == null) {
return false;
}
arri.componentType = oldPd.getType();
arri.dimension = depth;
Class componentType = oldPd.getType();
int[] dims = new int[depth];
Object array = Array.newInstance(componentType, dims);
arri.arrayType = array.getClass();
if (arrayType.isAssignableFrom(arri.arrayType))
return true;
else
return false;
}
/**
* Gets the BeanPropertyDescriptor of ArrayOfT class's array member.
* @param clazz a class of perhaps ArrayOfT type.
* @return the BeanPropertyDescriptor. If the clazz is not type of ArrayOfT, null is returned.
*/
private static BeanPropertyDescriptor getArrayComponentPD(Class clazz) {
BeanPropertyDescriptor bpd = null;
int count = 0;
Class cls = clazz;
while (!cls.getName().equals("java.lang.Object")) {
BeanPropertyDescriptor bpds[] = BeanUtils.getPd(clazz);
for (int i = 0; i < bpds.length; i++) {
BeanPropertyDescriptor pd = bpds[i];
if (pd.isReadable() && pd.isWriteable() && pd.isIndexed()) {
count++;
if (count >= 2)
return null;
else
bpd = pd;
}
}
cls = cls.getSuperclass();
}
if (count == 1) {
return bpd;
}
else
return null;
}
/**
* Gets the dimension of arrayType
* @param arrayType an array class
* @return the dimension
*/
public static int getArrayDimension(Class arrayType) {
if (!arrayType.isArray())
return 0;
int dim = 0;
Class compType = arrayType;
do {
dim++;
arrayType = compType;
compType = arrayType.getComponentType();
} while (compType.isArray());
return dim;
}
private static Object createNewInstance(Class cls) throws InstantiationException, IllegalAccessException {
Object obj = null;
if (!cls.isPrimitive())
obj = cls.newInstance();
else {
if (boolean.class.isAssignableFrom(cls))
obj = new Boolean(false);
else if (byte.class.isAssignableFrom(cls))
obj = new Byte((byte)0);
else if (char.class.isAssignableFrom(cls))
obj = new Character('\u0000');
else if (short.class.isAssignableFrom(cls))
obj = new Short((short)0);
else if (int.class.isAssignableFrom(cls))
obj = new Integer(0);
else if (long.class.isAssignableFrom(cls))
obj = new Long(0L);
else if (float.class.isAssignableFrom(cls))
obj = new Float(0.0F);
else if (double.class.isAssignableFrom(cls))
obj = new Double(0.0D);
}
return obj;
}
/**
* Convert an array object of which type is T[] to ArrayOfT class.
* @param array the array object
* @param destClass the destination class
* @return the object of type destClass if convertable, null if not.
*/
public static Object convertArrayToObject(Object array, Class destClass) {
int dim = getArrayDimension(array.getClass());
if (dim == 0) {
return null;
}
Object dest = null;
try {
// create the destArray
int arraylen = Array.getLength(array);
Object destArray = null;
Class destComp = null;
if (!destClass.isArray()) {
dest = destClass.newInstance();
BeanPropertyDescriptor pd = getArrayComponentPD(destClass);
if (pd == null)
return null;
destComp = pd.getType();
destArray = Array.newInstance(destComp, arraylen);
pd.set(dest, destArray);
} else {
destComp = destClass.getComponentType();
dest = Array.newInstance(destComp, arraylen);
destArray = dest;
}
// iniialize the destArray
for (int i = 0; i < arraylen; i++) {
Array.set(destArray, i, createNewInstance(destComp));
}
// set the destArray
for (int i = 0; i < arraylen; i++) {
Object comp = Array.get(array, i);
if (comp.getClass().isArray()) {
Class cls = Array.get(destArray, i).getClass();
Array.set(destArray, i, convertArrayToObject(comp, cls));
}
else {
Array.set(destArray, i, comp);
}
}
} catch (IllegalAccessException ignore) {
return null;
} catch (InvocationTargetException ignore) {
return null;
} catch (InstantiationException ignore) {
return null;
}
return dest;
}
}
1.84 +8 -0 ws-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java
Index: BeanSerializer.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- BeanSerializer.java 7 Feb 2005 07:54:04 -0000 1.83
+++ BeanSerializer.java 21 Mar 2005 12:37:20 -0000 1.84
@@ -27,6 +27,7 @@
import org.apache.axis.message.MessageElement;
import org.apache.axis.utils.BeanPropertyDescriptor;
import org.apache.axis.utils.BeanUtils;
+import org.apache.axis.utils.JavaUtils;
import org.apache.axis.utils.Messages;
import org.apache.axis.utils.FieldPropertyDescriptor;
import org.apache.axis.wsdl.fromJava.Types;
@@ -119,6 +120,13 @@
if (!suppressElement)
context.startElement(name, beanAttrs);
+ // check whether the array is converted to ArrayOfT shema type
+ if (value.getClass().isArray()) {
+ Object newVal = JavaUtils.convert(value, javaType);
+ if (newVal != null && javaType.isAssignableFrom(newVal.getClass())) {
+ value = newVal;
+ }
+ }
try {
// Serialize each property
for (int i=0; i<propertyDescriptor.length; i++) {
1.141 +16 -2 ws-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java
Index: Emitter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java,v
retrieving revision 1.140
retrieving revision 1.141
diff -u -r1.140 -r1.141
--- Emitter.java 24 Feb 2005 21:59:55 -0000 1.140
+++ Emitter.java 21 Mar 2005 12:37:20 -0000 1.141
@@ -211,6 +211,9 @@
/** Version string to put at top of WSDL */
private String versionMessage = null;
+
+ /** The mapping of generated type qname to its corresponding java type. For use with java<-->wsdl roundtripping */
+ private HashMap qName2ClassMap;
// Style Modes
@@ -235,6 +238,7 @@
namespaces = new Namespaces();
exceptionMsg = new HashMap();
usedElementNames = new HashMap();
+ qName2ClassMap = new HashMap();
}
/**
@@ -693,7 +697,9 @@
}
if (cls != null) {
- namespaces.put(cls.getName(), intfNS, "intf");
+ if (cls.getPackage() != null) {
+ namespaces.put(cls.getPackage().getName(), intfNS, "intf");
+ }
}
namespaces.putPrefix(implNS, "impl");
@@ -753,7 +759,7 @@
ParserConfigurationException {
types = new Types(def, tm, (TypeMapping)tmr.getDefaultTypeMapping(),
- namespaces, intfNS, stopClasses, serviceDesc);
+ namespaces, intfNS, stopClasses, serviceDesc, this);
if (inputWSDL != null) {
types.loadInputTypes(inputWSDL);
@@ -2739,4 +2745,12 @@
{
this.versionMessage = versionMessage;
}
+
+ /**
+ * Return the type qname to java type mapping
+ * @return mapping of type qname to its corresponding java type
+ */
+ public HashMap getQName2ClassMap() {
+ return qName2ClassMap;
+ }
}
1.112 +28 -0 ws-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java
Index: Types.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -r1.111 -r1.112
--- Types.java 25 Feb 2005 04:06:58 -0000 1.111
+++ Types.java 21 Mar 2005 12:37:20 -0000 1.112
@@ -120,6 +120,9 @@
/** Which types have we already written? */
Class [] mappedTypes = null;
+
+ /** The java to wsdl emitter */
+ Emitter emitter = null;
public static boolean isArray(Class clazz)
{
@@ -177,6 +180,26 @@
}
/**
+ * This class serailizes a <code>Class</code> to XML Schema. The constructor
+ * provides the context for the streamed node within the WSDL document
+ *
+ * @param def WSDL Definition Element to declare namespaces
+ * @param tm TypeMappingRegistry to handle known types
+ * @param defaultTM default TM
+ * @param namespaces user defined or autogenerated namespace and prefix maps
+ * @param targetNamespace targetNamespace of the document
+ * @param stopClasses
+ * @param serviceDesc
+ * @param emitter Java2Wsdl emitter
+ */
+ public Types(Definition def, TypeMapping tm, TypeMapping defaultTM,
+ Namespaces namespaces, String targetNamespace,
+ List stopClasses, ServiceDesc serviceDesc, Emitter emitter) {
+ this(def, tm, defaultTM, namespaces, targetNamespace, stopClasses, serviceDesc);
+ this.emitter = emitter;
+ }
+
+ /**
* Return the namespaces object for the current context
*
* @return
@@ -1805,6 +1828,11 @@
}
}
+ // store the mapping of type qname and its correspoding java type
+ if (emitter != null) {
+ emitter.getQName2ClassMap().put(qName, type);
+ }
+
return true;
}
1.85 +78 -1 ws-axis/java/src/org/apache/axis/wsdl/toJava/Emitter.java
Index: Emitter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/Emitter.java,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- Emitter.java 24 Feb 2005 21:59:55 -0000 1.84
+++ Emitter.java 21 Mar 2005 12:37:20 -0000 1.85
@@ -17,6 +17,7 @@
import org.apache.axis.Constants;
import org.apache.axis.constants.Scope;
+import org.apache.axis.description.ServiceDesc;
import org.apache.axis.encoding.TypeMapping;
import org.apache.axis.encoding.TypeMappingRegistryImpl;
import org.apache.axis.i18n.Messages;
@@ -33,6 +34,8 @@
import javax.wsdl.WSDLException;
import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
+
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Constructor;
@@ -140,6 +143,15 @@
private TypeMapping defaultTM = null; // Default TM
private TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
+
+ /** The mapping of qname to its corresponding java type generated by Java2Wsdl emitter. For deploy mode roundtripping use. */
+ private HashMap qName2ClassMap;
+
+ /** The ServiceDesc. For deploy mode roundtripping use. */
+ private ServiceDesc serviceDesc;
+
+ /** The deploy mode flag */
+ private boolean isDeploy;
/**
* Default constructor.
@@ -989,7 +1001,7 @@
public void setImplementationClassName(String implementationClassName) {
this.implementationClassName = implementationClassName;
}
-
+
/**
* @return Returns the allowInvalidURL.
*/
@@ -1003,4 +1015,69 @@
public void setAllowInvalidURL(boolean allowInvalidURL) {
this.allowInvalidURL = allowInvalidURL;
}
+
+ /**
+ * Set the type qname to java class map
+ * @param map a type qname to javaclass map (from Java2Wsdl emitter)
+ */
+ public void setQName2ClassMap(HashMap map) {
+ qName2ClassMap = map;
+ }
+
+ /**
+ * Get the type qname to java class map
+ * @return the type qname to java class map
+ */
+ public HashMap getQName2ClassMap() {
+ return qName2ClassMap;
+ }
+
+ /**
+ * Retruns the SericeDesc object
+ * @return
+ */
+ public ServiceDesc getServiceDesc() {
+ return serviceDesc;
+ }
+
+ /**
+ * Sets the ServicdDesc object
+ * @param serviceDesc ServiceDesc to set
+ */
+ public void setServiceDesc(ServiceDesc serviceDesc) {
+ this.serviceDesc = serviceDesc;
+ }
+
+ /**
+ * Returns the deploy mode flag
+ * @return
+ */
+ public boolean isDeploy() {
+ return isDeploy;
+ }
+
+ /**
+ * Sets the deploy mode flag
+ * @param isDeploy deploy mode flag
+ */
+ public void setDeploy(boolean isDeploy) {
+ this.isDeploy = isDeploy;
+ }
+
+ /**
+ * Check if the className exists.
+ *
+ * @param className className to check
+ * @return true if exists, false if not
+ */
+ protected boolean doesExist(String className) {
+ Class cls = null;
+ try {
+ cls = ClassUtils.forName(className);
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+
+ return true;
+ }
}
1.74 +15 -0 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.73
retrieving revision 1.74
diff -u -r1.73 -r1.74
--- JavaBeanWriter.java 5 Jan 2005 06:55:39 -0000 1.73
+++ JavaBeanWriter.java 21 Mar 2005 12:37:20 -0000 1.74
@@ -1242,4 +1242,19 @@
pw.println(" }");
pw.println("");
}
+
+ /** Generate a java source file and/or helper source file.
+ * If the emitter works in deploy mode and the class already exists, only the helper is generated.
+ * Otherwise, the java bean and helper source are generated.
+ */
+ public void generate() throws IOException {
+ String fqcn = getPackage() + "." + getClassName();
+ if (emitter.isDeploy() && emitter.doesExist(fqcn)) {
+ if (emitter.isHelperWanted()) {
+ helper.generate();
+ }
+ } else {
+ super.generate();
+ }
+ }
} // class JavaBeanWriter
1.26 +13 -0 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBindingWriter.java
Index: JavaBindingWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBindingWriter.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- JavaBindingWriter.java 10 May 2004 17:25:43 -0000 1.25
+++ JavaBindingWriter.java 21 Mar 2005 12:37:20 -0000 1.26
@@ -138,6 +138,7 @@
public void generate() throws IOException {
setGenerators();
+ postSetGenerators();
if (interfaceWriter != null) {
interfaceWriter.generate();
@@ -215,4 +216,16 @@
}
}
}
+
+ /**
+ * Set the writer based on the other condition after generate() is called.
+ */
+ protected void postSetGenerators() {
+ if (emitter.isDeploy()) {
+ interfaceWriter = null;
+ stubWriter = null;
+ skelWriter = null;
+ implWriter = null;
+ }
+ }
} // class JavaBindingWriter
1.90 +29 -2 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaDeployWriter.java
Index: JavaDeployWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaDeployWriter.java,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -r1.89 -r1.90
--- JavaDeployWriter.java 8 Feb 2005 18:44:36 -0000 1.89
+++ JavaDeployWriter.java 21 Mar 2005 12:37:20 -0000 1.90
@@ -17,6 +17,9 @@
import org.apache.axis.Constants;
import org.apache.axis.deployment.wsdd.WSDDConstants;
+import org.apache.axis.description.OperationDesc;
+import org.apache.axis.description.ServiceDesc;
+import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.constants.Scope;
import org.apache.axis.constants.Style;
import org.apache.axis.constants.Use;
@@ -29,6 +32,7 @@
import org.apache.axis.wsdl.symbolTable.SchemaUtils;
import org.apache.axis.wsdl.symbolTable.SymbolTable;
import org.apache.axis.wsdl.symbolTable.TypeEntry;
+import org.apache.commons.logging.Log;
import javax.wsdl.Binding;
import javax.wsdl.BindingOperation;
@@ -57,6 +61,8 @@
* This is Wsdl2java's deploy Writer. It writes the deploy.wsdd file.
*/
public class JavaDeployWriter extends JavaWriter {
+ /** Field log */
+ protected static Log log = LogFactory.getLog(JavaDeployWriter.class.getName());
/** Field definition */
protected Definition definition;
@@ -413,6 +419,8 @@
HashSet allowedMethods = new HashSet();
+ String namespaceURI = binding.getQName().getNamespaceURI();
+
if (!emitter.isSkeletonWanted()) {
Iterator operationsIterator =
binding.getBindingOperations().iterator();
@@ -422,8 +430,6 @@
(BindingOperation) operationsIterator.next();
Operation operation = bindingOper.getOperation();
OperationType type = operation.getStyle();
- String javaOperName =
- JavaUtils.xmlNameToJava(operation.getName());
// These operation types are not supported. The signature
// will be a string stating that fact.
@@ -431,7 +437,28 @@
|| (type == OperationType.SOLICIT_RESPONSE)) {
continue;
}
+ String javaOperName = null;
+ ServiceDesc serviceDesc = emitter.getServiceDesc();
+ if (emitter.isDeploy() && serviceDesc != null) {
+ // If the emitter works in deploy mode, sync the java operation name with it of the ServiceDesc
+ OperationDesc[] operDescs = serviceDesc.getOperationsByQName(new QName(namespaceURI, operation.getName()));
+ if (operDescs.length == 0) {
+ log.warn("Can't find operation in the Java Class for WSDL binding operation : " + operation.getName());
+ continue;
+ }
+ OperationDesc operDesc = operDescs[0];
+ if (operDesc.getMethod() == null) {
+ log.warn("Can't find Java method for operation descriptor : " + operDesc.getName());
+ continue;
+ }
+
+ javaOperName = operDesc.getMethod().getName();
+ } else {
+ javaOperName =
+ JavaUtils.xmlNameToJava(operation.getName());
+ }
+
allowedMethods.add(javaOperName);
// We pass "" as the namespace argument because we're just
1.30 +14 -0 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaEnumTypeWriter.java
Index: JavaEnumTypeWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaEnumTypeWriter.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- JavaEnumTypeWriter.java 8 Jul 2004 14:29:08 -0000 1.29
+++ JavaEnumTypeWriter.java 21 Mar 2005 12:37:20 -0000 1.30
@@ -358,4 +358,18 @@
return ids;
}
+
+ /** Generate a java source file for enum class.
+ * If the emitter works in deploy mode and the class already exists, the source wull not be generated.
+ */
+ public void generate() throws IOException {
+ String fqcn = getPackage() + "." + getClassName();
+ if (emitter.isDeploy()) {
+ if (!emitter.doesExist(fqcn)) {
+ super.generate();
+ }
+ } else {
+ super.generate();
+ }
+ }
} // class JavaEnumTypeWriter
1.66 +91 -62 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaGeneratorFactory.java
Index: JavaGeneratorFactory.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaGeneratorFactory.java,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- JavaGeneratorFactory.java 3 Feb 2005 17:42:41 -0000 1.65
+++ JavaGeneratorFactory.java 21 Mar 2005 12:37:20 -0000 1.66
@@ -571,6 +571,7 @@
// Need to javify the ref'd TypeEntry if it was not
// already processed
if (tEntry.getName() == null) {
+ boolean processed = false; // true if the java name is already determined
// Get the QName of the ref'd TypeEntry, which
// is will be used to javify the name
QName typeQName = tEntry.getQName();
@@ -591,69 +592,79 @@
typeQName = new QName(baseName.getNamespaceURI(),
baseName.getLocalPart() + "[]");
}
-
- if ((typeQName.getLocalPart().
- indexOf(SymbolTable.ANON_TOKEN) < 0)) {
- // Normal Case: The ref'd type is not anonymous
- // Simply construct the java name from
- // the qName
- tEntry.setName(emitter.getJavaName(typeQName));
- } else {
- // This is an anonymous type name.
- // Axis uses '>' as a nesting token to generate
- // unique qnames for anonymous types.
- // 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);
- // typeQName = new QName(typeQName.getNamespaceURI(),
- // localName);
- String localName = typeQName.getLocalPart();
-
- // Check to see if this is an anonymous type,
- // if it is, replace Axis' ANON_TOKEN with
- // an underscore to make sure we don't run
- // into name collisions with similarly named
- // non-anonymous types
- StringBuffer sb = new StringBuffer(localName);
- int aidx;
-
- while ((aidx = sb.toString().indexOf(SymbolTable.ANON_TOKEN)) > -1) {
- sb.replace(aidx, aidx + SymbolTable.ANON_TOKEN.length(), "");
- char c = sb.charAt(aidx);
- if (Character.isLetter(c) && Character.isLowerCase(c)) {
- sb.setCharAt(aidx, Character.toUpperCase(c));
- }
- }
-
- localName = sb.toString();
- typeQName = new QName(typeQName.getNamespaceURI(),
- localName);
-
- if (emitter.isTypeCollisionProtection() &&
- !emitter.getNamespaceExcludes().contains(new NamespaceSelector(typeQName.getNamespaceURI()))) {
- // If there is already an existing type,
- // there will be a collision.
- // If there is an existing anon type,
- // there will be a collision.
- // In both cases, mangle the name.
- if (symbolTable.getType(typeQName) != null ||
- anonQNames.get(typeQName) != null) {
- localName += "Type" + uniqueNum++;
- typeQName =
- new QName(typeQName.getNamespaceURI(),
- localName);
- }
-
- anonQNames.put(typeQName, typeQName);
- }
-
- // Now set the name with the constructed qname
- tEntry.setName(emitter.getJavaName(typeQName));
+
+ if (emitter.isDeploy()) {
+ Class class1 = (Class) emitter.getQName2ClassMap().get(typeQName);
+ if (class1 != null && !class1.isArray()) {
+ tEntry.setName(getJavaClassName(class1));
+ processed = true;
+ }
}
+
+ if (!processed) {
+ if ((typeQName.getLocalPart().
+ indexOf(SymbolTable.ANON_TOKEN) < 0)) {
+ // Normal Case: The ref'd type is not anonymous
+ // Simply construct the java name from
+ // the qName
+ tEntry.setName(emitter.getJavaName(typeQName));
+ } else {
+ // This is an anonymous type name.
+ // Axis uses '>' as a nesting token to generate
+ // unique qnames for anonymous types.
+ // 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);
+ // typeQName = new QName(typeQName.getNamespaceURI(),
+ // localName);
+ String localName = typeQName.getLocalPart();
+
+ // Check to see if this is an anonymous type,
+ // if it is, replace Axis' ANON_TOKEN with
+ // an underscore to make sure we don't run
+ // into name collisions with similarly named
+ // non-anonymous types
+ StringBuffer sb = new StringBuffer(localName);
+ int aidx;
+
+ while ((aidx = sb.toString().indexOf(SymbolTable.ANON_TOKEN)) > -1) {
+ sb.replace(aidx, aidx + SymbolTable.ANON_TOKEN.length(), "");
+ char c = sb.charAt(aidx);
+ if (Character.isLetter(c) && Character.isLowerCase(c)) {
+ sb.setCharAt(aidx, Character.toUpperCase(c));
+ }
+ }
+
+ localName = sb.toString();
+ typeQName = new QName(typeQName.getNamespaceURI(),
+ localName);
+
+ if (emitter.isTypeCollisionProtection() &&
+ !emitter.getNamespaceExcludes().contains(new NamespaceSelector(typeQName.getNamespaceURI()))) {
+ // If there is already an existing type,
+ // there will be a collision.
+ // If there is an existing anon type,
+ // there will be a collision.
+ // In both cases, mangle the name.
+ if (symbolTable.getType(typeQName) != null ||
+ anonQNames.get(typeQName) != null) {
+ localName += "Type" + uniqueNum++;
+ typeQName =
+ new QName(typeQName.getNamespaceURI(),
+ localName);
+ }
+
+ anonQNames.put(typeQName, typeQName);
+ }
+
+ // Now set the name with the constructed qname
+ tEntry.setName(emitter.getJavaName(typeQName));
+ }
+ } // if (!processed)
Vector elements = tEntry.getContainedElements();
if (elements != null) {
@@ -680,6 +691,24 @@
return uniqueNum;
}
+
+ /**
+ * Gets class name from Java class.
+ * If the class is an array, get its component type's name
+ * @param clazz a java class
+ * @return the class name in string
+ */
+ private static String getJavaClassName(Class clazz) {
+ Class class1 = clazz;
+
+ while (class1.isArray()) {
+ class1 = class1.getComponentType();
+ }
+
+ String name = class1.getName();
+ name.replace('$', '.');
+ return name;
+ }
/**
* setFaultContext:
1.19 +14 -0 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaHolderWriter.java
Index: JavaHolderWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaHolderWriter.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- JavaHolderWriter.java 18 Aug 2004 11:33:57 -0000 1.18
+++ JavaHolderWriter.java 21 Mar 2005 12:37:20 -0000 1.19
@@ -79,4 +79,18 @@
pw.println(" }");
pw.println();
} // writeOperation
+
+ /** Generate a java source file for the holder class.
+ * If the emitter works in deploy mode and the class already exists, the source wull not be generated.
+ */
+ public void generate() throws IOException {
+ String fqcn = getPackage() + "." + getClassName();
+ if (emitter.isDeploy()) {
+ if (!emitter.doesExist(fqcn)) {
+ super.generate();
+ }
+ } else {
+ super.generate();
+ }
+ }
} // class JavaHolderWriter
1.11 +34 -2 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaServiceWriter.java
Index: JavaServiceWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaServiceWriter.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- JavaServiceWriter.java 30 Mar 2004 11:36:02 -0000 1.10
+++ JavaServiceWriter.java 21 Mar 2005 12:37:20 -0000 1.11
@@ -39,6 +39,15 @@
/** Field PORT_NAME */
public static final String PORT_NAME = "port name";
+
+ /** Field emitter */
+ protected Emitter emitter;
+
+ /** Field WSDL service */
+ protected Service service;
+
+ /** Field symbolTable */
+ protected SymbolTable symbolTable;
/**
* Constructor.
@@ -49,7 +58,18 @@
*/
public JavaServiceWriter(Emitter emitter, Service service,
SymbolTable symbolTable) {
-
+ this.emitter = emitter;
+ this.service = service;
+ this.symbolTable = symbolTable;
+ } // ctor
+
+ /**
+ * setGenerators
+ * Logic to set the generators that are based on the Service.
+ * This logic was moved from the constructor so extended interfaces
+ * can more effectively use the hooks.
+ */
+ protected void setGenerators() {
ServiceEntry sEntry = symbolTable.getServiceEntry(service.getQName());
if (sEntry.isReferenced()) {
@@ -63,7 +83,17 @@
symbolTable);
}
}
- } // ctor
+ }
+
+ /**
+ * Set the writer based on the other condition after generate() is called.
+ */
+ protected void postSetGenerators() {
+ if (emitter.isDeploy()) {
+ serviceIfaceWriter = null;
+ serviceImplWriter = null;
+ }
+ }
/**
* Write all the service bindnigs: service and testcase.
@@ -71,6 +101,8 @@
* @throws IOException
*/
public void generate() throws IOException {
+ setGenerators();
+ postSetGenerators();
if (serviceIfaceWriter != null) {
serviceIfaceWriter.generate();
1.52 +68 -3 ws-axis/java/src/org/apache/axis/wsdl/Java2WSDL.java
Index: Java2WSDL.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/Java2WSDL.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- Java2WSDL.java 24 Feb 2005 21:59:55 -0000 1.51
+++ Java2WSDL.java 21 Mar 2005 12:37:20 -0000 1.52
@@ -25,8 +25,11 @@
import org.apache.axis.encoding.TypeMappingRegistryImpl;
import org.apache.axis.encoding.TypeMappingImpl;
+import java.io.File;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
/**
* Command line interface to the java2wsdl utility
@@ -114,6 +117,9 @@
/** Field STYLE_OPT */
protected static final int STYLE_OPT = 'y';
+
+ /** Field DEPLOY_OPT */
+ protected static final int DEPLOY_OPT = 'd';
/**
* Define the understood options. Each CLOptionDescriptor contains:
@@ -223,7 +229,11 @@
new CLOptionDescriptor("classpath",
CLOptionDescriptor.ARGUMENT_OPTIONAL,
CLASSPATH_OPT,
- Messages.getMessage("optionClasspath"))
+ Messages.getMessage("optionClasspath")),
+ new CLOptionDescriptor("deploy",
+ CLOptionDescriptor.ARGUMENT_DISALLOWED,
+ DEPLOY_OPT,
+ Messages.getMessage("j2woptDeploy00")),
};
/** Field emitter */
@@ -250,6 +260,9 @@
/** Field typeMappingVersion */
protected String typeMappingVersion = "1.2";
+ /** Field isDeplpy */
+ protected boolean isDeploy = false;
+
/**
* Instantiate a Java2WSDL emitter.
*/
@@ -479,7 +492,11 @@
option.getArgument(),
this.getClass().getClassLoader()));
break;
-
+
+ case DEPLOY_OPT:
+ isDeploy = true;
+ break;
+
default :
break;
}
@@ -572,7 +589,10 @@
} else {
emitter.emit(wsdlFilename, wsdlImplFilename);
}
-
+
+ if (isDeploy) {
+ generateServerSide(emitter, (wsdlImplFilename != null) ? wsdlImplFilename : wsdlFilename);
+ }
// everything is good
return (0);
} catch (Throwable t) {
@@ -583,6 +603,51 @@
} // run
/**
+ * Generate the server side artifacts from the generated WSDL
+ *
+ * @param j2w the Java2WSDL emitter
+ * @param wsdlFileName the generated WSDL file
+ * @throws Exception
+ */
+ protected void generateServerSide(Emitter j2w, String wsdlFileName) throws Exception {
+ org.apache.axis.wsdl.toJava.Emitter w2j = new org.apache.axis.wsdl.toJava.Emitter();
+ File wsdlFile = new File(wsdlFileName);
+ w2j.setServiceDesc(j2w.getServiceDesc());
+ w2j.setQName2ClassMap(j2w.getQName2ClassMap());
+ w2j.setOutputDir(wsdlFile.getParent());
+ w2j.setServerSide(true);
+ w2j.setHelperWanted(true);
+
+ // setup namespace-to-package mapping
+ String ns = j2w.getIntfNamespace();
+ String pkg = j2w.getCls().getPackage().getName();
+ w2j.getNamespaceMap().put(ns, pkg);
+
+ Map nsmap = j2w.getNamespaceMap();
+ if (nsmap != null) {
+ for (Iterator i = nsmap.keySet().iterator(); i.hasNext(); ) {
+ pkg = (String) i.next();
+ ns = (String) nsmap.get(pkg);
+ w2j.getNamespaceMap().put(ns, pkg);
+ }
+ }
+
+ // set 'deploy' mode
+ w2j.setDeploy(true);
+
+ if (j2w.getImplCls() != null) {
+ w2j.setImplementationClassName(j2w.getImplCls().getName());
+ } else {
+ if (!j2w.getCls().isInterface()) {
+ w2j.setImplementationClassName(j2w.getCls().getName());
+ } else {
+ throw new Exception("implementation class is not specified.");
+ }
+ }
+
+ w2j.run(wsdlFileName);
+ }
+ /**
* printUsage
* print usage information and quit.
*/
1.28 +59 -0 ws-axis/java/tools/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java
Index: Java2WsdlAntTask.java
===================================================================
RCS file: /home/cvs/ws-axis/java/tools/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Java2WsdlAntTask.java 24 Feb 2005 21:59:56 -0000 1.27
+++ Java2WsdlAntTask.java 21 Mar 2005 12:37:21 -0000 1.28
@@ -36,6 +36,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
/*
@@ -86,6 +87,7 @@
private Path classpath = null;
private String soapAction = null;
private List complexTypes = new LinkedList();
+ private boolean isDeploy = false;
private CommandlineJava commandline = new CommandlineJava();
/**
@@ -244,6 +246,9 @@
emitter.emit(output, outputImpl);
}
+ if (isDeploy == true) {
+ generateServerSide(emitter, (outputImpl != null) ? outputImpl : output);
+ }
} catch(BuildException b) {
//pass build exceptions up the wire
@@ -535,4 +540,58 @@
public void addSysproperty(Environment.Variable sysp) {
commandline.addSysproperty(sysp);
}
+
+ /**
+ * Sets the deploy flag
+ * @param deploy true if deploy mode
+ */
+ public void setDeploy(boolean deploy) {
+ this.isDeploy = deploy;
+ }
+
+ /**
+ * Generate the server side artifacts from the generated WSDL
+ *
+ * @param j2w the Java2WSDL emitter
+ * @param wsdlFileName the generated WSDL file
+ * @throws Exception
+ */
+ protected void generateServerSide(Emitter emitter, String wsdlFileName) throws Exception {
+ org.apache.axis.wsdl.toJava.Emitter w2j = new org.apache.axis.wsdl.toJava.Emitter();
+ File wsdlFile = new File(wsdlFileName);
+ w2j.setServiceDesc(emitter.getServiceDesc());
+ w2j.setQName2ClassMap(emitter.getQName2ClassMap());
+ w2j.setOutputDir(wsdlFile.getParent());
+ w2j.setServerSide(true);
+ w2j.setDeploy(true);
+
+ // setup namespace-to-package mapping
+ String ns = emitter.getIntfNamespace();
+ String pkg = emitter.getCls().getPackage().getName();
+ w2j.getNamespaceMap().put(ns, pkg);
+
+ Map nsmap = emitter.getNamespaceMap();
+ if (nsmap != null) {
+ for (Iterator i = nsmap.keySet().iterator(); i.hasNext(); ) {
+ pkg = (String) i.next();
+ ns = (String) nsmap.get(pkg);
+ w2j.getNamespaceMap().put(ns, pkg);
+ }
+ }
+
+ // set 'deploy' mode
+ w2j.setDeploy(true);
+
+ if (emitter.getImplCls() != null) {
+ w2j.setImplementationClassName(emitter.getImplCls().getName());
+ } else {
+ if (!emitter.getCls().isInterface()) {
+ w2j.setImplementationClassName(emitter.getCls().getName());
+ } else {
+ throw new Exception("implementation class is not specified.");
+ }
+ }
+
+ w2j.run(wsdlFileName);
+ }
}
1.113 +2 -0 ws-axis/java/src/org/apache/axis/i18n/resource.properties
Index: resource.properties
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/i18n/resource.properties,v
retrieving revision 1.112
retrieving revision 1.113
diff -u -r1.112 -r1.113
--- resource.properties 24 Feb 2005 21:59:55 -0000 1.112
+++ resource.properties 21 Mar 2005 12:37:21 -0000 1.113
@@ -736,6 +736,8 @@
j2woptexclude00=space or comma separated list of methods not to export
j2woptstopClass00=space or comma separated list of class names which will stop inheritance search if --all switch is given
j2woptImportSchema00=A file or URL to an XML Schema that should be physically imported into the generated WSDL
+j2woptDeploy00=generate wsdd and java classes for deploying
+
# NOTE: in optionSkeletonDeploy00, do not translate "--server-side".
optionSkeletonDeploy00=deploy skeleton (true) or implementation (false) in deploy.wsdd. Default is false. Assumes --server-side.
1.61 +9 -0 ws-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java
Index: TypeMappingImpl.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- TypeMappingImpl.java 15 Mar 2005 13:33:45 -0000 1.60
+++ TypeMappingImpl.java 21 Mar 2005 12:37:21 -0000 1.61
@@ -24,6 +24,7 @@
import org.apache.axis.encoding.ser.ArraySerializerFactory;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
+import org.apache.axis.utils.ArrayUtil;
import org.apache.axis.utils.Messages;
import org.apache.axis.utils.ClassUtils;
import org.apache.axis.utils.JavaUtils;
@@ -325,6 +326,14 @@
}
}
+ // check if ArrayOfT(xml)->T[](java) conversion is possible
+ if (sf == null && javaType.isArray() && xmlType != null) {
+ Pair pair2 = (Pair) qName2Pair.get(xmlType);
+ if (ArrayUtil.isConvertable(pair.javaType, javaType)) {
+ sf = (javax.xml.rpc.encoding.SerializerFactory) pair2SF.get(pair2);
+ }
+ }
+
return sf;
}