Java Code Examples for javax.xml.namespace.QName#getNamespaceURI()

The following examples show how to use javax.xml.namespace.QName#getNamespaceURI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WSEndpointReference.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param writer the writer should be at the start of element.
 * @param service Namespace URI of servcie is used as targetNamespace of wsdl if wsdlTargetNamespace is not null
 * @param wsdlAddress  wsdl location
 * @param wsdlTargetNamespace  targetnamespace of wsdl to be put in wsdliLocation
 *
 */
private static void writeWsdliLocation(StreamWriterBufferCreator writer, QName service,String wsdlAddress,String wsdlTargetNamespace) throws XMLStreamException {
    String wsdliLocation = "";
    if(wsdlTargetNamespace != null) {
       wsdliLocation = wsdlTargetNamespace + " ";
    } else if (service != null) {
        wsdliLocation = service.getNamespaceURI() + " ";
    } else {
        throw new WebServiceException("WSDL target Namespace cannot be resolved");
    }
    wsdliLocation += wsdlAddress;
    writer.writeNamespace(W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_PREFIX,
        W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_NAMESPACE);
    writer.writeAttribute(W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_PREFIX,
            W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_NAMESPACE,
            W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_LOCALNAME,
            wsdliLocation);

}
 
Example 2
Source File: WSEndpointReference.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param writer the writer should be at the start of element.
 * @param service Namespace URI of servcie is used as targetNamespace of wsdl if wsdlTargetNamespace is not null
 * @param wsdlAddress  wsdl location
 * @param wsdlTargetNamespace  targetnamespace of wsdl to be put in wsdliLocation
 *
 */
private static void writeWsdliLocation(StreamWriterBufferCreator writer, QName service,String wsdlAddress,String wsdlTargetNamespace) throws XMLStreamException {
    String wsdliLocation = "";
    if(wsdlTargetNamespace != null) {
       wsdliLocation = wsdlTargetNamespace + " ";
    } else if (service != null) {
        wsdliLocation = service.getNamespaceURI() + " ";
    } else {
        throw new WebServiceException("WSDL target Namespace cannot be resolved");
    }
    wsdliLocation += wsdlAddress;
    writer.writeNamespace(W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_PREFIX,
        W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_NAMESPACE);
    writer.writeAttribute(W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_PREFIX,
            W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_NAMESPACE,
            W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_LOCALNAME,
            wsdliLocation);

}
 
Example 3
Source File: WSEndpointReference.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param writer the writer should be at the start of element.
 * @param service Namespace URI of servcie is used as targetNamespace of wsdl if wsdlTargetNamespace is not null
 * @param wsdlAddress  wsdl location
 * @param wsdlTargetNamespace  targetnamespace of wsdl to be put in wsdliLocation
 *
 */
private static void writeWsdliLocation(StreamWriterBufferCreator writer, QName service,String wsdlAddress,String wsdlTargetNamespace) throws XMLStreamException {
    String wsdliLocation = "";
    if(wsdlTargetNamespace != null) {
       wsdliLocation = wsdlTargetNamespace + " ";
    } else if (service != null) {
        wsdliLocation = service.getNamespaceURI() + " ";
    } else {
        throw new WebServiceException("WSDL target Namespace cannot be resolved");
    }
    wsdliLocation += wsdlAddress;
    writer.writeNamespace(W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_PREFIX,
        W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_NAMESPACE);
    writer.writeAttribute(W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_PREFIX,
            W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_NAMESPACE,
            W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_LOCALNAME,
            wsdliLocation);

}
 
Example 4
Source File: AbstractFaultSoapPayloadConverter.java    From syndesis with Apache License 2.0 6 votes vote down vote up
protected static String getFaultCodePrefix(XMLStreamWriter writer, QName faultCode) throws XMLStreamException {
    String codeNs = faultCode.getNamespaceURI();
    String prefix = null;
    if (codeNs.length() > 0) {
        prefix = faultCode.getPrefix();
        if (!StringUtils.isEmpty(prefix)) {
            String boundNS = writer.getNamespaceContext().getNamespaceURI(prefix);
            if (StringUtils.isEmpty(boundNS)) {
                writer.writeNamespace(prefix, codeNs);
            } else if (!codeNs.equals(boundNS)) {
                prefix = null;
            }
        }
        if (StringUtils.isEmpty(prefix)) {
            prefix = StaxUtils.getUniquePrefix(writer, codeNs, true);
        }
    }
    return prefix;
}
 
