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.ode.store.ProcessStoreImpl.java

private QName toPid(QName processType, long version) {
    return new QName(processType.getNamespaceURI(), processType.getLocalPart() + "-" + version);
}

From source file:org.apache.ode.utils.DOMUtils.java

/**
 * Deep clone, but don't fry, the given node in the context of the given document.
 * For all intents and purposes, the clone is the exact same copy of the node,
 * except that it might have a different owner document.
 *
 * This method is fool-proof, unlike the <code>adoptNode</code> or <code>adoptNode</code> methods,
 * in that it doesn't assume that the given node has a parent or a owner document.
 *
 * @param document//from w ww  .  j av a2 s.  c o m
 * @param sourceNode
 * @return a clone of node
 */
public static Node cloneNode(Document document, Node sourceNode) {
    Node clonedNode = null;

    // what is my name?
    QName sourceQName = getNodeQName(sourceNode);
    String nodeName = sourceQName.getLocalPart();
    String namespaceURI = sourceQName.getNamespaceURI();

    // if the node is unqualified, don't assume that it inherits the WS-BPEL target namespace
    if (Namespaces.WSBPEL2_0_FINAL_EXEC.equals(namespaceURI)) {
        namespaceURI = null;
    }

    switch (sourceNode.getNodeType()) {
    case Node.ATTRIBUTE_NODE:
        if (namespaceURI == null) {
            clonedNode = document.createAttribute(nodeName);
        } else {
            String prefix = ((Attr) sourceNode).lookupPrefix(namespaceURI);
            // the prefix for the XML namespace can't be looked up, hence this...
            if (prefix == null && namespaceURI.equals(NS_URI_XMLNS)) {
                prefix = "xmlns";
            }
            // if a prefix exists, qualify the name with it
            if (prefix != null && !"".equals(prefix)) {
                nodeName = prefix + ":" + nodeName;
            }
            // create the appropriate type of attribute
            if (prefix != null) {
                clonedNode = document.createAttributeNS(namespaceURI, nodeName);
            } else {
                clonedNode = document.createAttribute(nodeName);
            }
        }
        break;
    case Node.CDATA_SECTION_NODE:
        clonedNode = document.createCDATASection(((CDATASection) sourceNode).getData());
        break;
    case Node.COMMENT_NODE:
        clonedNode = document.createComment(((Comment) sourceNode).getData());
        break;
    case Node.DOCUMENT_FRAGMENT_NODE:
        clonedNode = document.createDocumentFragment();
        break;
    case Node.DOCUMENT_NODE:
        clonedNode = document;
        break;
    case Node.ELEMENT_NODE:
        // create the appropriate type of element
        if (namespaceURI == null) {
            clonedNode = document.createElement(nodeName);
        } else {
            String prefix = namespaceURI.equals(Namespaces.XMLNS_URI) ? "xmlns"
                    : ((Element) sourceNode).lookupPrefix(namespaceURI);
            if (prefix != null && !"".equals(prefix)) {
                nodeName = prefix + ":" + nodeName;
                clonedNode = document.createElementNS(namespaceURI, nodeName);
            } else {
                clonedNode = document.createElement(nodeName);
            }
        }
        // attributes are not treated as child nodes, so copy them explicitly
        NamedNodeMap attributes = ((Element) sourceNode).getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Attr attributeClone = (Attr) cloneNode(document, attributes.item(i));
            if (attributeClone.getNamespaceURI() == null) {
                ((Element) clonedNode).setAttributeNode(attributeClone);
            } else {
                ((Element) clonedNode).setAttributeNodeNS(attributeClone);
            }
        }
        break;
    case Node.ENTITY_NODE:
        // TODO
        break;
    case Node.ENTITY_REFERENCE_NODE:
        clonedNode = document.createEntityReference(nodeName);
        // TODO
        break;
    case Node.NOTATION_NODE:
        // TODO
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        clonedNode = document.createProcessingInstruction(((ProcessingInstruction) sourceNode).getData(),
                nodeName);
        break;
    case Node.TEXT_NODE:
        clonedNode = document.createTextNode(((Text) sourceNode).getData());
        break;
    default:
        break;
    }

    // clone children of element and attribute nodes
    NodeList sourceChildren = sourceNode.getChildNodes();
    if (sourceChildren != null) {
        for (int i = 0; i < sourceChildren.getLength(); i++) {
            Node sourceChild = sourceChildren.item(i);
            Node clonedChild = cloneNode(document, sourceChild);
            clonedNode.appendChild(clonedChild);
            // if the child has a textual value, parse it for any embedded prefixes
            if (clonedChild.getNodeType() == Node.TEXT_NODE
                    || clonedChild.getNodeType() == Node.CDATA_SECTION_NODE) {
                parseEmbeddedPrefixes(sourceNode, clonedNode, clonedChild);
            }
        }
    }
    return clonedNode;
}

