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 aj...@apache.org on 2005/10/06 12:55:27 UTC
svn commit: r306583 [4/9] - in
/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2:
databinding/ databinding/gen/ databinding/gen/impl/
databinding/symbolTable/ databinding/toJava/ databinding/utils/
databinding/utils/support/ wsdl/codeg...
Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/symbolTable/Utils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/symbolTable/Utils.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/symbolTable/Utils.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/symbolTable/Utils.java Thu Oct 6 03:54:18 2005
@@ -0,0 +1,769 @@
+/*
+ * 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.axis2.databinding.symbolTable;
+
+//import org.apache.axis.Constants;
+//import org.apache.axis.utils.XMLUtils;
+import org.apache.axis2.databinding.Constants;
+import org.apache.axis2.databinding.utils.support.BooleanHolder;
+import org.apache.axis2.databinding.utils.XMLUtils;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ * This class contains static utility methods for the emitter.
+ *
+ * @author Rich Scheuerle (scheu@us.ibm.com)
+ * @author Tom Jordahl (tomj@macromedia.com)
+ */
+public class Utils {
+
+ /** cache of namespaces -> maps of localNames -> QNames */
+ static final Map nsmap = new HashMap();
+
+ /**
+ * Find or create a QName with the specified namespace/localName.
+ *
+ * @param namespace
+ * @param localName
+ * @return
+ */
+ static QName findQName(String namespace, String localName) {
+
+ QName qname = null;
+
+ // get the inner map, using the namespace as a key
+ Map ln2qn = (Map) nsmap.get(namespace);
+
+ if (null == ln2qn) { // cache miss
+ ln2qn = new HashMap();
+
+ nsmap.put(namespace, ln2qn);
+
+ qname = new QName(namespace, localName);
+
+ ln2qn.put(localName, qname);
+ } else { // cache hit
+ qname = (QName) ln2qn.get(localName);
+
+ if (null == qname) { // cache miss
+ qname = new QName(namespace, localName);
+
+ ln2qn.put(localName, qname);
+ } else {
+
+ // cache hit
+ }
+ }
+
+ return qname;
+ }
+
+ /**
+ * Given a node, return the value of the given attribute.
+ * If the attribute does not exist, searching continues through ancestor nodes until found.
+ * This method is useful for finding attributes that pertain to a group of contained
+ * nodes (i.e. xlmns, xmlns:tns, targetNamespace, name)
+ *
+ * @param node
+ * @param attr
+ * @return
+ */
+ public static String getScopedAttribute(Node node, String attr) {
+
+ if (node == null) {
+ return null;
+ }
+
+ if (node.getAttributes() == null) {
+ return getScopedAttribute(node.getParentNode(), attr);
+ }
+
+ Node attrNode = node.getAttributes().getNamedItem(attr);
+
+ if (attrNode != null) {
+ return attrNode.getNodeValue();
+ } else {
+ return getScopedAttribute(node.getParentNode(), attr);
+ }
+ }
+
+ /**
+ * Given a node, return the value of the given attribute.
+ * Returns null if the attribute is not found
+ *
+ * @param node
+ * @param attr
+ * @return
+ */
+ public static String getAttribute(Node node, String attr) {
+
+ if ((node == null) || (node.getAttributes() == null)) {
+ return null;
+ }
+
+ Node attrNode = node.getAttributes().getNamedItem(attr);
+
+ if (attrNode != null) {
+ return attrNode.getNodeValue();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Given a node, return the attributes that have the specified local name.
+ * Returns null if the attribute is not found
+ *
+ * @param node
+ * @param localName
+ * @return
+ */
+ public static Vector getAttributesWithLocalName(Node node,
+ String localName) {
+
+ Vector v = new Vector();
+
+ if (node == null) {
+ return v;
+ }
+
+ NamedNodeMap map = node.getAttributes();
+
+ if (map != null) {
+ for (int i = 0; i < map.getLength(); i++) {
+ Node attrNode = map.item(i);
+
+ if ((attrNode != null)
+ && attrNode.getLocalName().equals(localName)) {
+ v.add(attrNode);
+ }
+ }
+ }
+
+ return v;
+ }
+
+ /**
+ * An xml element may have a name.
+ * For example <.element name="foo" type="b:bar">.
+ * has the name "element". This routine gets the full QName of the element.
+ *
+ * @param node
+ * @return
+ */
+ public static QName getNodeQName(Node node) {
+
+ if (node == null) {
+ return null;
+ }
+
+ String localName = node.getLocalName();
+
+ if (localName == null) {
+ return null;
+ }
+
+ String namespace = node.getNamespaceURI();
+
+ return (findQName(namespace, localName));
+ }
+
+ /**
+ * XML nodes may have a name attribute.
+ * For example <.element name="foo" type="b:bar">.
+ * has the name attribute value "foo". This routine gets the QName of the name attribute value.
+ *
+ * @param node
+ * @return
+ */
+ public static QName getNodeNameQName(Node node) {
+
+ if (node == null) {
+ return null;
+ }
+
+ String localName = null;
+ String namespace = null;
+
+ // First try to get the name directly
+ localName = getAttribute(node, "name");
+
+ // If this fails and the node has a ref, use the ref name.
+ if (localName == null) {
+ QName ref = getTypeQNameFromAttr(node, "ref");
+
+ if (ref != null) {
+ localName = ref.getLocalPart();
+ namespace = ref.getNamespaceURI();
+ }
+ }
+
+ // This routine may be called for complexType elements. In some cases,
+ // the complexType may be anonymous, which is why the getScopedAttribute
+ // method is used.
+
+ Node search = node.getParentNode();
+
+ while (search != null) {
+ String ln = search.getLocalName();
+
+ if (ln.equals("schema")) {
+ search = null;
+ } else if (ln.equals("element")
+ || ln.equals("attribute")) {
+ localName = SymbolTable.ANON_TOKEN
+ + getNodeNameQName(search).getLocalPart();
+ search = null;
+ } else if (ln.equals("complexType")
+ || ln.equals("simpleType")) {
+ localName = getNodeNameQName(search).getLocalPart()
+ + SymbolTable.ANON_TOKEN + localName;
+ search = null;
+ } else {
+ search = search.getParentNode();
+ }
+ }
+
+ if (localName == null) {
+ return null;
+ }
+
+ // Build and return the QName
+ if (namespace == null) {
+ namespace = getScopedAttribute(node, "targetNamespace");
+ }
+
+ return (findQName(namespace, localName));
+ }
+
+ /**
+ * An XML element or attribute node has several ways of
+ * identifying the type of the element or attribute:
+ * - use the type attribute to reference a complexType/simpleType
+ * - use the ref attribute to reference another element, group or attributeGroup
+ * - use of an anonymous type (i.e. a nested type underneath itself)
+ * - a wsdl:part can use the element attribute.
+ * - an extension can use the base attribute.
+ * <p/>
+ * This routine returns a QName representing this "type".
+ * The forElement value is also returned to indicate whether the
+ * QName represents an element (i.e. obtained using the ref attribute)
+ * or a type.
+ * <p/>
+ * Other attributes affect the QName that is returned.
+ * If the "minOccurs" and "maxOccurs" are set such that the
+ * type is a collection of "types", then an artificial qname is
+ * returned to represent the collection.
+ *
+ * @param node of the reference
+ * @param forElement output parameter is set to true if QName is for an element
+ * (i.e. ref= or element= attribute was used).
+ * @param ignoreMaxOccurs indicates whether minOccurs/maxOccurs affects the QName
+ * @return QName representing the type of this element
+ */
+ public static QName getTypeQName(Node node, BooleanHolder forElement,
+ boolean ignoreMaxOccurs) {
+
+ if (node == null) {
+ return null;
+ }
+
+ forElement.value = false; // Assume QName returned is for a type
+
+ // Try getting the QName of the type attribute.
+ // Note this also retrieves the type if an anonymous type is used.
+ QName qName = getTypeQNameFromAttr(node, "type");
+
+ // If not successful, try using the ref attribute.
+ if (qName == null) {
+ String localName = node.getLocalName();
+
+ // bug 23145: support attributeGroup (Brook Richan)
+ // a ref can be for an element or attributeGroup
+ if ((localName != null)
+ && !(localName.equals("attributeGroup") ||
+ localName.equals("group") ||
+ localName.equals("list"))) {
+ forElement.value = true;
+ }
+
+ qName = getTypeQNameFromAttr(node, "ref");
+ }
+
+ // in case of a list get the itemType
+ if (qName == null) {
+ qName = getTypeQNameFromAttr(node, "itemType");
+ }
+
+ // If the node has "type"/"ref" and "maxOccurs" then the type is really
+ // a collection. There is no qname in the wsdl which we can use to represent
+ // the collection, so we need to invent one.
+ // The local part of the qname is changed to <local>[minOccurs, maxOccurs]
+ // The namespace uri is changed to the targetNamespace of this node
+ if (!ignoreMaxOccurs) {
+ if (qName != null) {
+ String maxOccursValue = getAttribute(node, "maxOccurs");
+ String minOccursValue = getAttribute(node, "minOccurs");
+
+ if (maxOccursValue == null) {
+ maxOccursValue = "1";
+ }
+
+ if (minOccursValue == null) {
+ minOccursValue = "1";
+ }
+
+ if (minOccursValue.equals("0") && maxOccursValue.equals("1")) {
+
+ // If we have a minoccurs="0"/maxoccurs="1", this is just
+ // like a nillable single value, so treat it as such.
+// qName = getNillableQName(qName);
+ } else if (!maxOccursValue.equals("1")
+ || !minOccursValue.equals("1")) {
+ String localPart = qName.getLocalPart();
+ String range = "[";
+ if (!minOccursValue.equals("1")) {
+ range += minOccursValue;
+ }
+ range += ",";
+ if (!maxOccursValue.equals("1")) {
+ range += maxOccursValue;
+ }
+ range += "]";
+ localPart += range;
+ qName = findQName(qName.getNamespaceURI(), localPart);
+ }
+ }
+ }
+
+ // A WSDL Part uses the element attribute instead of the ref attribute
+ if (qName == null) {
+ forElement.value = true;
+ qName = getTypeQNameFromAttr(node, "element");
+ }
+
+ // "base" references a "type"
+ if (qName == null) {
+ forElement.value = false;
+ qName = getTypeQNameFromAttr(node, "base");
+ }
+
+ return qName;
+ }
+
+ /**
+ * Method getMemberTypeQNames
+ *
+ * @param node
+ * @return
+ */
+ public static QName[] getMemberTypeQNames(Node node) {
+
+ String attribute = getAttribute(node, "memberTypes");
+
+ if (attribute == null) {
+ return null;
+ }
+
+ StringTokenizer tokenizer = new StringTokenizer(attribute, " ");
+ QName[] memberTypes = new QName[tokenizer.countTokens()];
+
+ for (int i = 0; tokenizer.hasMoreElements(); i++) {
+ String element = (String) tokenizer.nextElement();
+
+ memberTypes[i] = XMLUtils.getFullQNameFromString(element, node);
+ }
+
+ return memberTypes;
+ }
+
+ /**
+ * Gets the QName of the type of the node via the specified attribute
+ * name.
+ * <p/>
+ * If "type", the QName represented by the type attribute's value is
+ * returned. If the type attribute is not set, the anonymous type
+ * or anyType is returned if no other type information is available.
+ * Note that the QName returned in these cases is affected by
+ * the presence of the nillable attribute.
+ * <p/>
+ * If "ref", the QName represented by the ref attribute's value is
+ * returned.
+ * <p/>
+ * If "base" or "element", the QName represented by the base/element
+ * attribute's value is returned.
+ *
+ * @param node in the dom
+ * @param typeAttrName (type, base, element, ref)
+ * @return
+ */
+ private static QName getTypeQNameFromAttr(Node node, String typeAttrName) {
+
+ if (node == null) {
+ return null;
+ }
+
+ // Get the raw prefixed value
+ String prefixedName = getAttribute(node, typeAttrName);
+
+ // If "type" was specified but there is no type attribute,
+ // check for an anonymous type. If no anonymous type
+ // then the type is anyType.
+ if ((prefixedName == null) && typeAttrName.equals("type")) {
+ if ((getAttribute(node, "ref") == null)
+ && (getAttribute(node, "base") == null)
+ && (getAttribute(node, "element") == null)) {
+
+ // Try getting the anonymous qname
+ QName anonQName = SchemaUtils.getElementAnonQName(node);
+
+ if (anonQName == null) {
+ anonQName = SchemaUtils.getAttributeAnonQName(node);
+ }
+
+ if (anonQName != null) {
+ return anonQName;
+ }
+
+ // Try returning anyType
+ String localName = node.getLocalName();
+
+ if ((localName != null)
+ && org.apache.axis2.databinding.Constants.isSchemaXSD(node.getNamespaceURI())
+ && (localName.equals("element") ||
+ localName.equals("attribute"))) {
+ return Constants.XSD_ANYTYPE;
+ }
+ }
+ }
+
+ // Return null if not found
+ if (prefixedName == null) {
+ return null;
+ }
+
+ // Change the prefixed name into a full qname
+ QName qName = getQNameFromPrefixedName(node, prefixedName);
+
+ // An alternate qname is returned if nillable
+// if (typeAttrName.equals("type")) {
+// if (JavaUtils.isTrueExplicitly(getAttribute(node, "nillable"))) {
+// qName = getNillableQName(qName);
+// }
+// }
+
+ return qName;
+ }
+
+ /**
+ * Convert a prefixed name into a qname
+ *
+ * @param node
+ * @param prefixedName
+ * @return
+ */
+ public static QName getQNameFromPrefixedName(Node node,
+ String prefixedName) {
+
+ String localName = prefixedName.substring(prefixedName.lastIndexOf(":")
+ + 1);
+ String namespace = null;
+
+ // Associate the namespace prefix with a namespace
+ if (prefixedName.length() == localName.length()) {
+ namespace = getScopedAttribute(
+ node, "xmlns"); // Get namespace for unqualified reference
+ } else {
+ namespace = getScopedAttribute(node,
+ "xmlns:"
+ + prefixedName.substring(0,
+ prefixedName.lastIndexOf(":")));
+ }
+
+ return (findQName(namespace, localName));
+ }
+
+ /**
+ * This method returns a set of all types that are derived
+ * from this type via an extension of a complexType
+ *
+ * @param type
+ * @param symbolTable
+ * @return
+ */
+ public static HashSet getDerivedTypes(TypeEntry type,
+ SymbolTable symbolTable) {
+
+ HashSet types = (HashSet)symbolTable.derivedTypes.get(type);
+
+ if (types != null) {
+ return types;
+ }
+
+ types = new HashSet();
+
+ symbolTable.derivedTypes.put(type, types);
+
+ if ((type != null) && (type.getNode() != null)) {
+ getDerivedTypes(type, types, symbolTable);
+ } else if (Constants.isSchemaXSD(type.getQName().getNamespaceURI())
+ && (type.getQName().getLocalPart().equals("anyType")
+ || type.getQName().getLocalPart().equals("any"))) {
+
+ // All types are derived from anyType
+ types.addAll(symbolTable.getTypeIndex().values());
+ }
+
+ return types;
+ } // getNestedTypes
+
+ /**
+ * Method getDerivedTypes
+ *
+ * @param type
+ * @param types
+ * @param symbolTable
+ */
+ private static void getDerivedTypes(TypeEntry type, HashSet types,
+ SymbolTable symbolTable) {
+
+ // If all types are in the set, return
+ if (types.size() == symbolTable.getTypeEntryCount()) {
+ return;
+ }
+
+ // Search the dictionary for derived types of type
+ for (Iterator it = symbolTable.getTypeIndex().values().iterator();
+ it.hasNext();) {
+ Type t = (Type) it.next();
+
+ if ((t instanceof DefinedType) && (t.getNode() != null)
+ && !types.contains(t)
+ && (((DefinedType) t).getComplexTypeExtensionBase(symbolTable)
+ == type)) {
+ types.add(t);
+ getDerivedTypes(t, types, symbolTable);
+ }
+ }
+ } // getDerivedTypes
+
+ /**
+ * This method returns a set of all the nested types.
+ * Nested types are types declared within this TypeEntry (or descendents)
+ * plus any extended types and the extended type nested types
+ * The elements of the returned HashSet are Types.
+ *
+ * @param type is the type entry to consider
+ * @param symbolTable is the symbolTable
+ * @param derivedFlag should be set if all dependendent derived types should also be
+ * returned.
+ * @return
+ */
+ protected static HashSet getNestedTypes(TypeEntry type,
+ SymbolTable symbolTable,
+ boolean derivedFlag) {
+
+ HashSet types = new HashSet();
+
+ getNestedTypes(type, types, symbolTable, derivedFlag);
+
+ return types;
+ } // getNestedTypes
+
+ /**
+ * Method getNestedTypes
+ *
+ * @param type
+ * @param types
+ * @param symbolTable
+ * @param derivedFlag
+ */
+ private static void getNestedTypes(TypeEntry type, HashSet types,
+ SymbolTable symbolTable,
+ boolean derivedFlag) {
+
+ if (type == null) {
+ return;
+ }
+
+ // If all types are in the set, return
+ if (types.size() == symbolTable.getTypeEntryCount()) {
+ return;
+ }
+
+ // Process types derived from this type
+ if (derivedFlag) {
+ HashSet derivedTypes = getDerivedTypes(type, symbolTable);
+ Iterator it = derivedTypes.iterator();
+
+ while (it.hasNext()) {
+ TypeEntry derivedType = (TypeEntry) it.next();
+
+ if (!types.contains(derivedType)) {
+ types.add(derivedType);
+ getNestedTypes(derivedType, types, symbolTable,
+ derivedFlag);
+ }
+ }
+ }
+
+ // Continue only if the node exists
+ if (type.getNode() == null) {
+ return;
+ }
+
+ Node node = type.getNode();
+
+ // Process types declared in this type
+ Vector v = SchemaUtils.getContainedElementDeclarations(node,
+ symbolTable);
+
+ if (v != null) {
+ for (int i = 0; i < v.size(); i++) {
+ ElementDecl elem = (ElementDecl) v.get(i);
+
+ if (!types.contains(elem.getType())) {
+ types.add(elem.getType());
+ getNestedTypes(elem.getType(), types, symbolTable,
+ derivedFlag);
+ }
+ }
+ }
+
+ // Process attributes declared in this type
+ v = SchemaUtils.getContainedAttributeTypes(node, symbolTable);
+
+ if (v != null) {
+ for (int i = 0; i < v.size(); i++) {
+ ContainedAttribute attr = (ContainedAttribute) v.get(i);
+ TypeEntry te = attr.getType();
+ if (!types.contains(te)) {
+ types.add(te);
+ getNestedTypes(te, types, symbolTable, derivedFlag);
+ }
+ }
+ }
+
+ // Process referenced types
+ if ((type.getRefType() != null) && !types.contains(type.getRefType())) {
+ types.add(type.getRefType());
+ getNestedTypes(type.getRefType(), types, symbolTable, derivedFlag);
+ }
+
+ /*
+ * Anonymous processing and should be automatically handled by the
+ * reference processing above
+ * // Get the anonymous type of the element
+ * QName anonQName = SchemaUtils.getElementAnonQName(node);
+ * if (anonQName != null) {
+ * TypeEntry anonType = symbolTable.getType(anonQName);
+ * if (anonType != null && !types.contains(anonType)) {
+ * types.add(anonType);
+ * }
+ * }
+ *
+ * // Get the anonymous type of an attribute
+ * anonQName = SchemaUtils.getAttributeAnonQName(node);
+ * if (anonQName != null) {
+ * TypeEntry anonType = symbolTable.getType(anonQName);
+ * if (anonType != null && !types.contains(anonType)) {
+ * types.add(anonType);
+ * }
+ * }
+ */
+
+ // Process extended types
+ TypeEntry extendType = SchemaUtils.getComplexElementExtensionBase(node,
+ symbolTable);
+
+ if (extendType != null) {
+ if (!types.contains(extendType)) {
+ types.add(extendType);
+ getNestedTypes(extendType, types, symbolTable, derivedFlag);
+ }
+ }
+
+ /*
+ * Array component processing should be automatically handled by the
+ * reference processing above.
+ * // Process array components
+ * QName componentQName = SchemaUtils.getArrayComponentQName(node, new IntHolder(0));
+ * TypeEntry componentType = symbolTable.getType(componentQName);
+ * if (componentType == null) {
+ * componentType = symbolTable.getElement(componentQName);
+ * }
+ * if (componentType != null) {
+ * if (!types.contains(componentType)) {
+ * types.add(componentType);
+ * getNestedTypes(componentType, types, symbolTable, derivedFlag);
+ * }
+ * }
+ */
+ } // getNestedTypes
+
+ /**
+ * Generate an XML prefixed attribute value with a corresponding xmlns
+ * declaration for the prefix. If there is no namespace,
+ * don't prefix the name or emit the xmlns attribute.
+ * <p/>
+ * Caller should provide the enclosing quotes.
+ * <p/>
+ * Usage: println("name=\"" + genXMLQNameString(qname, "foo") + "\""
+ *
+ * @param qname
+ * @param prefix
+ * @return
+ */
+ public static String genQNameAttributeString(QName qname, String prefix) {
+
+ if ((qname.getNamespaceURI() == null)
+ || qname.getNamespaceURI().equals("")) {
+ return qname.getLocalPart();
+ }
+
+ return prefix + ":" + qname.getLocalPart() + "\" xmlns:" + prefix
+ + "=\"" + qname.getNamespaceURI();
+ }
+
+ public static String genQNameAttributeStringWithLastLocalPart(QName qname, String prefix) {
+ String lastLocalPart = getLastLocalPart(qname.getLocalPart());
+ if ((qname.getNamespaceURI() == null)
+ || qname.getNamespaceURI().equals("")) {
+ return lastLocalPart;
+ }
+
+ return prefix + ":" + lastLocalPart + "\" xmlns:" + prefix
+ + "=\"" + qname.getNamespaceURI();
+ }
+
+ public static String getLastLocalPart(String localPart) {
+ int anonymousDelimitorIndex = localPart.lastIndexOf('>');
+ if (anonymousDelimitorIndex > -1 && anonymousDelimitorIndex < localPart.length()-1) {
+ localPart = localPart.substring(anonymousDelimitorIndex + 1);
+ }
+ return localPart;
+
+ }
+}
Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/DuplicateFileException.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/DuplicateFileException.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/DuplicateFileException.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/DuplicateFileException.java Thu Oct 6 03:54:18 2005
@@ -0,0 +1,51 @@
+/*
+ * 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.axis2.databinding.toJava;
+
+import java.io.IOException;
+
+/**
+ * Class DuplicateFileException
+ *
+ * @version %I%, %G%
+ */
+public class DuplicateFileException extends IOException {
+
+ /** Field filename */
+ private String filename = null;
+
+ /**
+ * Constructor DuplicateFileException
+ *
+ * @param message
+ * @param filename
+ */
+ public DuplicateFileException(String message, String filename) {
+
+ super(message);
+
+ this.filename = filename;
+ }
+
+ /**
+ * Method getFileName
+ *
+ * @return
+ */
+ public String getFileName() {
+ return this.filename;
+ }
+}
Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/Emitter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/Emitter.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/Emitter.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/Emitter.java Thu Oct 6 03:54:18 2005
@@ -0,0 +1,1029 @@
+/*
+ * 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.axis2.databinding.toJava;
+
+//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;
+//import org.apache.axis.utils.ClassUtils;
+//import org.apache.axis.utils.JavaUtils;
+//import org.apache.axis.wsdl.gen.GeneratorFactory;
+//import org.apache.axis.wsdl.gen.Parser;
+//import org.apache.axis.wsdl.symbolTable.BaseTypeMapping;
+//import org.apache.axis.wsdl.symbolTable.SymTabEntry;
+//import org.apache.axis.wsdl.symbolTable.SymbolTable;
+import org.apache.axis2.databinding.gen.Parser;
+import org.apache.axis2.databinding.gen.GeneratorFactory;
+import org.apache.axis2.databinding.symbolTable.BaseTypeMapping;
+import org.apache.axis2.databinding.symbolTable.SymbolTable;
+import org.apache.axis2.databinding.symbolTable.SymTabEntry;
+
+import javax.xml.namespace.QName;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Vector;
+
+//import com.sun.tools.javac.v8.code.Scope;
+
+/**
+ * This class produces java files for stubs, skeletons, and types from a
+ * WSDL document.
+ *
+ * @author Russell Butek (butek@us.ibm.com)
+ * @author Tom Jordahl (tjordahl@macromedia.com)
+ * @author Rich Scheuerle (scheu@us.ibm.com)
+ * @author Steve Graham (sggraham@us.ibm.com)
+ */
+public class Emitter extends Parser {
+
+ /** Field DEFAULT_NSTOPKG_FILE */
+ public static final String DEFAULT_NSTOPKG_FILE = "NStoPkg.properties";
+
+ /** Field namespaceMap */
+ protected HashMap namespaceMap = new HashMap();
+
+ /** Field typeMappingVersion */
+ protected String typeMappingVersion = "1.2";
+
+ /** Field baseTypeMapping */
+ protected BaseTypeMapping baseTypeMapping = null;
+
+ /** Field namespaces */
+ protected Namespaces namespaces = null;
+
+ /** Field NStoPkgFilename */
+ protected String NStoPkgFilename = null;
+
+ /** Field bEmitServer */
+ private boolean bEmitServer = false;
+
+ /** Field bDeploySkeleton */
+ private boolean bDeploySkeleton = false;
+
+ /** Field bEmitTestCase */
+ private boolean bEmitTestCase = false;
+
+ /** Field bGenerateAll */
+ private boolean bGenerateAll = false;
+
+ /** Field bHelperGeneration */
+ private boolean bHelperGeneration = false;
+
+ private boolean bBuildFileGeneration = false;
+
+ private boolean typeCollisionProtection = true;
+
+ /** Check if URL endpoints are valid or not */
+ private boolean allowInvalidURL = false;
+
+ /** Field packageName */
+ private String packageName = null;
+
+ /** Field scope */
+// private Scope scope = null;
+
+ /** Field fileInfo */
+ private GeneratedFileInfo fileInfo = new GeneratedFileInfo();
+
+ /** Field delayedNamespacesMap */
+ private HashMap delayedNamespacesMap = new HashMap();
+
+ /** Field outputDir */
+ private String outputDir = null;
+
+ /** Field nsIncludes - defines a list of namespaces to specifically
+ * include in the generated source code. If non-empty, anything
+ * not in this list should be excluded. If empty, everything in this
+ * and not specifically excluded should be generated.
+ */
+ protected List nsIncludes = new ArrayList();
+
+ /** Field nsIncludes - defines a list of namespaces to specifically
+ * exclude from generated source code. Any entry in this list that
+ * is in conflict with the includes list should be ignored and
+ * generated.
+ */
+ protected List nsExcludes = new ArrayList();
+
+ /** Field properties - defines a set of general purpose properties
+ * that can be used by custom JavaGeneratorFactories.
+ */
+ protected List properties = new ArrayList();
+
+ /**
+ * Field implementationClassName - defines a non default classname for the actual
+ * implementation class. Particularly useful when exporting a webservice directly
+ * from the java implementation.
+ */
+ private String implementationClassName = null;
+
+// /** Field defaultTM */
+// 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;
+ private Class ClassUtils;
+
+// /**
+// * Default constructor.
+// */
+// public Emitter() {
+// setFactory(new JavaGeneratorFactory(this));
+// } // ctor
+
+ // /////////////////////////////////////////////////
+ //
+ // Command line switches
+ //
+
+ /**
+ * Turn on/off server skeleton creation
+ *
+ * @param value
+ */
+ public void setServerSide(boolean value) {
+ this.bEmitServer = value;
+ } // setServerSide
+
+ /**
+ * Indicate if we should be emitting server side code and deploy/undeploy
+ *
+ * @return
+ */
+ public boolean isServerSide() {
+ return bEmitServer;
+ } // isServerSide
+
+ /**
+ * Turn on/off server skeleton deploy
+ *
+ * @param value
+ */
+ public void setSkeletonWanted(boolean value) {
+ bDeploySkeleton = value;
+ } // setSkeletonWanted
+
+ /**
+ * Indicate if we should be deploying skeleton or implementation
+ *
+ * @return
+ */
+ public boolean isSkeletonWanted() {
+ return bDeploySkeleton;
+ } // isSkeletonWanted
+
+ /**
+ * Turn on/off Helper class generation
+ *
+ * @param value
+ */
+ public void setHelperWanted(boolean value) {
+ bHelperGeneration = value;
+ } // setHelperWanted
+
+ /**
+ * Indicate if we should be generating Helper classes
+ *
+ * @return
+ */
+ public boolean isHelperWanted() {
+ return bHelperGeneration;
+ } // isHelperWanted
+
+ /**
+ * Turn on/off test case creation
+ *
+ * @param value
+ */
+ public void setTestCaseWanted(boolean value) {
+ this.bEmitTestCase = value;
+ } // setTestCaseWanted
+
+ /**
+ * Method isTestCaseWanted
+ *
+ * @return
+ */
+ public boolean isTestCaseWanted() {
+ return bEmitTestCase;
+ } // isTestCaseWanted
+
+ /**
+ * get the build file genaeration state
+ * @return
+ */
+ public boolean isBuildFileWanted(){
+ return bBuildFileGeneration;
+ }
+
+ /**
+ * turn the build file genaration ON
+ * @param value
+ */
+ public void setBuildFileWanted(boolean value){
+ bBuildFileGeneration = value;
+ }
+
+ /**
+ * By default, code is generated only for referenced elements.
+ * Call bGenerateAll(true) and WSDL2Java will generate code for all
+ * elements in the scope regardless of whether they are
+ * referenced. Scope means: by default, all WSDL files; if
+ * generateImports(false), then only the immediate WSDL file.
+ *
+ * @param all
+ */
+ public void setAllWanted(boolean all) {
+ bGenerateAll = all;
+ } // setAllWanted
+
+ /**
+ * Method isAllWanted
+ *
+ * @return
+ */
+ public boolean isAllWanted() {
+ return bGenerateAll;
+ } // isAllWanted
+
+ /**
+ * Method getNamespaces
+ *
+ * @return
+ */
+ public Namespaces getNamespaces() {
+ return namespaces;
+ } // getNamespaces
+
+ /**
+ * Set the output directory to use in emitted source files
+ *
+ * @param outputDir
+ */
+ public void setOutputDir(String outputDir) {
+ this.outputDir = outputDir;
+ }
+
+ /**
+ * Get the output directory to use for emitted source files
+ *
+ * @return
+ */
+ public String getOutputDir() {
+ return outputDir;
+ }
+
+ /**
+ * Get global package name to use instead of mapping namespaces
+ *
+ * @return
+ */
+ public String getPackageName() {
+ return packageName;
+ }
+
+ /**
+ * Set a global package name to use instead of mapping namespaces
+ *
+ * @param packageName
+ */
+ public void setPackageName(String packageName) {
+ this.packageName = packageName;
+ }
+
+// /**
+// * Set the scope for the deploy.xml file.
+// *
+// * @param scope One of 'null',
+// * Scope.APPLICATION, Scope.REQUEST, Scope.SESSION.
+// * Anything else is equivalent to 'null' null and no explicit
+// * scope tag will appear in deploy.xml.
+// */
+// public void setScope(Scope scope) {
+// this.scope = scope;
+// } // setScope
+
+// /**
+// * Get the scope for the deploy.xml file.
+// *
+// * @return
+// */
+// public Scope getScope() {
+// return scope;
+// } // getScope
+
+ /**
+ * Set the NStoPkg mappings filename.
+ *
+ * @param NStoPkgFilename
+ */
+ public void setNStoPkg(String NStoPkgFilename) {
+
+ if (NStoPkgFilename != null) {
+ this.NStoPkgFilename = NStoPkgFilename;
+ }
+ } // setNStoPkg
+
+ /**
+ * Set a map of namespace -> Java package names
+ *
+ * @param map
+ */
+ public void setNamespaceMap(HashMap map) {
+ delayedNamespacesMap = map;
+ }
+
+ /**
+ * Get the map of namespace -> Java package names
+ *
+ * @return
+ */
+ public HashMap getNamespaceMap() {
+ return delayedNamespacesMap;
+ }
+
+ /** Sets the list of namespaces to specifically include
+ * in the generated code.
+ */
+ public void setNamespaceIncludes(List nsIncludes) {
+ this.nsIncludes = nsIncludes;
+ }
+
+ /** Returns the list of namespaces specifically excluded
+ * from the generated code.
+ */
+ public List getNamespaceIncludes() {
+ return this.nsIncludes;
+ }
+
+ /** Sets the list of namespaces to specifically exclude
+ * from the generated source.
+ */
+ public void setNamespaceExcludes(List nsExcludes) {
+ this.nsExcludes = nsExcludes;
+ }
+
+ /** Returns the list of excludes to specifically exclude
+ * from the generated source.
+ */
+ public List getNamespaceExcludes() {
+ return this.nsExcludes;
+ }
+
+ /** Sets the list of extension properties for custom
+ * JavaGeneratorFactories.
+ */
+ public void setProperties(List properties) {
+ this.properties = properties;
+ }
+
+ /** Gets the list of extension properties for custom
+ * JavaGeneratorFactories.
+ */
+ public List getProperties() {
+ return this.properties;
+ }
+
+// /**
+// * Returns the default <code>TypeMapping</code> used by the service
+// *
+// * @return the default <code>TypeMapping</code> used by the service
+// */
+// public TypeMapping getDefaultTypeMapping() {
+// if (defaultTM == null) {
+// defaultTM =
+// (TypeMapping)tmr.getTypeMapping(Constants.URI_SOAP11_ENC);
+// }
+// return defaultTM;
+// }
+//
+// /**
+// * Sets the default <code>TypeMapping</code> used by the service
+// *
+// * @param defaultTM the default <code>TypeMapping</code> used by the service
+// */
+// public void setDefaultTypeMapping(TypeMapping defaultTM) {
+// this.defaultTM = defaultTM;
+// }
+
+ /**
+ * Sets the <code>WriterFactory Class</code> to use
+ *
+ * @param factory the name of the factory <code>Class</code>
+ */
+ public void setFactory(String factory) {
+
+ try {
+ Class clazz = ClassUtils.forName(factory);
+ GeneratorFactory genFac;
+ try {
+ Constructor ctor = clazz.getConstructor(new Class[]{
+ getClass()});
+
+ genFac = (GeneratorFactory) ctor.newInstance(new Object[]{
+ this});
+ } catch (NoSuchMethodException ex) {
+ genFac = (GeneratorFactory) clazz.newInstance();
+ }
+
+ setFactory(genFac);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ } // setFactory
+
+ //
+ // Command line switches
+ //
+ // /////////////////////////////////////////////////
+
+ /**
+ * Returns an object which contains of information on all generated files
+ * including the class name, filename and a type string.
+ *
+ * @return An org.apache.axis.wsdl.toJava.GeneratedFileInfo object
+ * @see org.apache.axis.wsdl.toJava.GeneratedFileInfo
+ */
+ public GeneratedFileInfo getGeneratedFileInfo() {
+ return fileInfo;
+ }
+
+ /**
+ * This method returns a list of all generated class names.
+ *
+ * @return
+ */
+ public List getGeneratedClassNames() {
+ return fileInfo.getClassNames();
+ }
+
+ /**
+ * This method returns a list of all generated file names.
+ *
+ * @return
+ */
+ public List getGeneratedFileNames() {
+ return fileInfo.getFileNames();
+ }
+
+ /**
+ * Get the Package name for the specified namespace
+ *
+ * @param namespace
+ * @return
+ */
+ public String getPackage(String namespace) {
+ return namespaces.getCreate(namespace);
+ }
+
+ /**
+ * Get the Package name for the specified QName
+ *
+ * @param qName
+ * @return
+ */
+ public String getPackage(QName qName) {
+ return getPackage(qName.getNamespaceURI());
+ }
+
+ /**
+ * Convert the specified QName into a full Java Name.
+ *
+ * @param qName
+ * @return
+ */
+ public String getJavaName(QName qName) {
+
+ // If this is one of our special 'collection' qnames.
+ // get the element type and append []
+ if (qName.getLocalPart().indexOf("[") > 0) {
+ String localPart = qName.getLocalPart().substring(0,
+ qName.getLocalPart().indexOf("["));
+ QName eQName = new QName(qName.getNamespaceURI(), localPart);
+
+ return getJavaName(eQName) + "[]";
+ }
+
+ // Handle the special "java" namespace for types
+ if (qName.getNamespaceURI().equalsIgnoreCase("java")) {
+ return qName.getLocalPart();
+ }
+
+ // The QName may represent a base java name, so check this first
+ String fullJavaName =
+ getFactory().getBaseTypeMapping().getBaseName(qName);
+
+ if (fullJavaName != null) {
+ return fullJavaName;
+ }
+
+ fullJavaName = getJavaNameHook(qName);
+ if (fullJavaName != null) {
+ return fullJavaName;
+ }
+ // Use the namespace uri to get the appropriate package
+ String pkg = getPackage(qName.getNamespaceURI());
+
+ if (pkg != null && pkg.length() > 0) {
+ fullJavaName = pkg + "."
+ + Utils.xmlNameToJavaClass(qName.getLocalPart());
+ } else {
+ fullJavaName = Utils.xmlNameToJavaClass(qName.getLocalPart());
+ }
+
+ return fullJavaName;
+ } // getJavaName
+
+ protected String getJavaNameHook(QName qname) { return null; }
+
+
+ /**
+ * @param typeQName QName for containing xml type
+ * @param xmlName QName for element
+ * @return
+ */
+ public String getJavaVariableName(QName typeQName, QName xmlName, boolean isElement) {
+ String javaName = getJavaVariableNameHook(typeQName, xmlName, isElement);
+ if (javaName == null) {
+ String elemName = Utils.getLastLocalPart(xmlName.getLocalPart());
+ javaName = Utils.xmlNameToJava(elemName);
+ }
+ return javaName;
+ }
+
+ protected String getJavaVariableNameHook(QName typeQName, QName xmlName, boolean isElement) {
+ return null;
+ }
+
+
+
+ /**
+ * Method setup
+ *
+ * @throws IOException
+ */
+ private void setup() throws IOException {
+
+ if (baseTypeMapping == null) {
+// setTypeMappingVersion(typeMappingVersion);
+ }
+
+ getFactory().setBaseTypeMapping(baseTypeMapping);
+
+ namespaces = new Namespaces(outputDir);
+
+ if (packageName != null) {
+ namespaces.setDefaultPackage(packageName);
+ } else {
+
+ // First, read the namespace mapping file - configurable, by default
+ // NStoPkg.properties - if it exists, and load the namespaceMap HashMap
+ // with its data.
+ getNStoPkgFromPropsFile(namespaces);
+
+ if (delayedNamespacesMap != null) {
+ namespaces.putAll(delayedNamespacesMap);
+ }
+ }
+ } // setup
+
+ /**
+ * Method sanityCheck
+ *
+ * @param symbolTable
+ */
+ protected void sanityCheck(SymbolTable symbolTable) {
+
+ Iterator it = symbolTable.getHashMap().values().iterator();
+
+ while (it.hasNext()) {
+ Vector v = (Vector) it.next();
+
+ for (int i = 0; i < v.size(); ++i) {
+ SymTabEntry entry = (SymTabEntry) v.elementAt(i);
+ String namespace = entry.getQName().getNamespaceURI();
+ String packageName =
+ Utils.makePackageName(
+ namespace);
+ String localName = entry.getQName().getLocalPart();
+
+ if (localName.equals(packageName)
+ && packageName.equals(
+ namespaces.getCreate(namespace))) {
+ packageName += "_pkg";
+
+ namespaces.put(namespace, packageName);
+ }
+ }
+ }
+ }
+
+ /**
+ * Tries to load the namespace-to-package mapping file.
+ * <ol>
+ * <li>if a file name is explicitly set using <code>setNStoPkg()</code>, tries
+ * to load the mapping from this file. If this fails, the built-in default
+ * mapping is used.
+ * <p/>
+ * <li>if no file name is set, tries to load the file <code>DEFAULT_NSTOPKG_FILE</code>
+ * as a java resource. If this fails, the built-in dfault mapping is used.
+ * </ol>
+ *
+ * @param namespaces a hashmap which is filled with the namespace-to-package mapping
+ * in this method
+ * @throws IOException
+ * @see #setNStoPkg(String)
+ * @see #DEFAULT_NSTOPKG_FILE
+ * @see org.apache.axis.utils.ClassUtils#getResourceAsStream(java.lang.Class,String)
+ */
+ private void getNStoPkgFromPropsFile(HashMap namespaces)
+ throws IOException {
+
+ Properties mappings = new Properties();
+
+ if (NStoPkgFilename != null) {
+ try {
+ mappings.load(new FileInputStream(NStoPkgFilename));
+
+ if (verbose) {
+// System.out.println(
+// Messages.getMessage(
+// "nsToPkgFileLoaded00", NStoPkgFilename));
+ }
+ } catch (Throwable t) {
+
+ // loading the custom mapping file failed. We do not try
+ // to load the mapping from a default mapping file.
+ throw new IOException();
+// Messages.getMessage(
+// "nsToPkgFileNotFound00", NStoPkgFilename));
+ }
+ } else {
+ try {
+ mappings.load(new FileInputStream(DEFAULT_NSTOPKG_FILE));
+
+ if (verbose) {
+// System.out.println(
+// Messages.getMessage(
+// "nsToPkgFileLoaded00", DEFAULT_NSTOPKG_FILE));
+ }
+ } catch (Throwable t) {
+ try {
+ //mappings.load(ClassUtils.getResourceAsStream(Emitter.class,DEFAULT_NSTOPKG_FILE));
+
+ if (verbose) {
+// System.out.println(
+// Messages.getMessage(
+// "nsToPkgDefaultFileLoaded00",
+// DEFAULT_NSTOPKG_FILE));
+ }
+ } catch (Throwable t1) {
+
+ // loading the default mapping file failed.
+ // The built-in default mapping is used
+ // No message is given, since this is generally what happens
+ }
+ }
+ }
+
+ Enumeration keys = mappings.propertyNames();
+
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+
+ namespaces.put(key, mappings.getProperty(key));
+ }
+ } // getNStoPkgFromPropsFile
+
+ /**
+ * Get the typemapping version
+ */
+ public String getTypeMappingVersion() {
+ return typeMappingVersion;
+ }
+
+// /**
+// * Method setTypeMappingVersion
+// *
+// * @param typeMappingVersion
+// */
+// public void setTypeMappingVersion(String typeMappingVersion) {
+// this.typeMappingVersion = typeMappingVersion;
+// tmr.doRegisterFromVersion(typeMappingVersion);
+// baseTypeMapping = new BaseTypeMapping() {
+//
+// final TypeMapping defaultTM = getDefaultTypeMapping();
+//
+// public String getBaseName(QName qNameIn) {
+//
+// javax.xml.namespace.QName qName =
+// new javax.xml.namespace.QName(qNameIn.getNamespaceURI(),
+// qNameIn.getLocalPart());
+// Class cls =
+// defaultTM.getClassForQName(qName);
+//
+// if (cls == null) {
+// return null;
+// } else {
+// return JavaUtils.getTextClassName(cls.getName());
+// }
+// }
+// };
+// }
+
+ // The remainder are deprecated methods.
+
+ /**
+ * Get the GeneratorFactory.
+ *
+ * @return
+ * @deprecated Call getFactory instead. This doesn't return
+ * a WriterFactory, it returns a GeneratorFactory.
+ */
+ public GeneratorFactory getWriterFactory() {
+ return getFactory();
+ } // getWriterFactory
+
+
+
+// /**
+// * Call this method if your WSDL document has already been
+// * parsed as an XML DOM document.
+// *
+// * @param context context This is directory context for the Document.
+// * If the Document were from file "/x/y/z.wsdl" then the context could be "/x/y"
+// * (even "/x/y/z.wsdl" would work). If context is null, then the context
+// * becomes the current directory.
+// * @param doc doc This is the XML Document containing the WSDL.
+// * @throws IOException
+// * @throws SAXException
+// * @throws WSDLException
+// * @throws ParserConfigurationException
+// * @deprecated Call run(context, doc) instead.
+// */
+// public void emit(String context, Document doc)
+// throws IOException, SAXException, WSDLException,
+// ParserConfigurationException {
+// run(context, doc);
+// } // emit
+
+ /**
+ * Turn on/off server-side binding generation
+ *
+ * @param value
+ * @deprecated Use setServerSide(value)
+ */
+ public void generateServerSide(boolean value) {
+ setServerSide(value);
+ }
+
+ /**
+ * Indicate if we should be emitting server side code and deploy/undeploy
+ *
+ * @return
+ * @deprecated Use isServerSide()
+ */
+ public boolean getGenerateServerSide() {
+ return isServerSide();
+ }
+
+ /**
+ * Turn on/off server skeleton deploy
+ *
+ * @param value
+ * @deprecated Use setSkeletonWanted(value)
+ */
+ public void deploySkeleton(boolean value) {
+ setSkeletonWanted(value);
+ }
+
+ /**
+ * Indicate if we should be deploying skeleton or implementation
+ *
+ * @return
+ * @deprecated Use isSkeletonWanted()
+ */
+ public boolean getDeploySkeleton() {
+ return isSkeletonWanted();
+ }
+
+ /**
+ * Turn on/off Helper class generation
+ *
+ * @param value
+ * @deprecated Use setHelperWanted(value)
+ */
+ public void setHelperGeneration(boolean value) {
+ setHelperWanted(value);
+ }
+
+ /**
+ * Indicate if we should be generating Helper classes
+ *
+ * @return
+ * @deprecated Use isHelperWanted()
+ */
+ public boolean getHelperGeneration() {
+ return isHelperWanted();
+ }
+
+ /**
+ * Turn on/off generation of elements from imported files.
+ *
+ * @param generateImports
+ * @deprecated Use setImports(generateImports)
+ */
+ public void generateImports(boolean generateImports) {
+ setImports(generateImports);
+ } // generateImports
+
+ /**
+ * Turn on/off debug messages.
+ *
+ * @param value
+ * @deprecated Use setDebug(value)
+ */
+ public void debug(boolean value) {
+ setDebug(value);
+ } // debug
+
+ /**
+ * Return the status of the debug switch.
+ *
+ * @return
+ * @deprecated Use isDebug()
+ */
+ public boolean getDebug() {
+ return isDebug();
+ } // getDebug
+
+ /**
+ * Turn on/off verbose messages
+ *
+ * @param value
+ * @deprecated Use setVerbose(value)
+ */
+ public void verbose(boolean value) {
+ setVerbose(value);
+ }
+
+ /**
+ * Return the status of the verbose switch
+ *
+ * @return
+ * @deprecated Use isVerbose()
+ */
+ public boolean getVerbose() {
+ return isVerbose();
+ }
+
+ /**
+ * Turn on/off test case creation
+ *
+ * @param value
+ * @deprecated Use setTestCaseWanted()
+ */
+ public void generateTestCase(boolean value) {
+ setTestCaseWanted(value);
+ }
+
+ /**
+ * @param all
+ * @deprecated Use setAllWanted(all)
+ */
+ public void generateAll(boolean all) {
+ setAllWanted(all);
+ } // generateAll
+
+ /**
+ * Get the type collision protection setting
+ * @return
+ */
+ public boolean isTypeCollisionProtection(){
+ return this.typeCollisionProtection;
+ }
+
+ /**
+ * Enable/disable type collision protection
+ * @param value
+ */
+ public void setTypeCollisionProtection(boolean value){
+ this.typeCollisionProtection = value;
+ }
+
+ /**
+ * Get an implementation classname to use instead of the default.
+ * @return
+ */
+ public String getImplementationClassName() {
+ return implementationClassName;
+ }
+
+ /**
+ * Set an implementation classname to use instead of the default.
+ *
+ * @param implementationClassName
+ */
+ public void setImplementationClassName(String implementationClassName) {
+ this.implementationClassName = implementationClassName;
+ }
+
+ /**
+ * @return Returns the allowInvalidURL.
+ */
+ public boolean isAllowInvalidURL() {
+ return allowInvalidURL;
+ }
+
+ /**
+ * @param allowInvalidURL The allowInvalidURL to set.
+ */
+ 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;
+ }
+
+
+ /**
+ * 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) {
+ try {
+ ClassUtils.forName(className);
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public void setWrapArrays(boolean wrapArrays) {
+ this.wrapArrays = wrapArrays;
+ }
+}
Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/FactoryProperty.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/FactoryProperty.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/FactoryProperty.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/FactoryProperty.java Thu Oct 6 03:54:18 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2002,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.axis2.databinding.toJava;
+
+/**
+ This is a general purpose class that allows one to pass name/value
+ properties to the JavaGeneratorFactory.
+
+ @author Jim Stafford (jim.stafford@raba.com)
+*/
+public class FactoryProperty {
+ private String name_;
+ private String value_;
+
+ public FactoryProperty() {
+ }
+
+ public String getName() {
+ return name_;
+ }
+
+ public String getValue() {
+ return value_;
+ }
+
+ public void setName(String string) {
+ name_ = string;
+ }
+
+ public void setValue(String string) {
+ value_ = string;
+ }
+
+ public String toString() {
+ return name_ + "=" + value_;
+ }
+
+ public boolean equals(Object rhs) {
+ if (rhs == null) {
+ return false;
+ }
+ else if (rhs instanceof String) {
+ return ((String)rhs).equals(name_);
+ }
+ else if (rhs instanceof FactoryProperty) {
+ return ((FactoryProperty)rhs).equals(name_);
+ }
+ else {
+ return false;
+ }
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/GeneratedFileInfo.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/GeneratedFileInfo.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/GeneratedFileInfo.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/GeneratedFileInfo.java Thu Oct 6 03:54:18 2005
@@ -0,0 +1,242 @@
+/*
+ * 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.axis2.databinding.toJava;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * File info available after emit to describe what
+ * exactly was created by the Emitter.
+ *
+ * @author Tom Jordahl (tomj@macromedia.com)
+ */
+public class GeneratedFileInfo {
+
+ /** Field list */
+ protected ArrayList list = new ArrayList();
+
+ /**
+ * Structure to hold entries.
+ * There are three public data members:
+ * <ul>
+ * <li><code>fileName</code> - A relative path of the generated file.</li>
+ * <li><code>className</code> - The name of the class in the file.</li>
+ * <li><code>type</code> - The type of the file.<br>
+ * Valid types are:<br>
+ * <code>
+ * stub, interface, complexType, enumType, fault, holder, skeleton,
+ * skeletonImpl, service, deploy, undeploy, testCase
+ * </code></li>
+ * </ul>
+ */
+ public class Entry {
+
+ // relative path of the emitted file
+
+ /** Field fileName */
+ public String fileName;
+
+ // name of emitted class
+
+ /** Field className */
+ public String className;
+
+ // function of the emitted class
+
+ /** Field type */
+ public String type;
+
+ /**
+ * Constructor Entry
+ *
+ * @param name
+ * @param className
+ * @param type
+ */
+ public Entry(String name, String className, String type) {
+
+ this.fileName = name;
+ this.className = className;
+ this.type = type;
+ }
+
+ /**
+ * Method toString
+ *
+ * @return
+ */
+ public String toString() {
+ return "Name: " + fileName + " Class: " + className + " Type: "
+ + type;
+ }
+ } // Entry
+
+ /**
+ * Construct an empty file info list.
+ */
+ public GeneratedFileInfo() {
+ }
+
+ /**
+ * Return the entire list of generated files
+ *
+ * @return
+ */
+ public List getList() {
+ return list;
+ }
+
+ /**
+ * Add an entry
+ *
+ * @param name
+ * @param className
+ * @param type
+ */
+ public void add(String name, String className, String type) {
+ list.add(new Entry(name, className, type));
+ }
+
+ /**
+ * Lookup an entry by type.
+ * <br>
+ * Valid type values are:
+ * stub, interface, complexType, enumType, fault, holder, skeleton,
+ * skeletonImpl, service, deploy, undeploy, testCase
+ *
+ * @param type of objects you want info about
+ * @return A list of <code>org.apache.axis.wsdl.toJava.GeneratedFileInfo.Entry</code> objects. Null if no objects found.
+ */
+ public List findType(String type) {
+
+ // look at each entry for the type we want
+ ArrayList ret = null;
+
+ for (Iterator i = list.iterator(); i.hasNext();) {
+ Entry e = (Entry) i.next();
+
+ if (e.type.equals(type)) {
+ if (ret == null) {
+ ret = new ArrayList();
+ }
+
+ ret.add(e);
+ }
+ }
+
+ return ret;
+ }
+
+ /**
+ * Lookup an entry by file name
+ *
+ * @param file name you want info about
+ * @param fileName
+ * @return The entry for the file name specified. Null if not found
+ */
+ public Entry findName(String fileName) {
+
+ // look at each entry for the type we want
+ for (Iterator i = list.iterator(); i.hasNext();) {
+ Entry e = (Entry) i.next();
+
+ if (e.fileName.equals(fileName)) {
+ return e;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Lookup an entry by class name
+ *
+ * @param class name you want info about
+ * @param className
+ * @return The entry for the class specified. Null if not found
+ */
+ public Entry findClass(String className) {
+
+ // look at each entry for the type we want
+ for (Iterator i = list.iterator(); i.hasNext();) {
+ Entry e = (Entry) i.next();
+
+ if (e.className.equals(className)) {
+ return e;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Get the list of generated classes
+ *
+ * @return
+ */
+ public List getClassNames() {
+
+ // is there a better way to do this?
+ ArrayList ret = new ArrayList(list.size());
+
+ for (Iterator i = list.iterator(); i.hasNext();) {
+ Entry e = (Entry) i.next();
+
+ ret.add(e.className);
+ }
+
+ return ret;
+ }
+
+ /**
+ * Get the list of generated filenames
+ *
+ * @return
+ */
+ public List getFileNames() {
+
+ // is there a better way to do this?
+ ArrayList ret = new ArrayList(list.size());
+
+ for (Iterator i = list.iterator(); i.hasNext();) {
+ Entry e = (Entry) i.next();
+
+ ret.add(e.fileName);
+ }
+
+ return ret;
+ }
+
+ /**
+ * Convert all entries in the list to a string
+ *
+ * @return
+ */
+ public String toString() {
+
+ String s = "";
+
+ for (Iterator i = list.iterator(); i.hasNext();) {
+ Entry entry = (Entry) i.next();
+
+ s += entry.toString() + "\n";
+ }
+
+ return s;
+ }
+}
Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaBeanFaultWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaBeanFaultWriter.java?rev=306583&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaBeanFaultWriter.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/toJava/JavaBeanFaultWriter.java Thu Oct 6 03:54:18 2005
@@ -0,0 +1,142 @@
+/*
+ * 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.axis2.databinding.toJava;
+
+//import org.apache.axis.wsdl.symbolTable.TypeEntry;
+import org.apache.axis2.databinding.symbolTable.TypeEntry;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Vector;
+import java.util.Set;
+import java.util.Collections;
+import java.util.HashSet;
+
+/**
+ * This is Wsdl2java's Complex Fault Writer.
+ * It generates bean-like class for complexTypes used
+ * in an operation fault message.
+ */
+public class JavaBeanFaultWriter extends JavaBeanWriter {
+ /**
+ * All server specific exception classes have {@link Throwable} as an
+ * indirect superclass. <code>Throwable</code> defines a set of properties
+ * that may potentially conflict with those that would be generated by
+ * this class for an XSD complex type used as a fault. The following
+ * immutable object contains all property names that must be excluded
+ * when generating a service specific exception. <i>Note:</t>
+ * {@link org.apache.axis.encoding.ser.BeanSerializer} always excludes
+ * <code>Throwable</code>'s and <code>AxisFault</code>'s properties
+ * when marshalling a service Java exception.
+ */
+ public static final Set RESERVED_PROPERTY_NAMES;
+ static {
+ Set temp = new HashSet();
+ // Throwable's properties.
+ temp.add("cause");
+ temp.add("message");
+ temp.add("localizedMessage");
+ temp.add("stackTrace");
+ // AxisFault's properties.
+ temp.add("faultActor");
+ temp.add("faultCode");
+ temp.add("faultDetails");
+ temp.add("faultNode");
+ temp.add("faultReason");
+ temp.add("faultRole");
+ temp.add("faultString");
+ temp.add("faultSubCodes");
+ temp.add("headers");
+ RESERVED_PROPERTY_NAMES = Collections.unmodifiableSet(temp);
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param emitter
+ * @param type The type representing this class
+ * @param elements Vector containing the Type and name of each property
+ * @param extendType The type representing the extended class (or null)
+ * @param attributes Vector containing the attribute types and names
+ * @param helper Helper class writer
+ */
+ protected JavaBeanFaultWriter(Emitter emitter, TypeEntry type,
+ Vector elements, TypeEntry extendType,
+ Vector attributes, JavaWriter helper) {
+
+ super(emitter, type, elements, extendType, attributes, helper);
+
+ // The Default Constructor is not JSR 101 v1.0 compliant, but
+ // is the only way that Axis can get something back over the wire.
+ // This will need to be changed when fault contents are supported
+ // over the wire.
+ enableDefaultConstructor = true;
+
+ // JSR 101 v1.0 requires a full constructor
+ enableFullConstructor = true;
+
+ // JSR 101 v1.0 does not support write access methods
+ enableSetters = true;
+ } // ctor
+
+ /**
+ * Returns the appropriate extends text
+ *
+ * @return "" or " extends <class> "
+ */
+ protected String getExtendsText() {
+
+ // See if this class extends another class
+ String extendsText = super.getExtendsText();
+
+ if (extendsText.equals("")) {
+
+ // JSR 101 compliant code should extend java.lang.Exception!
+ // extendsText = " extends java.lang.Exception ";
+ extendsText = " extends org.apache.axis.AxisFault ";
+ }
+
+ return extendsText;
+ }
+
+ /**
+ * Write the Exception serialization code
+ * <p/>
+ * NOTE: This function is written in JavaFaultWriter.java also.
+ *
+ * @param pw
+ * @throws IOException
+ */
+ protected void writeFileFooter(PrintWriter pw) throws IOException {
+
+ // We need to have the Exception class serialize itself
+ // with the correct namespace, which can change depending on which
+ // operation the exception is thrown from. We therefore have the
+ // framework call this generated routine with the correct QName,
+ // and allow it to serialize itself.
+ // method that serializes this exception (writeDetail)
+ pw.println();
+ pw.println(" /**");
+ pw.println(" * Writes the exception data to the faultDetails");
+ pw.println(" */");
+ pw.println(
+ " public void writeDetails(javax.xml.namespace.QName qname, org.apache.axis.encoding.SerializationContext context) throws java.io.IOException {");
+ pw.println(" context.serialize(qname, null, this);");
+ pw.println(" }");
+ super.writeFileFooter(pw);
+ } // writeFileFooter
+} // class JavaBeanFaultWriter