Example 5
Source File: XmlSchemaGenerator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void addDependencyTo(@Nullable QName qname) {
    // even though the Element interface says getElementName() returns non-null,
    // ClassInfo always implements Element (even if an instance of ClassInfo might not be an Element).
    // so this check is still necessary
    if (qname==null) {
        return;
    }

    String nsUri = qname.getNamespaceURI();

    if (nsUri.equals(XML_SCHEMA)) {
        // no need to explicitly refer to XSD namespace
        return;
    }

    if (nsUri.equals(uri)) {
        selfReference = true;
        return;
    }

    // found a type in a foreign namespace, so make sure we generate an import for it
    depends.add(getNamespace(nsUri));
}
 
Example 6
Source File: PropertyInfoImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private QName calcXmlName(String uri,String local) {
    // compute the default
    TODO.checkSpec();
    if(local.length()==0 || local.equals("##default"))
        local = seed.getName();
    if(uri.equals("##default")) {
        XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
        // JAX-RPC doesn't want the default namespace URI swapping to take effect to
        // local "unqualified" elements. UGLY.
        if(xs!=null) {
            switch(xs.elementFormDefault()) {
            case QUALIFIED:
                QName typeName = parent.getTypeName();
                if(typeName!=null)
                    uri = typeName.getNamespaceURI();
                else
                    uri = xs.namespace();
                if(uri.length()==0)
                    uri = parent.builder.defaultNsUri;
                break;
            case UNQUALIFIED:
            case UNSET:
                uri = "";
            }
        } else {
            uri = "";
        }
    }
    return new QName(uri.intern(),local.intern());
}
 
Example 7
Source File: PropertyInfoImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private QName calcXmlName(String uri,String local) {
    // compute the default
    TODO.checkSpec();
    if(local.length()==0 || local.equals("##default"))
        local = seed.getName();
    if(uri.equals("##default")) {
        XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
        // JAX-RPC doesn't want the default namespace URI swapping to take effect to
        // local "unqualified" elements. UGLY.
        if(xs!=null) {
            switch(xs.elementFormDefault()) {
            case QUALIFIED:
                QName typeName = parent.getTypeName();
                if(typeName!=null)
                    uri = typeName.getNamespaceURI();
                else
                    uri = xs.namespace();
                if(uri.length()==0)
                    uri = parent.builder.defaultNsUri;
                break;
            case UNQUALIFIED:
            case UNSET:
                uri = "";
            }
        } else {
            uri = "";
        }
    }
    return new QName(uri.intern(),local.intern());
}
 
Example 8
Source File: PropertyInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private QName calcXmlName(String uri,String local) {
    // compute the default
    TODO.checkSpec();
    if(local.length()==0 || local.equals("##default"))
        local = seed.getName();
    if(uri.equals("##default")) {
        XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
        // JAX-RPC doesn't want the default namespace URI swapping to take effect to
        // local "unqualified" elements. UGLY.
        if(xs!=null) {
            switch(xs.elementFormDefault()) {
            case QUALIFIED:
                QName typeName = parent.getTypeName();
                if(typeName!=null)
                    uri = typeName.getNamespaceURI();
                else
                    uri = xs.namespace();
                if(uri.length()==0)
                    uri = parent.builder.defaultNsUri;
                break;
            case UNQUALIFIED:
            case UNSET:
                uri = "";
            }
        } else {
            uri = "";
        }
    }
    return new QName(uri.intern(),local.intern());
}
 
Example 9
Source File: Header1_2Impl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected SOAPHeaderElement createHeaderElement(QName name)
    throws SOAPException {
    String uri = name.getNamespaceURI();
    if (uri == null || uri.equals("")) {
        log.severe("SAAJ0413.ver1_2.header.elems.must.be.ns.qualified");
        throw new SOAPExceptionImpl("SOAP 1.2 header elements must be namespace qualified");
    }
    return new HeaderElement1_2Impl(
        ((SOAPDocument) getOwnerDocument()).getDocument(),
        name);
}
 
Example 10
Source File: Fault1_2Impl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void appendFaultSubcode(QName subcode) throws SOAPException {
    if (subcode == null) {
        return;
    }
    if (subcode.getNamespaceURI() == null ||
        "".equals(subcode.getNamespaceURI())) {

        log.severe("SAAJ0432.ver1_2.subcode.not.ns.qualified");
        throw new SOAPExceptionImpl("A Subcode must be namespace-qualified");
    }
    if (innermostSubCodeElement == null) {
        if (faultCodeElement == null)
            findFaultCodeElement();
        innermostSubCodeElement = faultCodeElement;
    }
    String prefix = null;
    if (subcode.getPrefix() == null || "".equals(subcode.getPrefix())) {
        prefix =
            ((ElementImpl) innermostSubCodeElement).getNamespacePrefix(
                subcode.getNamespaceURI());
    } else
        prefix = subcode.getPrefix();
    if (prefix == null || "".equals(prefix)) {
        prefix = "ns1";
    }
    innermostSubCodeElement =
        innermostSubCodeElement.addChildElement(subcodeName);
    SOAPElement subcodeValueElement =
        innermostSubCodeElement.addChildElement(valueName);
    ((ElementImpl) subcodeValueElement).ensureNamespaceIsDeclared(
        prefix,
        subcode.getNamespaceURI());
    subcodeValueElement.addTextNode(prefix + ":" + subcode.getLocalPart());
}
 