From source file:org.apache.ode.utils.xsd.SchemaModelImpl.java

/**
 * @see org.apache.ode.utils.xsd.SchemaModel#isCompatible(javax.xml.namespace.QName,
 *      javax.xml.namespace.QName)// w w w .  j  a  v  a 2  s .co m
 */
public boolean isCompatible(QName type1, QName type2) {
    XSTypeDefinition typeDef1;
    XSTypeDefinition typeDef2;

    if (knowsElementType(type1)) {
        typeDef1 = _model.getElementDeclaration(type1.getLocalPart(), type1.getNamespaceURI())
                .getTypeDefinition();
    } else if (knowsSchemaType(type1)) {
        typeDef1 = _model.getTypeDefinition(type1.getLocalPart(), type1.getNamespaceURI());
    } else {
        throw new IllegalArgumentException("unknown schema type: " + type1);
    }

    if (knowsElementType(type2)) {
        typeDef2 = _model.getElementDeclaration(type2.getLocalPart(), type2.getNamespaceURI())
                .getTypeDefinition();
    } else if (knowsSchemaType(type2)) {
        typeDef2 = _model.getTypeDefinition(type2.getLocalPart(), type2.getNamespaceURI());
    } else {
        throw new IllegalArgumentException("unknown schema type: " + type2);
    }

    return typeDef1.derivedFromType(typeDef2, (short) 0) || typeDef2.derivedFromType(typeDef1, (short) 0);
}

From source file:org.apache.ode.utils.xsd.SchemaModelImpl.java

/**
 * @see org.apache.ode.utils.xsd.SchemaModel#isSimpleType(javax.xml.namespace.QName)
 *//*from   w w w. ja v  a  2s . co  m*/
public boolean isSimpleType(QName type) {
    if (type == null)
        throw new NullPointerException("Null type argument!");

    XSTypeDefinition typeDef = _model.getTypeDefinition(type.getLocalPart(), type.getNamespaceURI());

    return (typeDef != null) && (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE);
}

From source file:org.apache.ode.utils.xsd.SchemaModelImpl.java

/**
 * @see org.apache.ode.utils.xsd.SchemaModel#knowsElementType(javax.xml.namespace.QName)
 *///from   w  w  w. ja v  a  2s. com
public boolean knowsElementType(QName elementType) {
    if (elementType == null)
        throw new NullPointerException("Null type argument!");

    return _model.getElementDeclaration(elementType.getLocalPart(), elementType.getNamespaceURI()) != null;
}

From source file:org.apache.ode.utils.xsd.SchemaModelImpl.java

/**
 * @see org.apache.ode.utils.xsd.SchemaModel#knowsSchemaType(javax.xml.namespace.QName)
 *//*from www .  j  a  v  a2 s  . co m*/
public boolean knowsSchemaType(QName schemaType) {
    if (schemaType == null)
        throw new NullPointerException("Null type argument!");

    return _model.getTypeDefinition(schemaType.getLocalPart(), schemaType.getNamespaceURI()) != null;
}

From source file:org.apache.openejb.server.axis.assembler.CommonsSchemaInfoBuilder.java

private void addType(QName typeQName, XmlSchemaType type) {
    // skip built in xml schema types
    if (XML_SCHEMA_NS.equals(typeQName.getNamespaceURI())) {
        return;/*from   w w  w .j av a  2s. com*/
    }

    XmlTypeInfo typeInfo = createXmlTypeInfo(typeQName, type);
    xmlTypes.put(typeQName, typeInfo);

    if (type instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;

        // process elements nested inside of this element
        List<XmlSchemaElement> elements = getNestedElements(complexType);
        for (XmlSchemaElement element : elements) {
            addNestedElement(element, typeInfo);
        }
    }
}

From source file:org.apache.openejb.server.axis.assembler.HeavyweightTypeInfoBuilder.java

