Example usage for javax.xml.namespace QName getLocalPart

List of usage examples for javax.xml.namespace QName getLocalPart

Introduction

In this page you can find the example usage for javax.xml.namespace QName getLocalPart.

Prototype

public String getLocalPart() 

Source Link

Document

Get the local part of this QName.

Usage

From source file:org.apache.axis.wsdl.fromJava.Types.java

/**
 * Create an array which is a wrapper type for "item" elements
 * of a component type.  This is basically the unencoded parallel to
 * a SOAP-encoded array.//w w  w . j  a va 2 s  . co  m
 *
 * @param componentType
 * @param itemName the QName of the inner element (right now we only use the localPart)
 * @return
 */
public Element createLiteralArrayElement(String componentType, QName itemName) {
    String itemLocalName = "item";
    if (itemName != null) {
        itemLocalName = itemName.getLocalPart();
    }

    Element complexType = docHolder.createElement("complexType");
    Element sequence = docHolder.createElement("sequence");

    complexType.appendChild(sequence);

    Element elem = docHolder.createElement("element");
    elem.setAttribute("name", itemLocalName);
    elem.setAttribute("type", componentType);
    elem.setAttribute("minOccurs", "0");
    elem.setAttribute("maxOccurs", "unbounded");

    sequence.appendChild(elem);

    return complexType;
}

From source file:org.apache.axis.wsdl.fromJava.Types.java

/**
 * Write Enumeration Complex Type/*from w ww.j  a  v a 2s.  com*/
 * (Only supports enumeration classes of string types)
 *
 * @param qName QName of type.
 * @param cls   class of type
 * @return
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws AxisFault
 */
public Element writeEnumType(QName qName, Class cls)
        throws NoSuchMethodException, IllegalAccessException, AxisFault {

    if (!isEnumClass(cls)) {
        return null;
    }

    // Get the base type of the enum class
    java.lang.reflect.Method m = cls.getMethod("getValue", null);
    Class base = m.getReturnType();

    // Create simpleType, restriction elements
    Element simpleType = docHolder.createElement("simpleType");

    simpleType.setAttribute("name", qName.getLocalPart());

    Element restriction = docHolder.createElement("restriction");

    simpleType.appendChild(restriction);

    String baseType = writeType(base, null);

    restriction.setAttribute("base", baseType);

    // Create an enumeration using the field values
    Field[] fields = cls.getDeclaredFields();

    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        int mod = field.getModifiers();

        // Inspect each public static final field of the same type
        // as the base
        if (Modifier.isPublic(mod) && Modifier.isStatic(mod) && Modifier.isFinal(mod)
                && (field.getType() == base)) {

            // Create an enumeration using the value specified
            Element enumeration = docHolder.createElement("enumeration");

            enumeration.setAttribute("value", field.get(null).toString());
            restriction.appendChild(enumeration);
        }
    }

    return simpleType;
}

From source file:org.apache.axis.wsdl.fromJava.Types.java

/**
 * Create a top-level element declaration in our generated schema
 *
 * @param qname/*from   ww  w.ja  v a2 s .c o m*/
 * @param javaType
 * @param typeQName
 * @param nillable  nillable attribute of the element
 * @param itemQName
 * @throws AxisFault
 */
public void writeElementDecl(QName qname, Class javaType, QName typeQName, boolean nillable, QName itemQName)
        throws AxisFault {

    if (writtenElementQNames.contains(qname)) {
        return;
    }

    String name = qname.getLocalPart();

    Element element = docHolder.createElement("element");

    // Generate an element name that matches the type.
    element.setAttribute("name", name);

    if (nillable) {
        element.setAttribute("nillable", "true");
    }

    /*
     * These are not legal on top-level elements!
     * (feel free to delete this block after say Oct 2005)
    if (omittable) {
    element.setAttribute("minOccurs", "0");
    element.setAttribute("maxOccurs", "1");
    }
            
    if (javaType.isArray()) {
    element.setAttribute("maxOccurs", "unbounded");
    }
    */

    if (javaType.isArray()) {
        // TODO : Should check to see if this array type is specifically mapped
        String componentType = writeType(javaType.getComponentType());
        Element complexType = createLiteralArrayElement(componentType, itemQName);
        element.appendChild(complexType);
    } else {
        // Write the type for this element, handling anonymous or named
        // types appropriately.
        makeTypeElement(javaType, typeQName, element);
    }

    writeSchemaElementDecl(qname, element);
}