Example 11
Source File: PackageOutlineImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * pull the uri out of the specified QName and keep track of it in the
 * specified hash map
 *
 * @param qname
 */
private void countURI(HashMap<String, Integer> map, QName qname) {
    if (qname == null) return;

    String uri = qname.getNamespaceURI();

    if (map.containsKey(uri)) {
        map.put(uri, map.get(uri) + 1);
    } else {
        map.put(uri, 1);
    }
}
 
Example 12
Source File: PropertyInfoImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private QName calcXmlName(String uri,String local) {
    // compute the default
    TODO.checkSpec();
    if(local.length()==0 || local.equals("##default"))
        local = seed.getName();
    if(uri.equals("##default")) {
        XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
        // JAX-RPC doesn't want the default namespace URI swapping to take effect to
        // local "unqualified" elements. UGLY.
        if(xs!=null) {
            switch(xs.elementFormDefault()) {
            case QUALIFIED:
                QName typeName = parent.getTypeName();
                if(typeName!=null)
                    uri = typeName.getNamespaceURI();
                else
                    uri = xs.namespace();
                if(uri.length()==0)
                    uri = parent.builder.defaultNsUri;
                break;
            case UNQUALIFIED:
            case UNSET:
                uri = "";
            }
        } else {
            uri = "";
        }
    }
    return new QName(uri.intern(),local.intern());
}
 
Example 13
Source File: JAXBHeader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public JAXBHeader(XMLBridge bridge, Object jaxbObject) {
    this.jaxbObject = jaxbObject;
    this.bridge = bridge;

    QName tagName = bridge.getTypeInfo().tagName;
    this.nsUri = tagName.getNamespaceURI();
    this.localName = tagName.getLocalPart();
}
 
Example 14
Source File: ParserVocabulary.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void addToNameTable(QName n, QualifiedNameArray a,
        boolean isAttribute,
        StringIntMap prefixMap, StringIntMap namespaceNameMap,
        StringIntMap localNameMap) {
    int namespaceURIIndex = -1;
    int prefixIndex = -1;
    if (n.getNamespaceURI().length() > 0) {
        namespaceURIIndex = namespaceNameMap.obtainIndex(n.getNamespaceURI());
        if (namespaceURIIndex == KeyIntMap.NOT_PRESENT) {
            namespaceURIIndex = namespaceName.getSize();
            namespaceName.add(n.getNamespaceURI());
        }

        if (n.getPrefix().length() > 0) {
            prefixIndex = prefixMap.obtainIndex(n.getPrefix());
            if (prefixIndex == KeyIntMap.NOT_PRESENT) {
                prefixIndex = prefix.getSize();
                prefix.add(n.getPrefix());
            }
        }
    }

    int localNameIndex = localNameMap.obtainIndex(n.getLocalPart());
    if (localNameIndex == KeyIntMap.NOT_PRESENT) {
        localNameIndex = localName.getSize();
        localName.add(n.getLocalPart());
    }

    QualifiedName name = new QualifiedName(n.getPrefix(), n.getNamespaceURI(), n.getLocalPart(),
            a.getSize(),
            prefixIndex, namespaceURIIndex, localNameIndex);
    if (isAttribute) {
        name.createAttributeValues(DuplicateAttributeVerifier.MAP_SIZE);
    }
    a.add(name);
}
 