public List<JaxRpcTypeInfo> buildTypeInfo() throws OpenEJBException {
    List<JaxRpcTypeInfo> typeInfos = new ArrayList<JaxRpcTypeInfo>();

    Set<QName> mappedTypeQNames = new HashSet<QName>();

    ///*w w  w  .  ja va 2  s. c o  m*/
    // Map types with explicity Java to XML mappings
    //
    for (JavaXmlTypeMapping javaXmlTypeMapping : mapping.getJavaXmlTypeMapping()) {
        // get the QName for this mapping
        QName qname;
        if (javaXmlTypeMapping.getRootTypeQname() != null) {
            qname = javaXmlTypeMapping.getRootTypeQname();

            // Skip the wrapper elements.
            if (wrapperElementQNames.contains(qname)) {
                continue;
            }
        } else if (javaXmlTypeMapping.getAnonymousTypeQname() != null) {
            String anonTypeQNameString = javaXmlTypeMapping.getAnonymousTypeQname();

            // this appears to be ignored...
            int pos = anonTypeQNameString.lastIndexOf(":");
            if (pos == -1) {
                throw new OpenEJBException("anon QName is invalid, no final ':' " + anonTypeQNameString);
            }
            String namespace = anonTypeQNameString.substring(0, pos);
            String localPart = anonTypeQNameString.substring(pos + 1);
            qname = new QName(namespace, localPart);

            // Skip the wrapper elements.
            // todo why is this +2
            if (wrapperElementQNames.contains(new QName(namespace, anonTypeQNameString.substring(pos + 2)))) {
                continue;
            }
        } else {
            throw new OpenEJBException("either root type qname or anonymous type qname must be set");
        }

        // get the xml type qname of this mapping
        QName xmlTypeQName;
        if ("element".equals(javaXmlTypeMapping.getQNameScope())) {
            XmlElementInfo elementInfo = schemaInfo.elements.get(qname);
            if (elementInfo == null) {
                log.warn("Element [" + qname + "] not been found in schema, known elements: "
                        + schemaInfo.elements.keySet());
            }
            xmlTypeQName = elementInfo.xmlType;
        } else {
            xmlTypeQName = qname;
        }

        // finally, get the xml type info for the mapping
        XmlTypeInfo xmlTypeInfo = schemaInfo.types.get(xmlTypeQName);
        if (xmlTypeInfo == null) {
            // if this is a built in type then assume this is a redundant mapping
            if (WebserviceNameSpaces.contains(xmlTypeInfo.qname.getNamespaceURI())) {
                continue;
            }
            log.warn(
                    "Schema type QName [" + qname + "] not been found in schema: " + schemaInfo.types.keySet());
            continue;
        }

        // mark this type as mapped
        mappedTypeQNames.add(xmlTypeInfo.qname);

        // load the java class
        Class clazz;
        try {
            clazz = Class.forName(javaXmlTypeMapping.getJavaType(), false, classLoader);
        } catch (ClassNotFoundException e) {
            throw new OpenEJBException("Could not load java type " + javaXmlTypeMapping.getJavaType(), e);
        }

        // create the jax-rpc type mapping
        JaxRpcTypeInfo typeInfo = createTypeInfo(qname, xmlTypeInfo, clazz);
        mapFields(clazz, xmlTypeInfo, javaXmlTypeMapping, typeInfo);

        typeInfos.add(typeInfo);
    }

    //
    // Map types used in operations
    //
    for (JaxRpcOperationInfo operationInfo : operations) {
        List<JaxRpcParameterInfo> parameters = new ArrayList<JaxRpcParameterInfo>(operationInfo.parameters);

        // add the return type to the parameters so it is processed below
        if (operationInfo.returnXmlType != null) {
            JaxRpcParameterInfo returnParameter = new JaxRpcParameterInfo();
            returnParameter.xmlType = operationInfo.returnXmlType;
            returnParameter.javaType = operationInfo.returnJavaType;
            parameters.add(returnParameter);
        }

        // add type mappings for each parameter (including the return type)
        for (JaxRpcParameterInfo parameterInfo : parameters) {
            QName xmlType = parameterInfo.xmlType;

            // skip types that have already been mapped or are built in types
            if (xmlType == null || mappedTypeQNames.contains(xmlType)
                    || xmlType.getNamespaceURI().equals(XML_SCHEMA_NS)
                    || xmlType.getNamespaceURI().equals(SOAP_ENCODING_NS)) {
                continue;
            }

            // get the xml type info
            XmlTypeInfo xmlTypeInfo = schemaInfo.types.get(xmlType);
            if (xmlTypeInfo == null) {
                log.warn("Type QName [" + xmlType + "] defined by operation [" + operationInfo
                        + "] has not been found in schema: " + schemaInfo.types.keySet());
                continue;
            }
            mappedTypeQNames.add(xmlTypeInfo.qname);

            // load the java class
            Class<?> clazz;
            try {
                clazz = classLoader.loadClass(parameterInfo.javaType);
            } catch (ClassNotFoundException e) {
                throw new OpenEJBException("Could not load paramter");
            }

            // we only process simpleTypes and arrays (not normal complex types)
            if (xmlTypeInfo.simpleBaseType == null && !clazz.isArray()) {
                if (!mappedTypeQNames.contains(xmlTypeInfo.qname)) {
                    // TODO: this lookup is not enough: the jaxrpc mapping file may define an anonymous mapping
                    log.warn("Operation " + operationInfo.name + "] uses XML type [" + xmlTypeInfo
                            + "], whose mapping is not declared by the jaxrpc mapping file.\n Continuing deployment; "
                            + "yet, the deployment is not-portable.");
                }
                continue;
            }

            // create the jax-rpc type mapping
            JaxRpcTypeInfo typeInfo = createTypeInfo(parameterInfo.qname, xmlTypeInfo, clazz);
            typeInfos.add(typeInfo);
        }
    }

    return typeInfos;
}

