Example usage for javax.xml.namespace QName getNamespaceURI

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

Introduction

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

Prototype

public String getNamespaceURI() 

Source Link

Document

Get the Namespace URI of this QName.

Usage

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

/**
 * Method writeSchemaElementDecl//from w ww . j  a  va  2  s.  c o m
 *
 * @param qname
 * @param element
 * @throws AxisFault
 */
public void writeSchemaElementDecl(QName qname, Element element) throws AxisFault {

    if (writtenElementQNames.contains(qname)) {
        throw new AxisFault(Constants.FAULT_SERVER_GENERAL,
                Messages.getMessage("duplicateSchemaElement", qname.toString()), null, null);
    }

    writeSchemaElement(qname.getNamespaceURI(), element);
    writtenElementQNames.add(qname);
}

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

/**
 * @deprecated//from   ww w  .  j  a va2 s.  co  m
 * Please use writeSchemaElement(String namespaceURI, Element element) 
 *
 * @param qName qName to get the namespace of the schema node
 * @param element      the Element to append to the Schema node
 * @throws AxisFault
 */
public void writeSchemaElement(QName qName, Element element) throws AxisFault {
    writeSchemaElement(qName.getNamespaceURI(), element);
}

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

/**
 * Is the given class one of the simple types?  In other words,
 * do we have a mapping for this type which is in the xsd or
 * soap-enc namespaces?//  w w  w.  j  a v  a 2  s .c  o  m
 *
 * @param type input Class
 * @return true if the type is a simple type
 */
boolean isSimpleType(Class type) {

    QName qname = tm.getTypeQName(type);

    if (qname == null) {
        return false; // No mapping
    }

    String nsURI = qname.getNamespaceURI();

    return (Constants.isSchemaXSD(nsURI) || Constants.isSOAP_ENC(nsURI));
}

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   w w  w. ja v a  2s.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   ww  w. j a  v a  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.toJava.JavaDeployWriter.java

/**
 * Write out bean mappings for each type
 *
 * @param pw//from   w w  w .j  a  v  a2s.c o m
 * @param binding
 * @param hasLiteral
 * @param hasMIME
 * @param use
 * @throws IOException
 */
protected void writeDeployTypes(PrintWriter pw, Binding binding, boolean hasLiteral, boolean hasMIME, Use use)
        throws IOException {

    pw.println();

    if (hasMIME) {
        QName bQName = binding.getQName();

        writeTypeMapping(pw, bQName.getNamespaceURI(), "DataHandler", "javax.activation.DataHandler",
                "org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory",
                "org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory", use.getEncoding());
    }

    Map types = symbolTable.getTypeIndex();
    Collection typeCollection = types.values();
    for (Iterator i = typeCollection.iterator(); i.hasNext();) {
        TypeEntry type = (TypeEntry) i.next();

        // Note this same check is repeated in JavaStubWriter.
        boolean process = true;

        // Don't register types we shouldn't (see Utils.shouldEmit for
        // details)
        if (!Utils.shouldEmit(type)) {
            process = false;
        }

        if (process) {
            String namespaceURI = type.getQName().getNamespaceURI();
            String localPart = type.getQName().getLocalPart();
            String javaType = type.getName();
            String serializerFactory;
            String deserializerFactory;
            String encodingStyle = "";
            QName innerType = null;

            if (!hasLiteral) {
                encodingStyle = use.getEncoding();
            }

            if (javaType.endsWith("[]")) {
                if (SchemaUtils.isListWithItemType(type.getNode())) {
                    serializerFactory = "org.apache.axis.encoding.ser.SimpleListSerializerFactory";
                    deserializerFactory = "org.apache.axis.encoding.ser.SimpleListDeserializerFactory";
                } else {
                    serializerFactory = "org.apache.axis.encoding.ser.ArraySerializerFactory";
                    deserializerFactory = "org.apache.axis.encoding.ser.ArrayDeserializerFactory";
                    innerType = type.getComponentType();
                }
            } else if ((type.getNode() != null)
                    && (Utils.getEnumerationBaseAndValues(type.getNode(), symbolTable) != null)) {
                serializerFactory = "org.apache.axis.encoding.ser.EnumSerializerFactory";
                deserializerFactory = "org.apache.axis.encoding.ser.EnumDeserializerFactory";
            } else if (type.isSimpleType()) {
                serializerFactory = "org.apache.axis.encoding.ser.SimpleSerializerFactory";
                deserializerFactory = "org.apache.axis.encoding.ser.SimpleDeserializerFactory";
            } else if (type.getBaseType() != null) {
                serializerFactory = "org.apache.axis.encoding.ser.SimpleSerializerFactory";
                deserializerFactory = "org.apache.axis.encoding.ser.SimpleDeserializerFactory";
            } else {
                serializerFactory = "org.apache.axis.encoding.ser.BeanSerializerFactory";
                deserializerFactory = "org.apache.axis.encoding.ser.BeanDeserializerFactory";
            }

            if (innerType == null) {
                // no arrays
                writeTypeMapping(pw, namespaceURI, localPart, javaType, serializerFactory, deserializerFactory,
                        encodingStyle);
            } else {
                // arrays
                writeArrayTypeMapping(pw, namespaceURI, localPart, javaType, encodingStyle, innerType);
            }
        }
    }
}

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

/**
 * Write out deployment and undeployment instructions for given WSDL port
 *
 * @param pw//from   w w  w . j  ava 2s  . 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;//w w w. j  a  v a 2 s .  co  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

/**
 * Method getBaseTypeMapping//from  w  ww .j  a  va 2 s .c o m
 *
 * @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;
}

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

/**
 * Determines whether the QName supplied should be generated by comparing
 * the namespace for the QName against the included and excluded names.
 <p/>//from w ww  .j  a  va 2 s . c o m
 <ul>
 <li>if both the includes and excludes are both empty,
     the element is generated</li>
 <li>if the namespace is in the includes,
     the element is generated</li>
 <li>if the namespace is not in the excludes and the includes are empty,
     the element will be generated.
 <li>if the namespace is only in the excludes,
     the element is not generated</li>
 <li>if the namespace is not in the includes and the includes are not
     empty, the element is not generated</li>
@param qName
@return
 */
protected boolean include(QName qName) {
    String namespace = (qName != null && qName.getNamespaceURI() != null) ? qName.getNamespaceURI() : "";

    boolean doInclude = false;
    NamespaceSelector selector = new NamespaceSelector(namespace);
    if (qName == null || emitter == null || emitter.getNamespaceIncludes().contains(selector)
            || (emitter.getNamespaceIncludes().size() == 0
                    && !emitter.getNamespaceExcludes().contains(selector))) {
        doInclude = true;
    } else {
        log_.info("excluding code generation for non-included QName:" + qName);

    }
    return doInclude;
}