From source file:org.apache.axis.wsdl.fromJava.Types.java

/**
 * Add the type to an ArrayList and return true if the Schema node
 * needs to be generated/*from  www.  j  a  v a  2 s .c o  m*/
 * If the type already exists, just return false to indicate that the type is already
 * generated in a previous iteration
 *
 * @param qName of the type.
 * @return if the type is added returns true,
 *         else if the type is already present returns false
 */
private boolean addToTypesList(QName qName) {

    boolean added = false;
    String namespaceURI = qName.getNamespaceURI();
    ArrayList types = (ArrayList) schemaTypes.get(namespaceURI);

    // Quick return if schema type (will never add these ourselves)
    if (Constants.isSchemaXSD(namespaceURI)
            || (Constants.isSOAP_ENC(namespaceURI) && !"Array".equals(qName.getLocalPart()))) {

        // Make sure we do have the namespace declared, though...
        writeTypeNamespace(namespaceURI);

        return false;
    }

    if (types == null) {
        types = new ArrayList();

        types.add(qName.getLocalPart());

        writeTypeNamespace(namespaceURI);
        schemaTypes.put(namespaceURI, types);

        added = true;
    } else {
        if (!types.contains(qName.getLocalPart())) {
            types.add(qName.getLocalPart());

            added = true;
        }
    }

    // If addded, look at the namespace uri to see if the schema element should be
    // generated.
    if (added) {
        String prefix = namespaces.getCreatePrefix(namespaceURI);

        if (prefix.equals(Constants.NS_PREFIX_SOAP_ENV) || prefix.equals(Constants.NS_PREFIX_SOAP_ENC)
                || prefix.equals(Constants.NS_PREFIX_SCHEMA_XSD) || prefix.equals(Constants.NS_PREFIX_WSDL)
                || prefix.equals(Constants.NS_PREFIX_WSDL_SOAP)) {
            return false;
        } else {
            return true;
        }
    }

    return false;
}

From source file:org.apache.axis.wsdl.fromJava.Types.java

/**
 * Add the element to an ArrayList and return true if the Schema element
 * needs to be generated//from   w  w w.java 2  s.c om
 * If the element already exists, just return false to indicate that the type is already
 * generated in a previous iteration
 *
 * @param qName the name space of the element
 * @return if the type is added returns true, else if the type is already present returns false
 */
private boolean addToElementsList(QName qName) {

    if (qName == null) {
        return false;
    }

    boolean added = false;
    ArrayList elements = (ArrayList) schemaElementNames.get(qName.getNamespaceURI());

    if (elements == null) {
        elements = new ArrayList();

        elements.add(qName.getLocalPart());
        schemaElementNames.put(qName.getNamespaceURI(), elements);

        added = true;
    } else {
        if (!elements.contains(qName.getLocalPart())) {
            elements.add(qName.getLocalPart());

            added = true;
        }
    }

    return added;
}

From source file:org.apache.axis.wsdl.fromJava.Types.java

/**
 * Create a schema type element (either simpleType or complexType) for
 * the particular type/qName combination.  If the type is named, we
 * handle inserting the new type into the appropriate &lt;schema&gt;
 * in the WSDL types section.  If the type is anonymous, we append the
 * definition underneath the Element which was passed as the container
 * (typically a field of a higher-level type or a parameter in a wrapped
 * operation).//ww w  .jav  a 2  s.  c  o m
 *
 * @param type              Java type to write
 * @param qName             the desired type QName
 * @param containingElement a schema element ("element" or "attribute")
 *                          which should either receive a type="" attribute decoration
 *                          (for named types) or a child element defining an anonymous
 *                          type
 * @return true if the type was already present or was added, false if there was a problem
 * @throws AxisFault
 */