From source file:org.apache.pluto.driver.services.container.EventProviderImpl.java

private List<String> getAllPortletsRegisteredForEvent(Event event, DriverConfiguration driverConfig,
        ServletContext containerServletContext) {
    Set<String> resultSet = new HashSet<String>();
    List<String> resultList = new ArrayList<String>();
    QName eventName = event.getQName();
    Collection<PortletWindowConfig> portlets = getAllPortlets(driverConfig);
    if (portletRegistry == null) {
        portletRegistry = ((PortletContainer) containerServletContext
                .getAttribute(AttributeKeys.PORTLET_CONTAINER)).getOptionalContainerServices()
                        .getPortletRegistryService();
    }//from   w w  w.  j  a v a  2 s.  co  m

    for (PortletWindowConfig portlet : portlets) {
        String contextPath = portlet.getContextPath();
        String applicationName = contextPath;
        if (applicationName.length() > 0) {
            applicationName = applicationName.substring(1);
        }
        PortletApplicationDefinition portletAppDD = null;
        try {
            portletAppDD = portletRegistry.getPortletApplication(applicationName);
            List<? extends PortletDefinition> portletDDs = portletAppDD.getPortlets();
            List<QName> aliases = getAllAliases(eventName, portletAppDD);
            for (PortletDefinition portletDD : portletDDs) {
                List<? extends EventDefinitionReference> processingEvents = portletDD
                        .getSupportedProcessingEvents();
                if (isEventSupported(processingEvents, eventName, portletAppDD.getDefaultNamespace())) {
                    if (portletDD.getPortletName().equals(portlet.getPortletName())) {
                        resultSet.add(portlet.getId());
                    }
                } else {

                    if (processingEvents != null) {
                        for (EventDefinitionReference ref : processingEvents) {
                            QName name = ref.getQualifiedName(portletAppDD.getDefaultNamespace());
                            if (name == null) {
                                continue;
                            }
                            // add also grouped portlets, that ends with "."
                            if (name.toString().endsWith(".")
                                    && eventName.toString().startsWith(name.toString())
                                    && portletDD.getPortletName().equals(portlet.getPortletName())) {
                                resultSet.add(portlet.getId());
                            }
                            // also look for alias names:
                            if (aliases != null) {
                                for (QName alias : aliases) {
                                    if (alias.toString().equals(name.toString())
                                            && portletDD.getPortletName().equals(portlet.getPortletName())) {
                                        resultSet.add(portlet.getId());
                                    }
                                }
                            }
                            // also look for default namespaced events
                            if (name.getNamespaceURI() == null || name.getNamespaceURI().equals("")) {
                                String defaultNamespace = portletAppDD.getDefaultNamespace();
                                QName qname = new QName(defaultNamespace, name.getLocalPart());
                                if (eventName.toString().equals(qname.toString())
                                        && portletDD.getPortletName().equals(portlet.getPortletName())) {
                                    resultSet.add(portlet.getId());
                                }
                            }
                        }
                    }
                }
            }
        } catch (PortletContainerException e) {
            LOG.warn(e);
        }
    }

    // make list
    for (String name : resultSet) {
        resultList.add(name);
    }
    return resultList;
}

From source file:org.apache.rahas.impl.SAML2TokenIssuer.java

/**
 * This method is used to build the assertion elements
 * @param objectQName/* www . j av  a 2  s  .  c  o  m*/
 * @return
 * @throws Exception
 */
protected static XMLObject buildXMLObject(QName objectQName) throws Exception {
    XMLObjectBuilder builder = org.opensaml.xml.Configuration.getBuilderFactory().getBuilder(objectQName);
    if (builder == null) {
        throw new TrustException("Unable to retrieve builder for object QName " + objectQName);
    }
    return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(),
            objectQName.getPrefix());
}