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

/**
 * Walk the type/element entries in the symbol table and
 * add each one to the list of processed types. This prevents
 * the types from being duplicated.//  w  w  w  .jav  a2 s  .  c  o m
 *
 * @param symbolTable
 */
private void processSymTabEntries(SymbolTable symbolTable) {

    Iterator iterator = symbolTable.getElementIndex().entrySet().iterator();

    while (iterator.hasNext()) {
        Map.Entry me = (Map.Entry) iterator.next();
        QName name = (QName) me.getKey();
        TypeEntry te = (TypeEntry) me.getValue();
        String prefix = XMLUtils.getPrefix(name.getNamespaceURI(), te.getNode());

        if (!((null == prefix) || "".equals(prefix))) {
            namespaces.putPrefix(name.getNamespaceURI(), prefix);
            def.addNamespace(prefix, name.getNamespaceURI());
        }

        addToElementsList(name);
    }

    iterator = symbolTable.getTypeIndex().entrySet().iterator();

    while (iterator.hasNext()) {
        Map.Entry me = (Map.Entry) iterator.next();
        QName name = (QName) me.getKey();
        TypeEntry te = (TypeEntry) me.getValue();
        String prefix = XMLUtils.getPrefix(name.getNamespaceURI(), te.getNode());

        if (!((null == prefix) || "".equals(prefix))) {
            namespaces.putPrefix(name.getNamespaceURI(), prefix);
            def.addNamespace(prefix, name.getNamespaceURI());
        }

        addToTypesList(name);
    }
}

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

/**
 * Load the types from the input wsdl file.
 *
 * @param inputWSDL file or URL/*from  w ww .  ja  va2 s  . c o  m*/
 * @throws IOException
 * @throws WSDLException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public void loadInputTypes(String inputWSDL)
        throws IOException, WSDLException, SAXException, ParserConfigurationException {

    // Read the input wsdl file into a Document
    Document doc = XMLUtils.newDocument(inputWSDL);

    // Search for the 'types' element
    NodeList elements = doc.getChildNodes();

    if ((elements.getLength() > 0) && elements.item(0).getLocalName().equals("definitions")) {
        elements = elements.item(0).getChildNodes();

        for (int i = 0; (i < elements.getLength()) && (wsdlTypesElem == null); i++) {
            Node node = elements.item(i);

            if ((node.getLocalName() != null) && node.getLocalName().equals("types")) {
                wsdlTypesElem = (Element) node;
            }
        }
    }

    // If types element not found, there is no need to continue.
    if (wsdlTypesElem == null) {
        return;
    }

    // Import the types element into the Types docHolder document
    wsdlTypesElem = (Element) docHolder.importNode(wsdlTypesElem, true);

    docHolder.appendChild(wsdlTypesElem);

    // Create a symbol table and populate it with the input wsdl document
    BaseTypeMapping btm = new BaseTypeMapping() {

        public String getBaseName(QName qNameIn) {

            QName qName = new QName(qNameIn.getNamespaceURI(), qNameIn.getLocalPart());
            Class cls = tm.getClassForQName(qName);

            if (cls == null) {
                return null;
            } else {
                return JavaUtils.getTextClassName(cls.getName());
            }
        }
    };
    SymbolTable symbolTable = new SymbolTable(btm, true, false, false);

    symbolTable.populate(null, doc);
    processSymTabEntries(symbolTable);
}

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

/**
 * Write out a type referenced by a part type attribute.
 *
 * @param type  <code>Class</code> to generate the XML Schema info for
 * @param qname <code>QName</code> of the type.  If null, qname is
 *              defaulted from the class.
 * @return the QName of the generated Schema type, null if void,
 *         if the Class type cannot be converted to a schema type
 *         then xsd:anytype is returned.
 * @throws AxisFault//from   w w w  .j av  a2  s.c  o  m
 */
public QName writeTypeForPart(Class type, QName qname) throws AxisFault {

    // patch by costin to fix an NPE; commented out till we find out what the problem is
    // if you get NullPointerExceptions in this class, turn it on and submit some
    // replicable test data to the Axis team via bugzilla

    /*
    * if( type==null ) {
    *   return null;
    * }
    */
    if (type.getName().equals("void")) {
        return null;
    }

    if (Holder.class.isAssignableFrom(type)) {
        type = JavaUtils.getHolderValueType(type);
    }

    // Get the qname
    if ((qname == null)
            || (Constants.isSOAP_ENC(qname.getNamespaceURI()) && "Array".equals(qname.getLocalPart()))) {
        qname = getTypeQName(type);

        if (qname == null) {
            throw new AxisFault("Class:" + type.getName());
        }
    }

    if (!makeTypeElement(type, qname, null)) {
        qname = Constants.XSD_ANYTYPE;
    }

    return qname;
}

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