private boolean makeTypeElement(Class type, QName qName, Element containingElement) throws AxisFault {

    // Get a corresponding QName if one is not provided
    if ((qName == null) || Constants.equals(Constants.SOAP_ARRAY, qName)) {
        qName = getTypeQName(type);
    }

    boolean anonymous = isAnonymousType(qName);

    // Can't have an anonymous type outside of a containing element
    if (anonymous && (containingElement == null)) {
        throw new AxisFault(Messages.getMessage("noContainerForAnonymousType", qName.toString()));
    }

    // If we've already got this type (because it's a native type or
    // because we've already written it), just add the type="" attribute
    // (if appropriate) and return.
    if (!addToTypesList(qName) && !anonymous) {
        if (containingElement != null) {
            containingElement.setAttribute("type", getQNameString(qName));
        }

        return true;
    }

    // look up the serializer in the TypeMappingRegistry
    SerializerFactory factory;
    factory = (SerializerFactory) tm.getSerializer(type, qName);

    // If no factory is found, use the BeanSerializerFactory
    // if applicable, otherwise issue errors and treat as an anyType
    if (factory == null) {
        if (isEnumClass(type)) {
            factory = new EnumSerializerFactory(type, qName);
        } else if (isBeanCompatible(type, true)) {
            factory = new BeanSerializerFactory(type, qName);
        } else {
            return false;
        }
    }

    // factory is not null
    Serializer ser = (Serializer) factory.getSerializerAs(Constants.AXIS_SAX);

    // if we can't get a serializer, that is bad.
    if (ser == null) {
        throw new AxisFault(Messages.getMessage("NoSerializer00", type.getName()));
    }

    Element typeEl;

    try {
        typeEl = ser.writeSchema(type, this);
    } catch (Exception e) {
        throw AxisFault.makeFault(e);
    }

    // If this is an anonymous type, just make the type element a child
    // of containingElement.  If not, set the "type" attribute of
    // containingElement to the right QName, and make sure the type is
    // correctly written into the appropriate <schema> element.
    if (anonymous) {
        if (typeEl == null) {
            containingElement.setAttribute("type", getQNameString(getTypeQName(type)));
        } else {
            containingElement.appendChild(typeEl);
        }
    } else {
        if (typeEl != null) {
            typeEl.setAttribute("name", qName.getLocalPart());

            // Write the type in the appropriate <schema>
            writeSchemaTypeDecl(qName, typeEl);
        }

        if (containingElement != null) {
            containingElement.setAttribute("type", getQNameString(qName));
        }
    }

    // store the mapping of type qname and its correspoding java type   
    if (emitter != null) {
        emitter.getQName2ClassMap().put(qName, type);
    }

    return true;
}

From source file:org.apache.axis.wsdl.toJava.JavaDeployWriter.java

/**
 * Write out deployment and undeployment instructions for given WSDL port
 *
 * @param pw// w w w.ja v a2s  . com
 * @param port
 * @param service
 * @param bEntry
 * @throws IOException
 */