Example 15
Source File: RuntimeModeler.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void processClass(Class clazz) {
        classUsesWebMethod = new HashSet<Class>();
        determineWebMethodUse(clazz);
        WebService webService = getAnnotation(clazz, WebService.class);
        QName portTypeName = getPortTypeName(clazz, targetNamespace, metadataReader);
//        String portTypeLocalName  = clazz.getSimpleName();
//        if (webService.name().length() >0)
//            portTypeLocalName = webService.name();
//
//        targetNamespace = webService.targetNamespace();
        packageName = "";
        if (clazz.getPackage() != null)
            packageName = clazz.getPackage().getName();
//        if (targetNamespace.length() == 0) {
//            targetNamespace = getNamespace(packageName);
//        }
//        model.setTargetNamespace(targetNamespace);
//        QName portTypeName = new QName(targetNamespace, portTypeLocalName);
        targetNamespace = portTypeName.getNamespaceURI();
        model.setPortTypeName(portTypeName);
        model.setTargetNamespace(targetNamespace);
        model.defaultSchemaNamespaceSuffix = config.getMappingInfo().getDefaultSchemaNamespaceSuffix();
        model.setWSDLLocation(webService.wsdlLocation());

        SOAPBinding soapBinding = getAnnotation(clazz, SOAPBinding.class);
        if (soapBinding != null) {
            if (soapBinding.style() == SOAPBinding.Style.RPC && soapBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) {
                throw new RuntimeModelerException("runtime.modeler.invalid.soapbinding.parameterstyle",
                        soapBinding, clazz);

            }
            isWrapped = soapBinding.parameterStyle()== WRAPPED;
        }
        defaultBinding = createBinding(soapBinding);
        /*
         * if clazz != portClass then there is an SEI.  If there is an
         * SEI, then all methods should be processed.  However, if there is
         * no SEI, and the implementation class uses at least one
         * WebMethod annotation, then only methods with this annotation
         * will be processed.
         */
/*        if (clazz == portClass) {
            WebMethod webMethod;
            for (Method method : clazz.getMethods()) {
                webMethod = getPrivMethodAnnotation(method, WebMethod.class);
                if (webMethod != null &&
                    !webMethod.exclude()) {
                    usesWebMethod = true;
                    break;
                }
            }
        }*/

        for (Method method : clazz.getMethods()) {
            if (!clazz.isInterface()) {     // if clazz is SEI, then all methods are web methods
                if (method.getDeclaringClass() == Object.class) continue;
                if (!getBooleanSystemProperty("com.sun.xml.internal.ws.legacyWebMethod")) {  // legacy webMethod computation behaviour to be used
                    if (!isWebMethodBySpec(method, clazz))
                        continue;
                } else {
                    if (!isWebMethod(method))
                        continue;
                }
            }
            // TODO: binding can be null. We need to figure out how to post-process
            // RuntimeModel to link to WSDLModel
            processMethod(method);
        }
        //Add additional jaxb classes referenced by {@link XmlSeeAlso}
        XmlSeeAlso xmlSeeAlso = getAnnotation(clazz, XmlSeeAlso.class);
        if(xmlSeeAlso != null)
            model.addAdditionalClasses(xmlSeeAlso.value());
    }
 
Example 16
Source File: EPRHeader.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
EPRHeader(QName tagName, WSEndpointReference epr) {
    this.nsUri = tagName.getNamespaceURI();
    this.localName = tagName.getLocalPart();
    this.epr = epr;
}
 
Example 17
Source File: RelatesToHeader.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public RelatesToHeader(QName name, String messageId, String type) {
    super(name, messageId);
    this.type = type;
    this.typeAttributeName = new QName(name.getNamespaceURI(), "type");
}
 
Example 18
Source File: EPRHeader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
EPRHeader(QName tagName, WSEndpointReference epr) {
    this.nsUri = tagName.getNamespaceURI();
    this.localName = tagName.getLocalPart();
    this.epr = epr;
}
 
Example 19
Source File: NameImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static Name convertToName(QName qname) {
    return new NameImpl(qname.getLocalPart(),
                        qname.getPrefix(),
                        qname.getNamespaceURI());
}
 
Example 20
Source File: SpnegoContextToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getSpnegoContextToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();
    String prefix;

    String writerPrefix = writer.getPrefix(namespaceURI);

    if (writerPrefix == null) {
        prefix = name.getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    } else {
        prefix = writerPrefix;
    }

    // <sp:SpnegoContextToken>
    writer.writeStartElement(prefix, localname, namespaceURI);

    if (writerPrefix == null) {
        // xmlns:sp=".."
        writer.writeNamespace(prefix, namespaceURI);
    }

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    if (issuerEpr != null) {
        // <sp:Issuer>
        writer.writeStartElement(prefix, SPConstants.ISSUER, namespaceURI);

        StaxUtils.copy(issuerEpr, writer);

        writer.writeEndElement();
    }

    if (isDerivedKeys()) {

        String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI();

        String wspPrefix;

        String wspWriterPrefix = writer.getPrefix(wspNamespaceURI);

        if (wspWriterPrefix == null) {
            wspPrefix = SPConstants.POLICY.getPrefix();
            writer.setPrefix(wspPrefix, wspNamespaceURI);

        } else {
            wspPrefix = wspWriterPrefix;
        }

        // <wsp:Policy>
        writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(), wspNamespaceURI);

        if (wspWriterPrefix == null) {
            // xmlns:wsp=".."
            writer.writeNamespace(wspPrefix, wspNamespaceURI);
        }

        if (isDerivedKeys()) {
            // <sp:RequireDerivedKeys />
            writer.writeEmptyElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
        }

        // </wsp:Policy>
        writer.writeEndElement();
    }

    // </sp:SpnegoContextToken>
    writer.writeEndElement();
}