/**
 * Write out an element referenced by a part element attribute.
 *
 * @param type  <code>Class</code> to generate the XML Schema info for
 * @param qname <code>QName</code> of the element.  If null, qname is
 *              defaulted from the class.
 * @return the QName of the generated Schema type, null if no element
 * @throws AxisFault// ww w .  j  a  v a 2  s . co  m
 */
public QName writeElementForPart(Class type, QName qname) throws AxisFault {

    // patch by costin to fix an NPE; commented out till we find out what the problem is
    // if you get NullPointerExceptions in this class, turn it on and submit some
    // replicable test data to the Axis team via bugzilla

    /*
    * if( type==null ) {
    *   return null;
    * }
    */
    if (type.getName().equals("void")) {
        return null;
    }

    if (Holder.class.isAssignableFrom(type)) {
        type = JavaUtils.getHolderValueType(type);
    }

    // Get the qname
    if ((qname == null)
            || (Constants.isSOAP_ENC(qname.getNamespaceURI()) && "Array".equals(qname.getLocalPart()))) {
        qname = getTypeQName(type);

        if (qname == null) {
            throw new AxisFault("Class:" + type.getName());
        }
    }

    // Return null it a simple type (not an element)
    String nsURI = qname.getNamespaceURI();

    if (Constants.isSchemaXSD(nsURI)
            || (Constants.isSOAP_ENC(nsURI) && !"Array".equals(qname.getLocalPart()))) {
        return null;
    }

    // Make sure a types section is present
    if (wsdlTypesElem == null) {
        writeWsdlTypesElement();
    }

    // Write Element, if problems occur return null.
    if (writeTypeAsElement(type, qname) == null) {
        qname = null;
    }

    return qname;
}

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

/**
 * Write the element definition for a WRAPPED operation.  This will
 * write out any necessary namespace/schema declarations, an an element
 * definition with an internal (anonymous) complexType.  The name of the
 * element will be *foo*Request or *foo*Response depending on whether the
 * request boolean is true.  If the operation contains parameters, then
 * we also generate a &gt;sequence&lt; node underneath the complexType,
 * and return it for later use by writeWrappedParameter() below.
 *
 * @param qname     the desired element QName
 * @param request   true if we're writing the request wrapper, false if
 *                  writing the response.
 * @param hasParams true if there are parameters, and thus a sequence
 *                  node is needed/*from www  .  j a va  2s. c  o m*/
 * @return a DOM Element for the sequence, inside which we'll write the
 *         parameters as elements, or null if there are no parameters
 * @throws AxisFault
 */
public Element writeWrapperElement(QName qname, boolean request, boolean hasParams) throws AxisFault {

    // Make sure a types section is present
    if (wsdlTypesElem == null) {
        writeWsdlTypesElement();
    }

    // Write the namespace definition for the wrapper
    writeTypeNamespace(qname.getNamespaceURI());

    // Create an <element> for the wrapper
    Element wrapperElement = docHolder.createElement("element");

    writeSchemaElementDecl(qname, wrapperElement);
    wrapperElement.setAttribute("name", qname.getLocalPart());

    // Create an anonymous <complexType> for the wrapper
    Element complexType = docHolder.createElement("complexType");

    wrapperElement.appendChild(complexType);

    // If we have parameters in the operation, create a <sequence>
    // under the complexType and return it.
    if (hasParams) {
        Element sequence = docHolder.createElement("sequence");

        complexType.appendChild(sequence);

        return sequence;
    }

    return null;
}

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

/**
 * Write a parameter (a sub-element) into a sequence generated by
 * writeWrapperElement() above./*from  w w  w  .jav  a2s . c om*/
 *
 * @param sequence the &lt;sequence&gt; in which we're writing
 * @param name     is the name of an element to add to the wrapper element.
 * @param type     is the QName of the type of the element.
 * @param javaType
 * @throws AxisFault
 */