protected void writeDeployPort(PrintWriter pw, Port port, Service service, BindingEntry bEntry)
        throws IOException {

    String serviceName = port.getName();
    boolean hasLiteral = bEntry.hasLiteral();
    boolean hasMIME = Utils.hasMIME(bEntry);
    String prefix = WSDDConstants.NS_PREFIX_WSDD_JAVA;
    String styleStr = "";
    Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator();

    while (iterator.hasNext()) {
        Object obj = iterator.next();

        if (obj instanceof SOAPBinding) {
            use = Use.ENCODED;
        } else if (obj instanceof UnknownExtensibilityElement) {

            // TODO: After WSDL4J supports soap12, change this code
            UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
            QName name = unkElement.getElementType();

            if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP)
                    && name.getLocalPart().equals("binding")) {
                use = Use.ENCODED;
            }
        }
    }

    if (symbolTable.isWrapped()) {
        styleStr = " style=\"" + Style.WRAPPED + "\"";
        use = Use.LITERAL;
    } else {
        styleStr = " style=\"" + bEntry.getBindingStyle().getName() + "\"";

        if (hasLiteral) {
            use = Use.LITERAL;
        }
    }

    String useStr = " use=\"" + use + "\"";

    pw.println("  <service name=\"" + serviceName + "\" provider=\"" + prefix + ":RPC" + "\"" + styleStr
            + useStr + ">");
    pw.println("      <parameter name=\"wsdlTargetNamespace\" value=\"" + service.getQName().getNamespaceURI()
            + "\"/>");
    pw.println("      <parameter name=\"wsdlServiceElement\" value=\"" + service.getQName().getLocalPart()
            + "\"/>");
    // MIME attachments don't work with multiref, so turn it off.
    if (hasMIME) {
        pw.println("      <parameter name=\"sendMultiRefs\" value=\"false\"/>");
    }
    ArrayList qualified = new ArrayList();
    ArrayList unqualified = new ArrayList();
    Map elementFormDefaults = symbolTable.getElementFormDefaults();
    for (Iterator it = elementFormDefaults.entrySet().iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        if (entry.getValue().equals("qualified")) {
            qualified.add(entry.getKey());
        } else {
            unqualified.add(entry.getKey());
        }
    }
    if (qualified.size() > 0) {
        pw.print("      <parameter name=\"schemaQualified\" value=\"");
        for (int i = 0; i < qualified.size(); i++) {
            pw.print(qualified.get(i));
            if (i != qualified.size() - 1) {
                pw.print(',');
            }
        }
        pw.println("\"/>");
    }
    if (unqualified.size() > 0) {
        pw.print("      <parameter name=\"schemaUnqualified\" value=\"");
        for (int i = 0; i < unqualified.size(); i++) {
            pw.print(unqualified.get(i));
            if (i != unqualified.size() - 1) {
                pw.print(',');
            }
        }
        pw.println("\"/>");
    }
    pw.println("      <parameter name=\"wsdlServicePort\" value=\"" + serviceName + "\"/>");

    writeDeployBinding(pw, bEntry);
    writeDeployTypes(pw, bEntry.getBinding(), hasLiteral, hasMIME, use);
    pw.println("  </service>");
}

From source file:org.apache.axis.wsdl.toJava.JavaGeneratorFactory.java

