You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by de...@apache.org on 2006/03/27 11:26:45 UTC
svn commit: r389081 [2/2] - in /webservices/axis2/trunk/java: ./ etc/
modules/adb/src/org/apache/axis2/databinding/utils/
modules/codegen/src/org/apache/axis2/wsdl/
modules/codegen/src/org/apache/axis2/wsdl/codegen/ modules/core/
modules/core/src/org/a...
Added: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java?rev=389081&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java (added)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java Mon Mar 27 01:26:40 2006
@@ -0,0 +1,399 @@
+package org.apache.ws.java2wsdl;
+
+import org.apache.ws.commons.schema.*;
+import org.apache.ws.java2wsdl.bytecode.MethodTable;
+import org.apache.ws.java2wsdl.utils.TypeTable;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+import org.codehaus.jam.*;
+
+import javax.xml.namespace.QName;
+import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Locale;
+
+/*
+* Copyright 2004,2005 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.
+*
+* @author : Deepal Jayasinghe (deepal@apache.org)
+*
+*/
+
+public class SchemaGenerator {
+ protected Log log = LogFactory.getLog(getClass());
+ private ClassLoader classLoader;
+ private String className;
+ private XmlSchema schema;
+ private TypeTable typeTable;
+ // to keep loadded method using JAM
+ private JMethod methods [];
+ //to store byte code method using Axis 1.x codes
+ private MethodTable methodTable;
+
+ public static String METHOD_REQUEST_WRAPPER = "Request";
+ public static String METHOD_RESPONSE_WRAPPER = "Response";
+ public static String TARGET_NAMESPACE = "http://org.apache.axis2/";
+ public static String SCHEMA_TARGET_NAMESPACE = "http://org.apache.axis2/xsd";
+ public static String SCHEMA_NAMESPACE_PRFIX = "ns1";
+ public static String TARGET_NAMESPACE_PREFIX = "tns";
+ private String schemaTargetNameSpace;
+ private String schema_namespace_prefix;
+
+ public SchemaGenerator(ClassLoader loader, String className,
+ String schematargetNamespace,
+ String schematargetNamespacePrefix)
+ throws Exception {
+ this.classLoader = loader;
+ this.className = className;
+// TARGET_NAMESPACE = "http://" + className;
+ if (schematargetNamespace != null && !schematargetNamespace.trim().equals("")) {
+ this.schemaTargetNameSpace = schematargetNamespace;
+ } else {
+ this.schemaTargetNameSpace = SCHEMA_TARGET_NAMESPACE;
+ }
+ if (schematargetNamespacePrefix != null && !schematargetNamespacePrefix.trim().equals("")) {
+ this.schema_namespace_prefix = schematargetNamespacePrefix;
+ } else {
+ this.schema_namespace_prefix = SCHEMA_NAMESPACE_PRFIX;
+ }
+ Hashtable prefixmap = new Hashtable();
+ prefixmap.put(this.schema_namespace_prefix, this.schemaTargetNameSpace);
+
+ XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
+
+ schema = new XmlSchema(this.schemaTargetNameSpace, schemaCollection);
+// schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
+ schema.setPrefixToNamespaceMap(prefixmap);
+ this.typeTable = new TypeTable();
+
+ Class clazz = Class.forName(className, true, loader);
+ methodTable = new MethodTable(clazz);
+ }
+
+ /**
+ * Generates schema for all the parameters in method. First generates schema
+ * for all different parameter type and later refers to them.
+ *
+ * @return Returns XmlSchema.
+ * @throws Exception
+ */
+ public XmlSchema generateSchema() throws Exception {
+
+ JamServiceFactory factory = JamServiceFactory.getInstance();
+ JamServiceParams jam_service_parms = factory.createServiceParams();
+ //setting the classLoder
+// jam_service_parms.setParentClassLoader(factory.createJamClassLoader(classLoader));
+ //it can posible to add the classLoader as well
+ jam_service_parms.addClassLoader(classLoader);
+ jam_service_parms.includeClass(className);
+ JamService service = factory.createService(jam_service_parms);
+
+ JamClassIterator jClassIter = service.getClasses();
+ //all most all the time the ittr will have only one class in it
+ while (jClassIter.hasNext()) {
+ JClass jclass = (JClass) jClassIter.next();
+ // serviceName = jclass.getSimpleName();
+ //todo in the future , when we support annotation we can use this
+ //JAnnotation[] annotations = jclass.getAnnotations();
+
+ /**
+ * Schema genertaion done in two stage
+ * 1. Load all the methods and create type for methods parameters (if the parameters are
+ * Bean then it will create Complex types for those , and if the parameters are simple
+ * type which decribe in SimpleTypeTable nothing will happen)
+ * 2. In the next stage for all the methods messages and port types will be
+ * creteated
+ */
+ methods = jclass.getDeclaredMethods();
+
+ // since we do not support overload
+ HashMap uniqueMethods = new HashMap();
+
+ for (int i = 0; i < methods.length; i++) {
+ JMethod jMethod = methods[i];
+ //no need to think abt this method , since that is system config method
+ if (jMethod.getSimpleName().equals("init"))
+ continue;
+ if (uniqueMethods.get(jMethod.getSimpleName()) != null) {
+ throw new Exception(" Sorry we don't support methods overloading !!!! ");
+ }
+
+ if (!jMethod.isPublic()) {
+ // no need to generate Schema for non public methods
+ continue;
+ }
+ uniqueMethods.put(jMethod.getSimpleName(), jMethod);
+
+ //it can easily get the annotations
+// jMethod.getAnnotations();
+ JParameter [] paras = jMethod.getParameters();
+ for (int j = 0; j < paras.length; j++) {
+ JParameter methodParameter = paras[j];
+ JClass paraType = methodParameter.getType();
+ String classTypeName = paraType.getQualifiedName();
+ if (paraType.isArrayType()) {
+ classTypeName = paraType.getArrayComponentType().getQualifiedName();
+ if (!typeTable.isSimpleType(classTypeName)) {
+ generateSchema(paraType.getArrayComponentType());
+ }
+ } else {
+ if (!typeTable.isSimpleType(classTypeName)) {
+ generateSchema(methodParameter.getType());
+ }
+ }
+ /**
+ * 1. have to check whethet its a simple type
+ * 2. then to check whther its a simple type array
+ * 3. OM elemney
+ * 4. Bean
+ */
+
+ }
+ // for its return type
+ JClass retuenType = jMethod.getReturnType();
+ if (!retuenType.isVoidType()) {
+ if (retuenType.isArrayType()) {
+ String returnTypeName = retuenType.getArrayComponentType().getQualifiedName();
+ if (!typeTable.isSimpleType(returnTypeName)) {
+ generateSchema(retuenType.getArrayComponentType());
+ }
+ } else {
+ if (!typeTable.isSimpleType(retuenType.getQualifiedName())) {
+ generateSchema(retuenType);
+ }
+ }
+ }
+
+ }
+ generateWrapperElements(methods);
+ }
+ return schema;
+ }
+
+ /**
+ * Generates wrapper element. If a method takes more than one parameter
+ * e.g. foo(Type1 para1, Type2 para2){} creates a Wrapper element like
+ * <element name="fooInParameter type="tns:fooInParameterElement"">
+ * <complexType name="fooInParameterElement">
+ * <sequnce>
+ * <element name="para1" type="tns:Type1">
+ * <element name="para2" type="tns:Type2">
+ * </sequnce>
+ * </complexType>
+ * </element>
+ */
+ private void generateWrapperElements(JMethod methods[]) {
+ for (int i = 0; i < methods.length; i++) {
+ JMethod method = methods[i];
+ if (method.getSimpleName().equals("init"))
+ continue;
+ if (!method.isPublic())
+ continue;
+ genereteWrapperElementforMethod(method);
+ }
+ }
+
+ private void genereteWrapperElementforMethod(JMethod method) {
+ String methodName = method.getSimpleName();
+ XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema);
+ XmlSchemaSequence sequence = new XmlSchemaSequence();
+
+ XmlSchemaElement eltOuter = new XmlSchemaElement();
+ eltOuter.setName(methodName + METHOD_REQUEST_WRAPPER);
+// String complexTypeName = methodName + METHOD_REQUEST_WRAPPER;
+// complexType.setName(complexTypeName);
+ schema.getItems().add(eltOuter);
+// schema.getItems().add(complexType);
+// eltOuter.setSchemaTypeName(complexType.getQName());
+ eltOuter.setSchemaType(complexType);
+ // adding this type to the table
+ QName elementName = new QName(this.schemaTargetNameSpace,
+ eltOuter.getName(), this.schema_namespace_prefix);
+ typeTable.addComplexSchema(methodName + METHOD_REQUEST_WRAPPER, elementName);
+
+ JParameter [] paras = method.getParameters();
+ if (paras.length > 0) {
+ complexType.setParticle(sequence);
+ }
+ String parameterNames [] = null;
+ if (paras.length > 0) {
+ parameterNames = methodTable.getParameterNames(methodName);
+ }
+ for (int j = 0; j < paras.length; j++) {
+ JParameter methodParameter = paras[j];
+ String paraName = methodParameter.getSimpleName();
+ String classTypeName = methodParameter.getType().getQualifiedName();
+ boolean isArryType = methodParameter.getType().isArrayType();
+ if (isArryType) {
+ classTypeName = methodParameter.getType().getArrayComponentType().getQualifiedName();
+ }
+
+ if (parameterNames != null) {
+ paraName = parameterNames[j];
+ }
+
+ if (typeTable.isSimpleType(classTypeName)) {
+ XmlSchemaElement elt1 = new XmlSchemaElement();
+ elt1.setName(paraName);
+ elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(classTypeName));
+ sequence.getItems().add(elt1);
+ if (isArryType) {
+ elt1.setMaxOccurs(Long.MAX_VALUE);
+ elt1.setMinOccurs(0);
+ }
+ } else {
+ XmlSchemaElement elt1 = new XmlSchemaElement();
+ elt1.setName(paraName);
+ elt1.setSchemaTypeName(typeTable.getComplexSchemaType(classTypeName));
+ sequence.getItems().add(elt1);
+ if (isArryType) {
+ elt1.setMaxOccurs(Long.MAX_VALUE);
+ elt1.setMinOccurs(0);
+ }
+ }
+ }
+
+ //generating wrapper element for retuen element
+ JClass methodReturnType = method.getReturnType();
+ generateWrapperforReturnType(methodReturnType, methodName);
+
+ }
+
+ private void generateWrapperforReturnType(JClass retuenType, String methodName) {
+ if (!retuenType.isVoidType()) {
+ XmlSchemaComplexType retuen_com_type = new XmlSchemaComplexType(schema);
+ XmlSchemaElement ret_eltOuter = new XmlSchemaElement();
+ ret_eltOuter.setName(methodName + METHOD_RESPONSE_WRAPPER);
+ schema.getItems().add(ret_eltOuter);
+ ret_eltOuter.setSchemaType(retuen_com_type);
+ QName ret_comTypeName = new QName(this.schemaTargetNameSpace,
+ ret_eltOuter.getName(), this.schema_namespace_prefix);
+ typeTable.addComplexSchema(methodName + METHOD_RESPONSE_WRAPPER, ret_comTypeName);
+ String classTypeName = retuenType.getQualifiedName();
+ boolean isArryType = retuenType.isArrayType();
+ XmlSchemaSequence sequence = new XmlSchemaSequence();
+ retuen_com_type.setParticle(sequence);
+ if (isArryType) {
+ classTypeName = retuenType.getArrayComponentType().getQualifiedName();
+ }
+ if (typeTable.isSimpleType(classTypeName)) {
+ XmlSchemaElement elt1 = new XmlSchemaElement();
+ elt1.setName("return");
+ elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(classTypeName));
+ sequence.getItems().add(elt1);
+ if (isArryType) {
+ elt1.setMaxOccurs(Long.MAX_VALUE);
+ elt1.setMinOccurs(0);
+ }
+ } else {
+ XmlSchemaElement elt1 = new XmlSchemaElement();
+ elt1.setName("return");
+ elt1.setSchemaTypeName(typeTable.getComplexSchemaType(classTypeName));
+ sequence.getItems().add(elt1);
+ if (isArryType) {
+ elt1.setMaxOccurs(Long.MAX_VALUE);
+ elt1.setMinOccurs(0);
+ }
+ }
+ }
+ }
+
+ /**
+ * JAM convert first name of an attribute into UpperCase as an example
+ * if there is a instance variable called foo in a bean , then Jam give that as Foo
+ * so this method is to correct that error
+ *
+ * @param wrongName
+ * @return the right name, using english as the locale for case conversion
+ */
+ public static String getCorrectName(String wrongName) {
+ if (wrongName.length() > 1) {
+ return wrongName.substring(0, 1).toLowerCase(Locale.ENGLISH)
+ + wrongName.substring(1, wrongName.length());
+ } else {
+ return wrongName.substring(0, 1).toLowerCase(Locale.ENGLISH);
+ }
+ }
+
+ private void generateSchema(JClass javaType) {
+ String name = javaType.getQualifiedName();
+ if (typeTable.getComplexSchemaType(name) == null) {
+ String simpleName = javaType.getSimpleName();
+
+ XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema);
+ XmlSchemaSequence sequence = new XmlSchemaSequence();
+
+ XmlSchemaElement eltOuter = new XmlSchemaElement();
+ QName elemntName = new QName(this.schemaTargetNameSpace, simpleName, this.schema_namespace_prefix);
+ eltOuter.setName(simpleName);
+ eltOuter.setQName(elemntName);
+ complexType.setParticle(sequence);
+ complexType.setName(simpleName);
+
+ schema.getItems().add(eltOuter);
+ schema.getItems().add(complexType);
+ eltOuter.setSchemaTypeName(complexType.getQName());
+// System.out.println("QNAme: " + eltOuter.getQName().getPrefix());
+
+ // adding this type to the table
+ // typeTable.addComplexScheam(name, complexType.getQName());
+ typeTable.addComplexSchema(name, eltOuter.getQName());
+
+ JProperty [] properties = javaType.getDeclaredProperties();
+ for (int i = 0; i < properties.length; i++) {
+ JProperty property = properties[i];
+ String propertyName = property.getType().getQualifiedName();
+ boolean isArryType = property.getType().isArrayType();
+ if (isArryType) {
+ propertyName = property.getType().getArrayComponentType().getQualifiedName();
+ }
+ if (typeTable.isSimpleType(propertyName)) {
+ XmlSchemaElement elt1 = new XmlSchemaElement();
+ elt1.setName(getCorrectName(property.getSimpleName()));
+ elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(propertyName));
+ sequence.getItems().add(elt1);
+ if (isArryType) {
+ elt1.setMaxOccurs(Long.MAX_VALUE);
+ elt1.setMinOccurs(0);
+ }
+ } else {
+ if (isArryType) {
+ generateSchema(property.getType().getArrayComponentType());
+ } else {
+ generateSchema(property.getType());
+ }
+ XmlSchemaElement elt1 = new XmlSchemaElement();
+ elt1.setName(getCorrectName(property.getSimpleName()));
+ elt1.setSchemaTypeName(typeTable.getComplexSchemaType(propertyName));
+ sequence.getItems().add(elt1);
+ if (isArryType) {
+ elt1.setMaxOccurs(Long.MAX_VALUE);
+ elt1.setMinOccurs(0);
+ }
+ }
+ }
+ }
+ }
+
+ public TypeTable getTypeTable() {
+ return typeTable;
+ }
+
+ public JMethod[] getMethods() {
+ return methods;
+ }
+
+ }
+
Added: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ChainedParamReader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ChainedParamReader.java?rev=389081&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ChainedParamReader.java (added)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ChainedParamReader.java Mon Mar 27 01:26:40 2006
@@ -0,0 +1,102 @@
+package org.apache.ws.java2wsdl.bytecode;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Description: In ParamReader class, user cannot get inherited method parameter
+ * from the class they passed in for performance reasons This class
+ * is walks up the inheritance chain. If the method is not found in
+ * the derived class, search in super class. If not found in the immedidate super
+ * class, search super class's super class, until the root, which is java.lang.Object,
+ * is reached. This is not an eager load since it only start searching the super class
+ * when it is asked to.
+ */
+public class ChainedParamReader {
+ private List chain = new ArrayList();
+ private List clsChain = new ArrayList();
+ private Map methodToParamMap = new HashMap();
+
+ /**
+ * Processes a given class's parameter names.
+ *
+ * @param cls the class which user wants to get parameter info from
+ * @throws IOException
+ */
+ public ChainedParamReader(Class cls) throws IOException {
+ ParamReader reader = new ParamReader(cls);
+ chain.add(reader);
+ clsChain.add(cls);
+ }
+
+ //now I need to create deligate methods
+
+ /**
+ * Returns the names of the declared parameters for the given constructor.
+ * If we cannot determine the names, return null. The returned array will
+ * have one name per parameter. The length of the array will be the same
+ * as the length of the Class[] array returned by Constructor.getParameterTypes().
+ *
+ * @param ctor
+ * @return Returns array of names, one per parameter, or null
+ */
+ public String[] getParameterNames(Constructor ctor) {
+ //there is no need for the constructor chaining.
+ return ((ParamReader) chain.get(0)).getParameterNames(ctor);
+ }
+
+ /**
+ * Returns the names of the declared parameters for the given method.
+ * If cannot determine the names in the current class, search its parent
+ * class until we reach java.lang.Object. If still can not find the method,
+ * returns null. The returned array has one name per parameter. The length
+ * of the array will be the same as the length of the Class[] array
+ * returned by Method.getParameterTypes().
+ *
+ * @param method
+ * @return String[] Returns array of names, one per parameter, or null
+ */
+ public String[] getParameterNames(Method method) {
+ //go find the one from the cache first
+ if (methodToParamMap.containsKey(method)) {
+ return (String[]) methodToParamMap.get(method);
+ }
+
+ String[] ret = null;
+ for (Iterator it = chain.iterator(); it.hasNext();) {
+ ParamReader reader = (ParamReader) it.next();
+ ret = reader.getParameterNames(method);
+ if (ret != null) {
+ methodToParamMap.put(method, ret);
+ return ret;
+ }
+ }
+ //if we here, it means we need to create new chain.
+ Class cls = (Class) clsChain.get(chain.size() - 1);
+ while (cls != null && cls != java.lang.Object.class && cls.getSuperclass() != null) {
+ Class superClass = cls.getSuperclass();
+ try {
+ ParamReader _reader = new ParamReader(superClass);
+ chain.add(_reader);
+ clsChain.add(cls);
+ ret = _reader.getParameterNames(method);
+ if (ret != null) { //we found it so just return it.
+ methodToParamMap.put(method, ret);
+ return ret;
+ }
+ } catch (IOException e) {
+ //can not find the super class in the class path, abort here
+ return null;
+ }
+ cls = superClass;
+ }
+ methodToParamMap.put(method, ret);
+ return null;
+ }
+}
Added: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ClassReader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ClassReader.java?rev=389081&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ClassReader.java (added)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ClassReader.java Mon Mar 27 01:26:40 2006
@@ -0,0 +1,413 @@
+package org.apache.ws.java2wsdl.bytecode;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This is the class file reader for obtaining the parameter names
+ * for declared methods in a class. The class must have debugging
+ * attributes for us to obtain this information. <p>
+ * <p/>
+ * This does not work for inherited methods. To obtain parameter
+ * names for inherited methods, you must use a paramReader for the
+ * class that originally declared the method. <p>
+ * <p/>
+ * don't get tricky, it's the bare minimum. Instances of this class
+ * are not threadsafe -- don't share them. <p>
+ */
+public class ClassReader extends ByteArrayInputStream {
+ // constants values that appear in java class files,
+ // from jvm spec 2nd ed, section 4.4, pp 103
+ private final int CONSTANT_Class = 7;
+ private final int CONSTANT_Fieldref = 9;
+ private final int CONSTANT_Methodref = 10;
+ private final int CONSTANT_InterfaceMethodref = 11;
+ private final int CONSTANT_String = 8;
+ private final int CONSTANT_Integer = 3;
+ private final int CONSTANT_Float = 4;
+ private final int CONSTANT_Long = 5;
+ private final int CONSTANT_Double = 6;
+ private final int CONSTANT_NameAndType = 12;
+ private final int CONSTANT_Utf8 = 1;
+ /**
+ * the constant pool. constant pool indices in the class file
+ * directly index into this array. The value stored in this array
+ * is the position in the class file where that constant begins.
+ */
+ private int[] cpoolIndex;
+ private Object[] cpool;
+
+ private Map attrMethods;
+
+ /**
+ * Loads the bytecode for a given class, by using the class's defining
+ * classloader and assuming that for a class named P.C, the bytecodes are
+ * in a resource named /P/C.class.
+ *
+ * @param c the class of interest
+ * @return Returns a byte array containing the bytecode
+ * @throws IOException
+ */
+ protected static byte[] getBytes(Class c) throws IOException {
+ InputStream fin = c.getResourceAsStream('/' + c.getName().replace('.', '/') + ".class");
+ if (fin == null) {
+ throw new IOException("Unable to load bytecode for class " + c.getName()
+ );
+ }
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buf = new byte[1024];
+ int actual;
+ do {
+ actual = fin.read(buf);
+ if (actual > 0) {
+ out.write(buf, 0, actual);
+ }
+ } while (actual > 0);
+ return out.toByteArray();
+ } finally {
+ fin.close();
+ }
+ }
+
+ static String classDescriptorToName(String desc) {
+ return desc.replace('/', '.');
+ }
+
+ protected static Map findAttributeReaders(Class c) {
+ HashMap map = new HashMap();
+ Method[] methods = c.getMethods();
+
+ for (int i = 0; i < methods.length; i++) {
+ String name = methods[i].getName();
+ if (name.startsWith("read") && methods[i].getReturnType() == void.class) {
+ map.put(name.substring(4), methods[i]);
+ }
+ }
+
+ return map;
+ }
+
+
+ protected static String getSignature(Member method, Class[] paramTypes) {
+ // compute the method descriptor
+
+ StringBuffer b = new StringBuffer((method instanceof Method) ? method.getName() : "<init>");
+ b.append('(');
+
+ for (int i = 0; i < paramTypes.length; i++) {
+ addDescriptor(b, paramTypes[i]);
+ }
+
+ b.append(')');
+ if (method instanceof Method) {
+ addDescriptor(b, ((Method) method).getReturnType());
+ } else if (method instanceof Constructor) {
+ addDescriptor(b, void.class);
+ }
+
+ return b.toString();
+ }
+
+ private static void addDescriptor(StringBuffer b, Class c) {
+ if (c.isPrimitive()) {
+ if (c == void.class)
+ b.append('V');
+ else if (c == int.class)
+ b.append('I');
+ else if (c == boolean.class)
+ b.append('Z');
+ else if (c == byte.class)
+ b.append('B');
+ else if (c == short.class)
+ b.append('S');
+ else if (c == long.class)
+ b.append('J');
+ else if (c == char.class)
+ b.append('C');
+ else if (c == float.class)
+ b.append('F');
+ else if (c == double.class) b.append('D');
+ } else if (c.isArray()) {
+ b.append('[');
+ addDescriptor(b, c.getComponentType());
+ } else {
+ b.append('L').append(c.getName().replace('.', '/')).append(';');
+ }
+ }
+
+
+ /**
+ * @return Returns the next unsigned 16 bit value.
+ */
+ protected final int readShort() {
+ return (read() << 8) | read();
+ }
+
+ /**
+ * @return Returns the next signed 32 bit value.
+ */
+ protected final int readInt() {
+ return (read() << 24) | (read() << 16) | (read() << 8) | read();
+ }
+
+ /**
+ * Skips n bytes in the input stream.
+ */
+ protected void skipFully(int n) throws IOException {
+ while (n > 0) {
+ int c = (int) skip(n);
+ if (c <= 0)
+ throw new EOFException("Error looking for paramter names in bytecode: unexpected end of file");
+ n -= c;
+ }
+ }
+
+ protected final Member resolveMethod(int index) throws IOException, ClassNotFoundException, NoSuchMethodException {
+ int oldPos = pos;
+ try {
+ Member m = (Member) cpool[index];
+ if (m == null) {
+ pos = cpoolIndex[index];
+ Class owner = resolveClass(readShort());
+ NameAndType nt = resolveNameAndType(readShort());
+ String signature = nt.name + nt.type;
+ if (nt.name.equals("<init>")) {
+ Constructor[] ctors = owner.getConstructors();
+ for (int i = 0; i < ctors.length; i++) {
+ String sig = getSignature(ctors[i], ctors[i].getParameterTypes());
+ if (sig.equals(signature)) {
+ cpool[index] = m = ctors[i];
+ return m;
+ }
+ }
+ } else {
+ Method[] methods = owner.getDeclaredMethods();
+ for (int i = 0; i < methods.length; i++) {
+ String sig = getSignature(methods[i], methods[i].getParameterTypes());
+ if (sig.equals(signature)) {
+ cpool[index] = m = methods[i];
+ return m;
+ }
+ }
+ }
+ throw new NoSuchMethodException(signature);
+ }
+ return m;
+ } finally {
+ pos = oldPos;
+ }
+
+ }
+
+ protected final Field resolveField(int i) throws IOException, ClassNotFoundException, NoSuchFieldException {
+ int oldPos = pos;
+ try {
+ Field f = (Field) cpool[i];
+ if (f == null) {
+ pos = cpoolIndex[i];
+ Class owner = resolveClass(readShort());
+ NameAndType nt = resolveNameAndType(readShort());
+ cpool[i] = f = owner.getDeclaredField(nt.name);
+ }
+ return f;
+ } finally {
+ pos = oldPos;
+ }
+ }
+
+ private static class NameAndType {
+ String name;
+ String type;
+
+ public NameAndType(String name, String type) {
+ this.name = name;
+ this.type = type;
+ }
+ }
+
+ protected final NameAndType resolveNameAndType(int i) throws IOException {
+ int oldPos = pos;
+ try {
+ NameAndType nt = (NameAndType) cpool[i];
+ if (nt == null) {
+ pos = cpoolIndex[i];
+ String name = resolveUtf8(readShort());
+ String type = resolveUtf8(readShort());
+ cpool[i] = nt = new NameAndType(name, type);
+ }
+ return nt;
+ } finally {
+ pos = oldPos;
+ }
+ }
+
+
+ protected final Class resolveClass(int i) throws IOException, ClassNotFoundException {
+ int oldPos = pos;
+ try {
+ Class c = (Class) cpool[i];
+ if (c == null) {
+ pos = cpoolIndex[i];
+ String name = resolveUtf8(readShort());
+ cpool[i] = c = Class.forName(classDescriptorToName(name));
+ }
+ return c;
+ } finally {
+ pos = oldPos;
+ }
+ }
+
+ protected final String resolveUtf8(int i) throws IOException {
+ int oldPos = pos;
+ try {
+ String s = (String) cpool[i];
+ if (s == null) {
+ pos = cpoolIndex[i];
+ int len = readShort();
+ skipFully(len);
+ cpool[i] = s = new String(buf, pos - len, len, "utf-8");
+ }
+ return s;
+ } finally {
+ pos = oldPos;
+ }
+ }
+
+ protected final void readCpool() throws IOException {
+ int count = readShort(); // cpool count
+ cpoolIndex = new int[count];
+ cpool = new Object[count];
+ for (int i = 1; i < count; i++) {
+ int c = read();
+ cpoolIndex[i] = super.pos;
+ switch (c) // constant pool tag
+ {
+ case CONSTANT_Fieldref:
+ case CONSTANT_Methodref:
+ case CONSTANT_InterfaceMethodref:
+ case CONSTANT_NameAndType:
+
+ readShort(); // class index or (12) name index
+ // fall through
+
+ case CONSTANT_Class:
+ case CONSTANT_String:
+
+ readShort(); // string index or class index
+ break;
+
+ case CONSTANT_Long:
+ case CONSTANT_Double:
+
+ readInt(); // hi-value
+
+ // see jvm spec section 4.4.5 - double and long cpool
+ // entries occupy two "slots" in the cpool table.
+ i++;
+ // fall through
+
+ case CONSTANT_Integer:
+ case CONSTANT_Float:
+
+ readInt(); // value
+ break;
+
+ case CONSTANT_Utf8:
+
+ int len = readShort();
+ skipFully(len);
+ break;
+
+ default:
+ // corrupt class file
+ throw new IllegalStateException("Error looking for paramter names in bytecode: unexpected bytes in file");
+ }
+ }
+ }
+
+ protected final void skipAttributes() throws IOException {
+ int count = readShort();
+ for (int i = 0; i < count; i++) {
+ readShort(); // name index
+ skipFully(readInt());
+ }
+ }
+
+ /**
+ * Reads an attributes array. The elements of a class file that
+ * can contain attributes are: fields, methods, the class itself,
+ * and some other types of attributes.
+ */
+ protected final void readAttributes() throws IOException {
+ int count = readShort();
+ for (int i = 0; i < count; i++) {
+ int nameIndex = readShort(); // name index
+ int attrLen = readInt();
+ int curPos = pos;
+
+ String attrName = resolveUtf8(nameIndex);
+
+ Method m = (Method) attrMethods.get(attrName);
+
+ if (m != null) {
+ try {
+ m.invoke(this, new Object[]{});
+ } catch (IllegalAccessException e) {
+ pos = curPos;
+ skipFully(attrLen);
+ } catch (InvocationTargetException e) {
+ try {
+ throw e.getTargetException();
+ } catch (Error ex) {
+ throw ex;
+ } catch (RuntimeException ex) {
+ throw ex;
+ } catch (IOException ex) {
+ throw ex;
+ } catch (Throwable ex) {
+ pos = curPos;
+ skipFully(attrLen);
+ }
+ }
+ } else {
+ // don't care what attribute this is
+ skipFully(attrLen);
+ }
+ }
+ }
+
+ /**
+ * Reads a code attribute.
+ *
+ * @throws IOException
+ */
+ public void readCode() throws IOException {
+ readShort(); // max stack
+ readShort(); // max locals
+ skipFully(readInt()); // code
+ skipFully(8 * readShort()); // exception table
+
+ // read the code attributes (recursive). This is where
+ // we will find the LocalVariableTable attribute.
+ readAttributes();
+ }
+
+ protected ClassReader(byte buf[], Map attrMethods) {
+ super(buf);
+
+ this.attrMethods = attrMethods;
+ }
+}
+
Added: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/MethodTable.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/MethodTable.java?rev=389081&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/MethodTable.java (added)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/MethodTable.java Mon Mar 27 01:26:40 2006
@@ -0,0 +1,56 @@
+package org.apache.ws.java2wsdl.bytecode;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+/*
+* Copyright 2004,2005 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.
+*
+*/
+
+public class MethodTable {
+
+ private HashMap nameToMethodMap;
+ private ChainedParamReader cpr;
+
+ public MethodTable(Class cls) throws Exception {
+ cpr = new ChainedParamReader(cls);
+ nameToMethodMap = new HashMap();
+ loadMethods(cls);
+ }
+
+ /**
+ * To load all the methods in the given class by Java reflection
+ *
+ * @param cls
+ * @throws Exception
+ */
+ private void loadMethods(Class cls) throws Exception {
+ Method [] methods = cls.getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ Method method = methods[i];
+ nameToMethodMap.put(method.getName(), method);
+ }
+ }
+
+ public String [] getParameterNames(String methodName) {
+ Method method = (Method) nameToMethodMap.get(methodName);
+ if (method == null) {
+ return null;
+ }
+ return cpr.getParameterNames(method);
+ }
+
+
+}
Added: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ParamNameExtractor.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ParamNameExtractor.java?rev=389081&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ParamNameExtractor.java (added)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ParamNameExtractor.java Mon Mar 27 01:26:40 2006
@@ -0,0 +1,47 @@
+package org.apache.ws.java2wsdl.bytecode;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * This class retrieves function parameter names from bytecode built with
+ * debugging symbols. Used as a last resort when creating WSDL.
+ */
+public class ParamNameExtractor {
+
+ protected static Log log = LogFactory.getLog(ParamNameExtractor.class.getName());
+
+ /**
+ * Retrieves a list of function parameter names from a method.
+ * Returns null if unable to read parameter names (i.e. bytecode not
+ * built with debug).
+ */
+ public static String[] getParameterNamesFromDebugInfo(Method method) {
+ // Don't worry about it if there are no params.
+ int numParams = method.getParameterTypes().length;
+ if (numParams == 0)
+ return null;
+
+ // get declaring class
+ Class c = method.getDeclaringClass();
+
+ // Don't worry about it if the class is a Java dynamic proxy
+ if (Proxy.isProxyClass(c)) {
+ return null;
+ }
+
+ try {
+ // get a parameter reader
+ ParamReader pr = new ParamReader(c);
+ // get the parameter names
+ return pr.getParameterNames(method);
+ } catch (IOException e) {
+ // log it and leave
+ return null;
+ }
+ }
+}
Added: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ParamReader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ParamReader.java?rev=389081&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ParamReader.java (added)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/bytecode/ParamReader.java Mon Mar 27 01:26:40 2006
@@ -0,0 +1,205 @@
+package org.apache.ws.java2wsdl.bytecode;
+
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This is the class file reader for obtaining the parameter names
+ * for declared methods in a class. The class must have debugging
+ * attributes for us to obtain this information. <p>
+ * <p/>
+ * This does not work for inherited methods. To obtain parameter
+ * names for inherited methods, you must use a paramReader for the
+ * class that originally declared the method. <p>
+ * <p/>
+ * don't get tricky, it's the bare minimum. Instances of this class
+ * are not threadsafe -- don't share them. <p>
+ */
+public class ParamReader
+ extends ClassReader {
+ private String methodName;
+ private Map methods = new HashMap();
+ private Class[] paramTypes;
+
+ /**
+ * Processes a class file, given it's class. We'll use the defining
+ * classloader to locate the bytecode.
+ *
+ * @param c
+ * @throws java.io.IOException
+ */
+ public ParamReader(Class c) throws IOException {
+ this(getBytes(c));
+ }
+
+ /**
+ * Processes the given class bytes directly.
+ *
+ * @param b
+ * @throws IOException
+ */
+ public ParamReader(byte[] b) throws IOException {
+ super(b, findAttributeReaders(ParamReader.class));
+
+ // check the magic number
+ if (readInt() != 0xCAFEBABE) {
+ // not a class file!
+ throw new IOException("Error looking for paramter names in bytecode: input does not appear to be a valid class file");
+ }
+
+ readShort(); // minor version
+ readShort(); // major version
+
+ readCpool(); // slurp in the constant pool
+
+ readShort(); // access flags
+ readShort(); // this class name
+ readShort(); // super class name
+
+ int count = readShort(); // ifaces count
+ for (int i = 0; i < count; i++) {
+ readShort(); // interface index
+ }
+
+ count = readShort(); // fields count
+ for (int i = 0; i < count; i++) {
+ readShort(); // access flags
+ readShort(); // name index
+ readShort(); // descriptor index
+ skipAttributes(); // field attributes
+ }
+
+ count = readShort(); // methods count
+ for (int i = 0; i < count; i++) {
+ readShort(); // access flags
+ int m = readShort(); // name index
+ String name = resolveUtf8(m);
+ int d = readShort(); // descriptor index
+ this.methodName = name + resolveUtf8(d);
+ readAttributes(); // method attributes
+ }
+
+ }
+
+ public void readCode() throws IOException {
+ readShort(); // max stack
+ int maxLocals = readShort(); // max locals
+
+ MethodInfo info = new MethodInfo(maxLocals);
+ if (methods != null && methodName != null) {
+ methods.put(methodName, info);
+ }
+
+ skipFully(readInt()); // code
+ skipFully(8 * readShort()); // exception table
+ // read the code attributes (recursive). This is where
+ // we will find the LocalVariableTable attribute.
+ readAttributes();
+ }
+
+ /**
+ * Returns the names of the declared parameters for the given constructor.
+ * If we cannot determine the names, return null. The returned array will
+ * have one name per parameter. The length of the array will be the same
+ * as the length of the Class[] array returned by Constructor.getParameterTypes().
+ *
+ * @param ctor
+ * @return Returns String[] array of names, one per parameter, or null
+ */
+ public String[] getParameterNames(Constructor ctor) {
+ paramTypes = ctor.getParameterTypes();
+ return getParameterNames(ctor, paramTypes);
+ }
+
+ /**
+ * Returns the names of the declared parameters for the given method.
+ * If we cannot determine the names, return null. The returned array will
+ * have one name per parameter. The length of the array will be the same
+ * as the length of the Class[] array returned by Method.getParameterTypes().
+ *
+ * @param method
+ * @return Returns String[] array of names, one per parameter, or null
+ */
+ public String[] getParameterNames(Method method) {
+ paramTypes = method.getParameterTypes();
+ return getParameterNames(method, paramTypes);
+ }
+
+ protected String[] getParameterNames(Member member, Class [] paramTypes) {
+ // look up the names for this method
+ MethodInfo info = (MethodInfo) methods.get(getSignature(member, paramTypes));
+
+ // we know all the local variable names, but we only need to return
+ // the names of the parameters.
+
+ if (info != null) {
+ String[] paramNames = new String[paramTypes.length];
+ int j = Modifier.isStatic(member.getModifiers()) ? 0 : 1;
+
+ boolean found = false; // did we find any non-null names
+ for (int i = 0; i < paramNames.length; i++) {
+ if (info.names[j] != null) {
+ found = true;
+ paramNames[i] = info.names[j];
+ }
+ j++;
+ if (paramTypes[i] == double.class || paramTypes[i] == long.class) {
+ // skip a slot for 64bit params
+ j++;
+ }
+ }
+
+ if (found) {
+ return paramNames;
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ private static class MethodInfo {
+ String[] names;
+ int maxLocals;
+
+ public MethodInfo(int maxLocals) {
+ this.maxLocals = maxLocals;
+ names = new String[maxLocals];
+ }
+ }
+
+ private MethodInfo getMethodInfo() {
+ MethodInfo info = null;
+ if (methods != null && methodName != null) {
+ info = (MethodInfo) methods.get(methodName);
+ }
+ return info;
+ }
+
+ /**
+ * This is invoked when a LocalVariableTable attribute is encountered.
+ *
+ * @throws IOException
+ */
+ public void readLocalVariableTable() throws IOException {
+ int len = readShort(); // table length
+ MethodInfo info = getMethodInfo();
+ for (int j = 0; j < len; j++) {
+ readShort(); // start pc
+ readShort(); // length
+ int nameIndex = readShort(); // name_index
+ readShort(); // descriptor_index
+ int index = readShort(); // local index
+ if (info != null) {
+ info.names[index] = resolveUtf8(nameIndex);
+ }
+ }
+ }
+}
Added: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLCommandLineOption.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLCommandLineOption.java?rev=389081&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLCommandLineOption.java (added)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLCommandLineOption.java Mon Mar 27 01:26:40 2006
@@ -0,0 +1,87 @@
+package org.apache.ws.java2wsdl.utils;
+
+import org.apache.ws.java2wsdl.Constants;
+
+import java.util.ArrayList;
+/*
+* Copyright 2004,2005 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.
+*
+*
+*/
+
+public class Java2WSDLCommandLineOption implements Constants {
+
+ private String type;
+ private ArrayList optionValues;
+
+ public Java2WSDLCommandLineOption(String type, String[] values) {
+ setOptionType(type);
+ ArrayList arrayList = new ArrayList(values.length);
+ for (int i = 0; i < values.length; i++) {
+ arrayList.add(values[i]);
+ }
+ this.optionValues = arrayList;
+ }
+
+ private void setOptionType(String type) {
+ //cater for the long options first
+ if (type.startsWith("--")) type = type.replaceFirst("--", "");
+ if (type.startsWith("-")) type = type.replaceFirst("-", "");
+ this.type = type;
+ }
+
+ /**
+ * @param type
+ */
+ public Java2WSDLCommandLineOption(String type, ArrayList values) {
+ setOptionType(type);
+
+ if (null != values) {
+ this.optionValues = values;
+ }
+ }
+
+
+ /**
+ * @return Returns the type.
+ * @see <code>CommandLineOptionConstans</code>
+ */
+ public String getOptionType() {
+ return type;
+ }
+
+
+ /**
+ * @return Returns the optionValues.
+ */
+ public String getOptionValue() {
+ if (optionValues != null)
+ return (String) optionValues.get(0);
+ else
+ return null;
+ }
+
+
+
+ /**
+ * @return Returns the optionValues.
+ */
+ public ArrayList getOptionValues() {
+ return optionValues;
+ }
+
+
+ }
+
Added: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLCommandLineOptionParser.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLCommandLineOptionParser.java?rev=389081&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLCommandLineOptionParser.java (added)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLCommandLineOptionParser.java Mon Mar 27 01:26:40 2006
@@ -0,0 +1,128 @@
+package org.apache.ws.java2wsdl.utils;
+
+import org.apache.ws.java2wsdl.utils.Java2WSDLCommandLineOption;
+import org.apache.ws.java2wsdl.Constants;
+
+import java.util.*;
+/*
+* Copyright 2004,2005 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.
+*
+*
+*/
+
+public class Java2WSDLCommandLineOptionParser implements Constants {
+ private static int STARTED = 0;
+ private static int NEW_OPTION = 1;
+ private static int SUB_PARAM_OF_OPTION = 2;
+
+ private Map commandLineOptions;
+
+ public Java2WSDLCommandLineOptionParser(Map commandLineOptions) {
+ this.commandLineOptions = commandLineOptions;
+ }
+
+ public Java2WSDLCommandLineOptionParser(String[] args) {
+ this.commandLineOptions = this.parse(args);
+
+ }
+
+ /**
+ * Return a list with <code>CommandLineOption</code> objects
+ *
+ * @param args
+ * @return CommandLineOption List
+ */
+ private Map parse(String[] args) {
+ Map commandLineOptions = new HashMap();
+
+ if (0 == args.length)
+ return commandLineOptions;
+
+ //State 0 means started
+ //State 1 means earlier one was a new -option
+ //State 2 means earlier one was a sub param of a -option
+
+ int state = STARTED;
+ ArrayList optionBundle = null;
+ String optionType = null;
+ Java2WSDLCommandLineOption commandLineOption;
+
+ for (int i = 0; i < args.length; i++) {
+
+ if (args[i].startsWith("-")) {
+ if (STARTED == state) {
+ // fresh one
+ state = NEW_OPTION;
+ optionType = args[i];
+ } else if (SUB_PARAM_OF_OPTION == state || NEW_OPTION == state) {
+ // new one but old one should be saved
+ commandLineOption =
+ new Java2WSDLCommandLineOption(optionType, optionBundle);
+ commandLineOptions.put(commandLineOption.getOptionType(),
+ commandLineOption);
+ state = NEW_OPTION;
+ optionType = args[i];
+ optionBundle = null;
+
+ }
+ } else {
+ if (STARTED == state) {
+ commandLineOption =
+ new Java2WSDLCommandLineOption(
+ SOLE_INPUT,
+ args);
+ commandLineOptions.put(commandLineOption.getOptionType(),
+ commandLineOption);
+ return commandLineOptions;
+
+ } else if (NEW_OPTION == state) {
+ optionBundle = new ArrayList();
+ optionBundle.add(args[i]);
+ state = SUB_PARAM_OF_OPTION;
+
+ } else if (SUB_PARAM_OF_OPTION == state) {
+ optionBundle.add(args[i]);
+ }
+
+ }
+
+
+ }
+
+ commandLineOption = new Java2WSDLCommandLineOption(optionType, optionBundle);
+ commandLineOptions.put(commandLineOption.getOptionType(), commandLineOption);
+ return commandLineOptions;
+ }
+
+ public Map getAllOptions() {
+ return this.commandLineOptions;
+ }
+
+ public List getInvalidOptions(Java2WSDLOptionsValidator validator) {
+ List faultList = new ArrayList();
+ Iterator iterator = this.commandLineOptions.values().iterator();
+ while (iterator.hasNext()) {
+ Java2WSDLCommandLineOption commandLineOption = ((Java2WSDLCommandLineOption) (iterator
+ .next()));
+ if (validator.isInvalid(commandLineOption)) {
+ faultList.add(commandLineOption);
+ }
+ }
+
+ return faultList;
+ }
+
+
+}
Added: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLOptionsValidator.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLOptionsValidator.java?rev=389081&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLOptionsValidator.java (added)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLOptionsValidator.java Mon Mar 27 01:26:40 2006
@@ -0,0 +1,59 @@
+package org.apache.ws.java2wsdl.utils;
+
+import org.apache.ws.java2wsdl.utils.Java2WSDLCommandLineOption;
+import org.apache.ws.java2wsdl.Constants;
+/*
+* Copyright 2004,2005 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.
+*
+* @author : Deepal Jayasinghe (deepal@apache.org)
+*
+*/
+
+public class Java2WSDLOptionsValidator implements Constants {
+ public boolean isInvalid(Java2WSDLCommandLineOption option) {
+ boolean invalid;
+ String optionType = option.getOptionType();
+
+ invalid = !((Java2WSDLConstants.CLASSNAME_OPTION).equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.OUTPUT_LOCATION_OPTION.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.OUTPUT_FILENAME_OPTION.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.CLASSPATH_OPTION.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.TARGET_NAMESPACE_OPTION.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.TARGET_NAMESPACE_PREFIX_OPTION.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_OPTION.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_PREFIX_OPTION.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.SERVICE_NAME_OPTION.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.STYLE_OPTION.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.USE_OPTION.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.LOCATION_OPTION.equalsIgnoreCase(optionType) ||
+
+ Java2WSDLConstants.CLASSNAME_OPTION_LONG.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.OUTPUT_FILENAME_OPTION_LONG.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.OUTPUT_LOCATION_OPTION_LONG.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.CLASSNAME_OPTION_LONG.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.CLASSPATH_OPTION_LONG.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.TARGET_NAMESPACE_OPTION_LONG.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.TARGET_NAMESPACE_PREFIX_OPTION_LONG.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_OPTION_LONG.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_PREFIX_OPTION_LONG.equalsIgnoreCase(optionType) ||
+ Java2WSDLConstants.SERVICE_NAME_OPTION_LONG.equalsIgnoreCase(optionType)||
+ Java2WSDLConstants.STYLE_OPTION_LONG.equalsIgnoreCase(optionType)||
+ Java2WSDLConstants.USE_OPTION_LONG.equalsIgnoreCase(optionType)||
+ Java2WSDLConstants.LOCATION_OPTION_LONG.equalsIgnoreCase(optionType));
+
+
+ return invalid;
+ }
+}
Added: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/TypeTable.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/TypeTable.java?rev=389081&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/TypeTable.java (added)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/TypeTable.java Mon Mar 27 01:26:40 2006
@@ -0,0 +1,123 @@
+package org.apache.ws.java2wsdl.utils;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.ws.java2wsdl.Constants;
+
+import javax.xml.namespace.QName;
+import java.util.*;
+/*
+* Copyright 2004,2005 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.
+*
+*
+*/
+
+public class TypeTable {
+ private HashMap simpleTypetoxsd;
+ private HashMap complecTypeMap;
+
+ public TypeTable() {
+ simpleTypetoxsd = new HashMap();
+ complecTypeMap = new HashMap();
+ populateSimpleTypes();
+ }
+
+ private void populateSimpleTypes() {
+ //todo pls use the types from org.apache.ws.commons.schema.constants.Constants
+ simpleTypetoxsd.put("int",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "int", "xs"));
+ simpleTypetoxsd.put("java.lang.String",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "string", "xs"));
+ simpleTypetoxsd.put("boolean",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "boolean", "xs"));
+ simpleTypetoxsd.put("float",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "float", "xs"));
+ simpleTypetoxsd.put("double",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "double", "xs"));
+ simpleTypetoxsd.put("short",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "short", "xs"));
+ simpleTypetoxsd.put("long",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "long", "xs"));
+ simpleTypetoxsd.put("byte",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "byte", "xs"));
+ simpleTypetoxsd.put("char",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "anyType", "xs"));
+ simpleTypetoxsd.put("java.lang.Integer",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "int", "xs"));
+ simpleTypetoxsd.put("java.lang.Double",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "double", "xs"));
+ simpleTypetoxsd.put("java.lang.Float",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "float", "xs"));
+ simpleTypetoxsd.put("java.lang.Long",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "long", "xs"));
+ simpleTypetoxsd.put("java.lang.Character",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "anyType", "xs"));
+ simpleTypetoxsd.put("java.lang.Boolean",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "boolean", "xs"));
+ simpleTypetoxsd.put("java.lang.Byte",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "byte", "xs"));
+ simpleTypetoxsd.put("java.lang.Short",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "short", "xs"));
+ simpleTypetoxsd.put("java.util.Date",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "dateTime", "xs"));
+ simpleTypetoxsd.put("java.util.Calendar",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "dateTime", "xs"));
+
+ simpleTypetoxsd.put("java.lang.Object",
+ new QName(Constants.URI_2001_SCHEMA_XSD, "anyType", "xs"));
+
+ // Any types
+ simpleTypetoxsd.put(OMElement.class.getName(),
+ new QName(Constants.URI_2001_SCHEMA_XSD, "anyType", "xs"));
+ simpleTypetoxsd.put(ArrayList.class.getName(),
+ new QName(Constants.URI_2001_SCHEMA_XSD, "anyType", "xs"));
+ simpleTypetoxsd.put(Vector.class.getName(),
+ new QName(Constants.URI_2001_SCHEMA_XSD, "anyType", "xs"));
+ simpleTypetoxsd.put(List.class.getName(),
+ new QName(Constants.URI_2001_SCHEMA_XSD, "anyType", "xs"));
+ }
+
+ public QName getSimpleSchemaTypeName(String typename) {
+ return (QName) simpleTypetoxsd.get(typename);
+ }
+
+ public boolean isSimpleType(String typeName) {
+ Iterator keys = simpleTypetoxsd.keySet().iterator();
+ while (keys.hasNext()) {
+ String s = (String) keys.next();
+ if (s.equals(typeName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void addComplexSchema(String name, QName schemaType) {
+ complecTypeMap.put(name, schemaType);
+ }
+
+ public QName getComplexSchemaType(String name) {
+ return (QName) complecTypeMap.get(name);
+ }
+
+ public QName getQNamefortheType(String typeName) {
+ QName type = getSimpleSchemaTypeName(typeName);
+ if (type == null) {
+ type = getComplexSchemaType(typeName);
+ }
+ return type;
+ }
+}
+
+
Modified: webservices/axis2/trunk/java/modules/saaj/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/project.xml?rev=389081&r1=389080&r2=389081&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/project.xml (original)
+++ webservices/axis2/trunk/java/modules/saaj/project.xml Mon Mar 27 01:26:40 2006
@@ -94,6 +94,11 @@
<version>${axiom.version}</version>
</dependency>
<dependency>
+ <groupId>axis2</groupId>
+ <artifactId>axis2-java2wsdl</artifactId>
+ <version>${pom.currentVersion}</version>
+ </dependency>
+ <dependency>
<groupId>ws-commons</groupId>
<artifactId>axiom-impl</artifactId>
<version>${axiom.version}</version>
Modified: webservices/axis2/trunk/java/modules/tool/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/tool/project.xml?rev=389081&r1=389080&r2=389081&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/tool/project.xml (original)
+++ webservices/axis2/trunk/java/modules/tool/project.xml Mon Mar 27 01:26:40 2006
@@ -35,11 +35,18 @@
<module>true</module>
</properties>
</dependency>
+
<dependency>
<groupId>axis2</groupId>
<artifactId>axis2-common</artifactId>
<version>${pom.currentVersion}</version>
</dependency>
+ <dependency>
+ <groupId>axis2</groupId>
+ <artifactId>axis2-wsdl</artifactId>
+ <version>${pom.currentVersion}</version>
+ </dependency>
+
<dependency>
<groupId>axis2</groupId>