public void writeWrappedParameter(Element sequence, String name, QName type, Class javaType) throws AxisFault {

    if (javaType == void.class) {
        return;
    }

    // JAX-RPC 1.1 says that byte[] should always be a Base64Binary
    // This (rather strange) hack will ensure that we don't map it
    // in to an maxoccurs=unbounded array.
    if (javaType.isArray() && !javaType.equals(byte[].class)) {
        type = writeTypeForPart(javaType.getComponentType(), null);
    } else {
        type = writeTypeForPart(javaType, type);
    }

    if (type == null) {
        // TODO: throw an Exception!!
        return;
    }

    Element childElem;

    if (isAnonymousType(type)) {
        childElem = createElementWithAnonymousType(name, javaType, false, docHolder);
    } else {

        // Create the child <element> and add it to the wrapper <sequence>
        childElem = docHolder.createElement("element");

        childElem.setAttribute("name", name);

        String prefix = namespaces.getCreatePrefix(type.getNamespaceURI());
        String prefixedName = prefix + ":" + type.getLocalPart();

        childElem.setAttribute("type", prefixedName);

        // JAX-RPC 1.1 says that byte[] should always be a Base64Binary
        // This (rather strange) hack will ensure that we don't map it
        // in to an maxoccurs=unbounded array.
        if (javaType.isArray() && !javaType.equals(byte[].class)) {
            childElem.setAttribute("maxOccurs", "unbounded");
        }
    }

    sequence.appendChild(childElem);
}

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

/**
 * write out the namespace declaration and return the type QName for the
 * given <code>Class</code>//w  w  w.j  a  va 2  s  .co m
 *
 * @param type  input Class
 * @param qName qname of the Class
 * @return QName for the schema type representing the class
 */
private QName writeTypeNamespace(Class type, QName qName) {

    if (qName == null) {
        qName = getTypeQName(type);
    }

    writeTypeNamespace(qName.getNamespaceURI());

    return qName;
}

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

/**
 * Return the QName of the specified javaType
 *
 * @param javaType input javaType Class/*from   ww w.j  av  a 2 s  .c  o  m*/
 * @return QName
 */
public QName getTypeQName(Class javaType) {
    QName qName = null;

    // Use the typeMapping information to lookup the qName.
    qName = tm.getTypeQName(javaType);

    // If the javaType is an array and the qName is
    // SOAP_ARRAY, construct the QName using the
    // QName of the component type
    if (isArray(javaType) && Constants.equals(Constants.SOAP_ARRAY, qName)) {
        Class componentType = getComponentType(javaType);

        // For WS-I BP compliance, we can't use "ArrayOf" as a type prefix 
        // instead use "MyArrayOf" (gag) 
        String arrayTypePrefix = "ArrayOf";

        boolean isWSICompliant = JavaUtils
                .isTrue(AxisProperties.getProperty(Constants.WSIBP11_COMPAT_PROPERTY));
        if (isWSICompliant) {
            arrayTypePrefix = "MyArrayOf";
        }

        // If component namespace uri == targetNamespace
        // Construct ArrayOf<componentLocalPart>
        // Else
        // Construct ArrayOf_<componentPrefix>_<componentLocalPart>
        QName cqName = getTypeQName(componentType);

        if (targetNamespace.equals(cqName.getNamespaceURI())) {
            qName = new QName(targetNamespace, arrayTypePrefix + cqName.getLocalPart());
        } else {
            String pre = namespaces.getCreatePrefix(cqName.getNamespaceURI());

            qName = new QName(targetNamespace, arrayTypePrefix + "_" + pre + "_" + cqName.getLocalPart());
        }

        return qName;
    }

    // If a qName was not found construct one using the
    // class name information.
    if (qName == null) {
        String pkg = getPackageNameFromFullName(javaType.getName());
        String lcl = getLocalNameFromFullName(javaType.getName());
        String ns = namespaces.getCreate(pkg);

        namespaces.getCreatePrefix(ns);

        String localPart = lcl.replace('$', '_');

        qName = new QName(ns, localPart);
    }

    return qName;
}

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

/**
 * Return a string suitable for representing a given QName in the context
 * of this WSDL document.  If the namespace of the QName is not yet
 * registered, we will register it up in the Definitions.
 *
 * @param qname a QName (typically a type)
 * @return a String containing a standard "ns:localPart" rep of the QName
 */// w  w w .  j av  a 2 s  . c om
public String getQNameString(QName qname) {

    String prefix = namespaces.getCreatePrefix(qname.getNamespaceURI());

    return prefix + ":" + qname.getLocalPart();
}

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

/**
 * Method writeSchemaTypeDecl/* ww  w.j  av  a 2  s. com*/
 *
 * @param qname
 * @param element
 * @throws AxisFault
 */
public void writeSchemaTypeDecl(QName qname, Element element) throws AxisFault {
    writeSchemaElement(qname.getNamespaceURI(), element);
}