/** Refactored to call recursively for JAX-RPC 1.1 spec 4.2.5. */
protected int javifyTypeEntryName(SymbolTable symbolTable, TypeEntry entry, HashMap anonQNames, int uniqueNum) {
    TypeEntry tEntry = entry;/*from   w w w  . j a v  a  2  s.c o m*/
    String dims = tEntry.getDimensions();
    TypeEntry refType = tEntry.getRefType();
    while (refType != null) {
        tEntry = refType;
        dims += tEntry.getDimensions();
        refType = tEntry.getRefType();
    }

    TypeEntry te = tEntry;
    while (te != null) {
        TypeEntry base = SchemaUtils.getBaseType(te, symbolTable);
        if (base == null)
            break;

        uniqueNum = javifyTypeEntryName(symbolTable, base, anonQNames, uniqueNum);

        if (Utils.getEnumerationBaseAndValues(te.getNode(), symbolTable) == null
                && SchemaUtils.getComplexElementExtensionBase(te.getNode(), symbolTable) == null
                && te.getContainedAttributes() == null) {
            if (!SchemaUtils.isSimpleTypeWithUnion(te.getNode())) {
                if (base.isSimpleType()) {
                    // Case 1:
                    // <simpleType name="mySimpleStringType">
                    //   <restriction base="xs:string">
                    //   </restriction>
                    // </simpleType>
                    te.setSimpleType(true);
                    te.setName(base.getName());
                    te.setRefType(base);
                }

                if (base.isBaseType()) {
                    // Case 2:
                    // <simpleType name="FooString">
                    //   <restriction base="foo:mySimpleStringType">
                    //   </restriction>
                    // </simpleType>
                    te.setBaseType(true);
                    te.setName(base.getName());
                    te.setRefType(base);
                }
            }
        }

        if (!te.isSimpleType())
            break;

        te = base;
    }

    // Need to javify the ref'd TypeEntry if it was not
    // already processed
    if (tEntry.getName() == null) {
        boolean processed = false; // true if the java name is already determined
        // Get the QName of the ref'd TypeEntry, which
        // is will be used to javify the name
        QName typeQName = tEntry.getQName();

        // In case of <xsd:list itemType="...">,
        // set typeQName to the value of the itemType attribute.
        QName itemType = SchemaUtils.getListItemType(tEntry.getNode());
        if (itemType != null) {
            // Get the typeEntry so we know the absolute base type
            TypeEntry itemEntry = symbolTable.getTypeEntry(itemType, false);
            // TODO - If the itemEntry is not found, we need to throw
            // an exception.  "Item is referenced, but not defined"
            javifyTypeEntryName(symbolTable, itemEntry, anonQNames, uniqueNum);
            // Grab the referenced type, If it's there.
            TypeEntry refedEntry = itemEntry.getRefType();
            QName baseName = refedEntry == null ? itemEntry.getQName() : refedEntry.getQName();
            typeQName = new QName(baseName.getNamespaceURI(), baseName.getLocalPart() + "[]");
        }

        if (emitter.isDeploy()) {
            Class class1 = (Class) emitter.getQName2ClassMap().get(typeQName);
            if (class1 != null && !class1.isArray()) {
                tEntry.setName(getJavaClassName(class1));
                processed = true;
            }
        }

        if (!processed) {
            if ((typeQName.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) < 0)) {
                // Normal Case: The ref'd type is not anonymous
                // Simply construct the java name from
                // the qName
                tEntry.setName(emitter.getJavaName(typeQName));
            } else {
                // This is an anonymous type name.
                // Axis uses '>' as a nesting token to generate
                // unique qnames for anonymous types.
                // Only consider the localName after the last '>'
                // when generating the java name
                // String localName = typeQName.getLocalPart();
                // localName =
                // localName.substring(
                // localName.lastIndexOf(
                // SymbolTable.ANON_TOKEN)+1);
                // typeQName = new QName(typeQName.getNamespaceURI(),
                // localName);
                String localName = typeQName.getLocalPart();

                // Check to see if this is an anonymous type,
                // if it is, replace Axis' ANON_TOKEN with
                // an underscore to make sure we don't run
                // into name collisions with similarly named
                // non-anonymous types
                StringBuffer sb = new StringBuffer(localName);
                int aidx;

                while ((aidx = sb.toString().indexOf(SymbolTable.ANON_TOKEN)) > -1) {
                    sb.replace(aidx, aidx + SymbolTable.ANON_TOKEN.length(), "");
                    char c = sb.charAt(aidx);
                    if (Character.isLetter(c) && Character.isLowerCase(c)) {
                        sb.setCharAt(aidx, Character.toUpperCase(c));
                    }
                }

                localName = sb.toString();
                typeQName = new QName(typeQName.getNamespaceURI(), localName);

                if (emitter.isTypeCollisionProtection() && !emitter.getNamespaceExcludes()
                        .contains(new NamespaceSelector(typeQName.getNamespaceURI()))) {
                    // If there is already an existing type,
                    // there will be a collision.
                    // If there is an existing anon type,
                    // there will be a  collision.
                    // In both cases, mangle the name.
                    if (symbolTable.getType(typeQName) != null || anonQNames.get(typeQName) != null) {
                        localName += "Type" + uniqueNum++;
                        typeQName = new QName(typeQName.getNamespaceURI(), localName);
                    }

                    anonQNames.put(typeQName, typeQName);
                }

                // Now set the name with the constructed qname
                tEntry.setName(emitter.getJavaName(typeQName));
            }
        } // if (!processed)

        Vector elements = tEntry.getContainedElements();
        if (elements != null) {
            for (int i = 0; i < elements.size(); i++) {
                ElementDecl elem = (ElementDecl) elements.get(i);
                String varName = emitter.getJavaVariableName(typeQName, elem.getQName(), true);
                elem.setName(varName);
            }
        }

        Vector attributes = tEntry.getContainedAttributes();
        if (attributes != null) {
            for (int i = 0; i < attributes.size(); i++) {
                ContainedAttribute attr = (ContainedAttribute) attributes.get(i);
                String varName = emitter.getJavaVariableName(typeQName, attr.getQName(), false);
                attr.setName(varName);
            }
        }
    }

    // Set the entry with the same name as the ref'd entry
    // but add the appropriate amount of dimensions
    entry.setName(tEntry.getName() + dims);

    return uniqueNum;
}

From source file:org.apache.axis.wsdl.toJava.JavaGeneratorFactory.java

/**
 * Messages, PortTypes, Bindings, and Services can share the same name.  If they do in this
 * Definition, force their names to be suffixed with _PortType and _Service, respectively.
 *
 * @param symbolTable//  w  ww.  j  a  v a 2s  .  c om
 */
protected void resolveNameClashes(SymbolTable symbolTable) {

    // Keep a list of anonymous types so we don't try to resolve them twice.
    HashSet anonTypes = new HashSet();
    List collisionCandidates = new ArrayList(); // List of vector of SymbolTable entry

    List localParts = new ArrayList(); // all localparts in all symboltable entries        
    for (Iterator i = symbolTable.getHashMap().keySet().iterator(); i.hasNext();) {
        QName qName = (QName) i.next();
        String localPart = qName.getLocalPart();
        if (!localParts.contains(localPart))
            localParts.add(localPart);
    }

    Map pkg2NamespacesMap = emitter.getNamespaces().getPkg2NamespacesMap();
    for (Iterator i = pkg2NamespacesMap.values().iterator(); i.hasNext();) {
        Vector namespaces = (Vector) i.next(); // namepaces mapped to same package

        // Combine entry vectors, which have the same entry name, into a new entry vector.
        for (int j = 0; j < localParts.size(); j++) {
            Vector v = new Vector();
            for (int k = 0; k < namespaces.size(); k++) {
                QName qName = new QName((String) namespaces.get(k), (String) localParts.get(j));
                if (symbolTable.getHashMap().get(qName) != null) {
                    v.addAll((Vector) symbolTable.getHashMap().get(qName));
                }
            }
            if (v.size() > 0) {
                collisionCandidates.add(v);
            }
        }
    }
    Iterator it = collisionCandidates.iterator();

    while (it.hasNext()) {
        Vector v = new Vector((Vector) it.next()); // New vector we can temporarily add to it

        // Remove MessageEntries since they are not mapped
        int index = 0;

        while (index < v.size()) {
            if (v.elementAt(index) instanceof MessageEntry) {
                // Need to resolve a Exception message.
                MessageEntry msgEntry = (MessageEntry) v.elementAt(index);
                if (msgEntry.getDynamicVar(EXCEPTION_CLASS_NAME) == null) {
                    v.removeElementAt(index);
                } else {
                    index++;
                }
            } else {
                index++;
            }
        }

        if (v.size() > 1) {
            boolean resolve = true;

            // Common Special Case:
            // If a Type and Element have the same QName, and the Element
            // references the Type, then they are the same class so
            // don't bother mangling.
            if (v.size() == 2 && ((v.elementAt(0) instanceof Element && v.elementAt(1) instanceof Type)
                    || (v.elementAt(1) instanceof Element && v.elementAt(0) instanceof Type))) {
                Element e;
                if (v.elementAt(0) instanceof Element) {
                    e = (Element) v.elementAt(0);
                } else {
                    e = (Element) v.elementAt(1);
                }

                BooleanHolder forElement = new BooleanHolder();
                QName eType = Utils.getTypeQName(e.getNode(), forElement, false);

                if ((eType != null) && !forElement.value) {
                    resolve = false;
                }
            }

            // Other Special Case:
            // If the names are already different, no mangling is needed.
            if (resolve) {
                resolve = false; // Assume false

                String name = null;

                for (int i = 0; (i < v.size()) && !resolve; ++i) {
                    SymTabEntry entry = (SymTabEntry) v.elementAt(i);

                    if ((entry instanceof MessageEntry) || (entry instanceof BindingEntry)) {
                        // Need to resolve a exception class name                            
                        String exceptionClassName = (String) entry.getDynamicVar(EXCEPTION_CLASS_NAME);
                        if (exceptionClassName != null) {
                            if (name == null) {
                                name = exceptionClassName;
                            } else if (name.equals(exceptionClassName)) {
                                resolve = true;
                            }
                        }
                    } else if (name == null) {
                        name = entry.getName();
                    } else if (name.equals(entry.getName())) {
                        resolve = true; // Need to do resolution
                    }
                }
            }

            // Full Mangle if resolution is necessary.
            if (resolve) {
                boolean firstType = true;

                for (int i = 0; i < v.size(); ++i) {
                    SymTabEntry entry = (SymTabEntry) v.elementAt(i);

                    if (entry instanceof Element) {
                        entry.setName(mangleName(entry.getName(), ELEMENT_SUFFIX));

                        // If this global element was defined using
                        // an anonymous type, then need to change the
                        // java name of the anonymous type to match.
                        QName anonQName = new QName(entry.getQName().getNamespaceURI(),
                                SymbolTable.ANON_TOKEN + entry.getQName().getLocalPart());

                        TypeEntry anonType = symbolTable.getType(anonQName);

                        if (anonType != null) {
                            anonType.setName(entry.getName());
                            anonTypes.add(anonType);
                        }
                    } else if (entry instanceof TypeEntry) {

                        // Search all other types for java names that match this one.
                        // The sameJavaClass method returns true if the java names are
                        // the same (ignores [] ).
                        if (firstType) {
                            firstType = false;

                            Iterator types = symbolTable.getTypeIndex().values().iterator();

                            while (types.hasNext()) {
                                TypeEntry type = (TypeEntry) types.next();

                                if ((type != entry) && (type.getBaseType() == null)
                                        && sameJavaClass(entry.getName(), type.getName())) {
                                    v.add(type);
                                }
                            }
                        }

                        // If this is an anonymous type, it's name was resolved in
                        // the previous if block.  Don't reresolve it.
                        if (!anonTypes.contains(entry)) {
                            // In case that other entry in name collision among 
                            // PortTypeEntry, ServiceEntry and BindingEntry

                            boolean needResolve = false;

                            // check collision of TypeEntry with PortTypeEntry, ServiceEtnry and/or BindingEntry 
                            for (int j = 0; j < v.size(); j++) {
                                SymTabEntry e = (SymTabEntry) v.elementAt(j);
                                if ((e instanceof PortTypeEntry || e instanceof ServiceEntry
                                        || e instanceof BindingEntry)) {
                                    needResolve = true;
                                    break;
                                }
                            }

                            if (!needResolve) {
                                continue;
                            }

                            // Appended Suffix for avoiding name collisions (JAX-RPC 1.1)
                            Boolean isComplexTypeFault = (Boolean) entry.getDynamicVar(COMPLEX_TYPE_FAULT);
                            if ((isComplexTypeFault != null) && isComplexTypeFault.booleanValue()) {
                                entry.setName(mangleName(entry.getName(), EXCEPTION_SUFFIX));
                            } else {
                                entry.setName(mangleName(entry.getName(), TYPE_SUFFIX));
                            }

                            // should update the class name of ElementEntry which references this type entry
                            Map elementIndex = symbolTable.getElementIndex();
                            List elements = new ArrayList(elementIndex.values());
                            for (int j = 0; j < elementIndex.size(); j++) {
                                TypeEntry te = (TypeEntry) elements.get(j);
                                TypeEntry ref = te.getRefType();
                                if (ref != null && entry.getQName().equals(ref.getQName())) {
                                    te.setName(entry.getName());
                                }
                            }

                            // Need to resolve a complex-type exception message.
                            if ((isComplexTypeFault != null) && isComplexTypeFault.booleanValue()) {
                                // SHOULD update the exception class name of a referencing message entry.
                                List messageEntries = symbolTable.getMessageEntries();
                                for (int j = 0; j < messageEntries.size(); j++) {
                                    MessageEntry messageEntry = (MessageEntry) messageEntries.get(j);
                                    Boolean isComplexTypeFaultMsg = (Boolean) messageEntry
                                            .getDynamicVar(COMPLEX_TYPE_FAULT);
                                    if ((isComplexTypeFaultMsg != null)
                                            && (isComplexTypeFaultMsg.booleanValue())) {
                                        QName exceptionDataType = (QName) messageEntry
                                                .getDynamicVar(EXCEPTION_DATA_TYPE);
                                        if (((TypeEntry) entry).getQName().equals(exceptionDataType)) {
                                            String className = (String) messageEntry
                                                    .getDynamicVar(EXCEPTION_CLASS_NAME);
                                            messageEntry.setDynamicVar(EXCEPTION_CLASS_NAME,
                                                    className + EXCEPTION_SUFFIX);
                                        }
                                    }
                                }
                            }
                        }
                    } else if (entry instanceof PortTypeEntry) {
                        entry.setName(mangleName(entry.getName(), PORT_TYPE_SUFFIX)); // "_Port" --> "_PortType" for JAX-RPC 1.1
                    } else if (entry instanceof ServiceEntry) {
                        entry.setName(mangleName(entry.getName(), SERVICE_SUFFIX));
                    } else if (entry instanceof MessageEntry) {
                        Boolean complexTypeFault = (Boolean) entry.getDynamicVar(COMPLEX_TYPE_FAULT);
                        if ((complexTypeFault == null) || !complexTypeFault.booleanValue()) {
                            String exceptionClassName = (String) entry.getDynamicVar(EXCEPTION_CLASS_NAME);
                            entry.setDynamicVar(EXCEPTION_CLASS_NAME, exceptionClassName + EXCEPTION_SUFFIX);
                        }
                    }
                    // else if (entry instanceof MessageEntry) {
                    // we don't care about messages
                    // }
                    else if (entry instanceof BindingEntry) {
                        BindingEntry bEntry = (BindingEntry) entry;

                        // If there is no literal use, then we never see a
                        // class named directly from the binding name.  They
                        // all have suffixes:  Stub, Skeleton, Impl.
                        // If there IS literal use, then the SDI will be
                        // named after the binding name, so there is the
                        // possibility of a name clash.
                        if (bEntry.hasLiteral()) {
                            entry.setName(mangleName(entry.getName(), BINDING_SUFFIX));
                        }
                    }
                }
            }
        }
    }
}

From source file:org.apache.axis.wsdl.toJava.JavaGeneratorFactory.java

/**
 * Method getBaseTypeMapping//from   w w  w.ja  va2  s  . c om
 *
 * @return
 */
public BaseTypeMapping getBaseTypeMapping() {
    if (btm == null) {
        btm = new BaseTypeMapping() {

            public String getBaseName(QName qNameIn) {

                javax.xml.namespace.QName qName = new javax.xml.namespace.QName(qNameIn.getNamespaceURI(),
                        qNameIn.getLocalPart());
                Class cls = emitter.getDefaultTypeMapping().getClassForQName(qName);

                if (cls == null) {
                    return null;
                } else {
                    return JavaUtils.getTextClassName(cls.getName());
                }
            }
        };
    }

    return btm;
}