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

The following examples show how to use javax.xml.namespace.QName#equals() . 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: ResponseBuilder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
final Object readResponse(Object[] args, XMLStreamReader r, AttachmentSet att) throws JAXBException {
    Object obj;
    AttachmentUnmarshallerImpl au = (att != null)?new AttachmentUnmarshallerImpl(att):null;
    if (bridge instanceof RepeatedElementBridge) {
        RepeatedElementBridge rbridge = (RepeatedElementBridge)bridge;
        ArrayList list = new ArrayList();
        QName name = r.getName();
        while (r.getEventType()==XMLStreamReader.START_ELEMENT && name.equals(r.getName())) {
            list.add(rbridge.unmarshal(r, au));
            XMLStreamReaderUtil.toNextTag(r, name);
        }
        obj = rbridge.collectionHandler().convert(list);
    } else {
        obj = bridge.unmarshal(r, au);
    }
    return setter.put(obj,args);
}
 
Example 2
Source File: EndpointArgumentsBuilder.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
void readRequest( Object[] args, XMLStreamReader r, AttachmentSet att) throws JAXBException {
    Object obj = null;
    AttachmentUnmarshallerImpl au = (att != null)?new AttachmentUnmarshallerImpl(att):null;
    if (bridge instanceof RepeatedElementBridge) {
        RepeatedElementBridge rbridge = (RepeatedElementBridge)bridge;
        ArrayList list = new ArrayList();
        QName name = r.getName();
        while (r.getEventType()==XMLStreamReader.START_ELEMENT && name.equals(r.getName())) {
            list.add(rbridge.unmarshal(r, au));
            XMLStreamReaderUtil.toNextTag(r, name);
        }
        obj = rbridge.collectionHandler().convert(list);
    } else {
        obj = bridge.unmarshal(r, au);
    }
    setter.put(obj,args);
}
 
Example 3
Source File: HttpAdapterList.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a PortAddressResolver that maps portname to its address
 *
 * @param endpointImpl application endpoint Class that eventually serves the request.
 */
public PortAddressResolver createPortAddressResolver(final String baseAddress, final Class<?> endpointImpl) {
    return new PortAddressResolver() {
        @Override
        public String getAddressFor(@NotNull QName serviceName, @NotNull String portName) {
            String urlPattern = addressMap.get(new PortInfo(serviceName,portName, endpointImpl));
            if (urlPattern == null) {
                //if a WSDL defines more ports, urlpattern is null (portName does not match endpointImpl)
                //so fallback to the default behaviour where only serviceName/portName is checked
                for (Entry<PortInfo, String> e : addressMap.entrySet()) {
                    if (serviceName.equals(e.getKey().serviceName) && portName.equals(e.getKey().portName)) {
                            urlPattern = e.getValue();
                            break;
                    }
                }
            }
            return (urlPattern == null) ? null : baseAddress+urlPattern;
        }
    };
}
 
Example 4
Source File: PolicyUtils.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public int compare(final QName qn1, final QName qn2) {
    if (qn1 == qn2 || qn1.equals(qn2)) {
        return 0;
    }

    int result;

    result = qn1.getNamespaceURI().compareTo(qn2.getNamespaceURI());
    if (result != 0) {
        return result;
    }

    return qn1.getLocalPart().compareTo(qn2.getLocalPart());
}
 
Example 5
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void processStartTag(final StartElement element, final StartElement parent,
        final XMLEventReader reader, final Map<URI, Policy> map)
        throws PolicyException {
    try {
        final QName name = element.getName();
        if (parent == null) {
            if (!name.equals(POLICIES)) {
                throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<Policies>", name, element.getLocation())));
            }
        } else {
            final QName parentName = parent.getName();
            if (parentName.equals(POLICIES)) {
                if (!name.equals(POLICY_ATTACHMENT)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<PolicyAttachment>", name, element.getLocation())));
                }
            } else if (parentName.equals(POLICY_ATTACHMENT)) {
                if (name.equals(POLICY)) {
                    readPolicy(reader);
                    return;
                } else if (!name.equals(APPLIES_TO)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<AppliesTo> or <Policy>", name, element.getLocation())));
                }
            } else if (parentName.equals(APPLIES_TO)) {
                if (!name.equals(URI)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<URI>", name, element.getLocation())));
                }
            } else {
                throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0090_UNEXPECTED_ELEMENT(name, element.getLocation())));
            }
        }
        reader.nextEvent();
        this.unmarshal(reader, element);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(element.getLocation()), e));
    }
}
 
Example 6
Source File: MemberSubmissionAddressingWSDLParserExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private boolean addressibleElement(XMLStreamReader reader, WSDLFeaturedObject binding) {
    QName ua = reader.getName();
    if (ua.equals(AddressingVersion.MEMBER.wsdlExtensionTag)) {
        String required = reader.getAttributeValue(WSDLConstants.NS_WSDL, "required");
        binding.addFeature(new MemberSubmissionAddressingFeature(Boolean.parseBoolean(required)));
        XMLStreamReaderUtil.skipElement(reader);
        return true;        // UsingAddressing is consumed
    }

    return false;
}
 
Example 7
Source File: JwsImplGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static boolean equalsNSOptional(String strQName, QName checkQN) {
        if (strQName == null)
                return false;
        strQName = strQName.trim();
        QName reqQN = QName.valueOf(strQName);

        if (reqQN.getNamespaceURI() == null || reqQN.getNamespaceURI().equals(""))
                return reqQN.getLocalPart().equals(checkQN.getLocalPart());

        return reqQN.equals(checkQN);
}
 
Example 8
Source File: WSDLServiceImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
* gets the first port in this service which matches the portType
*/
public @Nullable
EditableWSDLPort getMatchingPort(QName portTypeName){
    for(EditableWSDLPort port : getPorts()){
        QName ptName = port.getBinding().getPortTypeName();
        assert (ptName != null);
        if(ptName.equals(portTypeName))
            return port;
    }
    return null;
}
 
Example 9
Source File: XPathExpressionImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private Object getResultAsType( XObject resultObject, QName returnType )
    throws javax.xml.transform.TransformerException {
    // XPathConstants.STRING
    if ( returnType.equals( XPathConstants.STRING ) ) {
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if ( returnType.equals( XPathConstants.NUMBER ) ) {
        return new Double ( resultObject.num());
    }
    // XPathConstants.BOOLEAN
    if ( returnType.equals( XPathConstants.BOOLEAN ) ) {
        return new Boolean( resultObject.bool());
    }
    // XPathConstants.NODESET ---ORdered, UNOrdered???
    if ( returnType.equals( XPathConstants.NODESET ) ) {
        return resultObject.nodelist();
    }
    // XPathConstants.NODE
    if ( returnType.equals( XPathConstants.NODE ) ) {
        NodeIterator ni = resultObject.nodeset();
        //Return the first node, or null
        return ni.nextNode();
    }
    // If isSupported check is already done then the execution path
    // shouldn't come here. Being defensive
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException ( fmsg );
}
 
Example 10
Source File: PolicyUtils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public int compare(final QName qn1, final QName qn2) {
    if (qn1 == qn2 || qn1.equals(qn2)) {
        return 0;
    }

    int result;

    result = qn1.getNamespaceURI().compareTo(qn2.getNamespaceURI());
    if (result != 0) {
        return result;
    }

    return qn1.getLocalPart().compareTo(qn2.getLocalPart());
}
 
Example 11
Source File: XPathImplUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get result depending on the QName type defined in XPathConstants
 * @param resultObject the result of an evaluation
 * @param returnType the return type
 * @return result per the return type
 * @throws TransformerException if the result can not be converted to
 * the specified return type.
 */
Object getResultAsType(XObject resultObject, QName returnType)
    throws TransformerException {
    // XPathConstants.STRING
    if (returnType.equals(XPathConstants.STRING)) {
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if (returnType.equals(XPathConstants.NUMBER)) {
        return resultObject.num();
    }
    // XPathConstants.BOOLEAN
    if (returnType.equals(XPathConstants.BOOLEAN)) {
        return resultObject.bool();
    }
    // XPathConstants.NODESET ---ORdered, UNOrdered???
    if (returnType.equals(XPathConstants.NODESET)) {
        return resultObject.nodelist();
    }
    // XPathConstants.NODE
    if (returnType.equals(XPathConstants.NODE)) {
        NodeIterator ni = resultObject.nodeset();
        //Return the first node, or null
        return ni.nextNode();
    }
    // If isSupported check is already done then the execution path
    // shouldn't come here. Being defensive
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException (fmsg);
}
 
Example 12
Source File: XPathImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSupported( QName returnType ) {
   if ( ( returnType.equals( XPathConstants.STRING ) ) ||
        ( returnType.equals( XPathConstants.NUMBER ) ) ||
        ( returnType.equals( XPathConstants.BOOLEAN ) ) ||
        ( returnType.equals( XPathConstants.NODE ) ) ||
        ( returnType.equals( XPathConstants.NODESET ) )  ) {

       return true;
   }
   return false;
}
 
Example 13
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void processStartTag(final StartElement element, final StartElement parent,
        final XMLEventReader reader, final Map<URI, Policy> map)
        throws PolicyException {
    try {
        final QName name = element.getName();
        if (parent == null) {
            if (!name.equals(POLICIES)) {
                throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<Policies>", name, element.getLocation())));
            }
        } else {
            final QName parentName = parent.getName();
            if (parentName.equals(POLICIES)) {
                if (!name.equals(POLICY_ATTACHMENT)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<PolicyAttachment>", name, element.getLocation())));
                }
            } else if (parentName.equals(POLICY_ATTACHMENT)) {
                if (name.equals(POLICY)) {
                    readPolicy(reader);
                    return;
                } else if (!name.equals(APPLIES_TO)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<AppliesTo> or <Policy>", name, element.getLocation())));
                }
            } else if (parentName.equals(APPLIES_TO)) {
                if (!name.equals(URI)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<URI>", name, element.getLocation())));
                }
            } else {
                throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0090_UNEXPECTED_ELEMENT(name, element.getLocation())));
            }
        }
        reader.nextEvent();
        this.unmarshal(reader, element);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(element.getLocation()), e));
    }
}
 
Example 14
Source File: XPathExpressionImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSupported( QName returnType ) {
   // XPathConstants.STRING
   if ( ( returnType.equals( XPathConstants.STRING ) ) ||
        ( returnType.equals( XPathConstants.NUMBER ) ) ||
        ( returnType.equals( XPathConstants.BOOLEAN ) ) ||
        ( returnType.equals( XPathConstants.NODE ) ) ||
        ( returnType.equals( XPathConstants.NODESET ) )  ) {

       return true;
   }
   return false;
}
 
Example 15
Source File: JwsImplGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean equalsNSOptional(String strQName, QName checkQN) {
        if (strQName == null)
                return false;
        strQName = strQName.trim();
        QName reqQN = QName.valueOf(strQName);

        if (reqQN.getNamespaceURI() == null || reqQN.getNamespaceURI().equals(""))
                return reqQN.getLocalPart().equals(checkQN.getLocalPart());

        return reqQN.equals(checkQN);
}
 
Example 16
Source File: RuntimeWSDLParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void parsePortTypeOperation(XMLStreamReader reader, EditableWSDLPortType portType) {
    String operationName = ParserUtil.getMandatoryNonEmptyAttribute(reader, WSDLConstants.ATTR_NAME);
    if (operationName == null) {
        //TODO: throw exception?
        //skip wsdl:portType element for now
        XMLStreamReaderUtil.skipElement(reader);
        return;
    }

    QName operationQName = new QName(portType.getName().getNamespaceURI(), operationName);
    EditableWSDLOperation operation = new WSDLOperationImpl(reader,portType, operationQName);
    extensionFacade.portTypeOperationAttributes(operation, reader);
    String parameterOrder = ParserUtil.getAttribute(reader, "parameterOrder");
    operation.setParameterOrder(parameterOrder);
    portType.put(operationName, operation);
    while (XMLStreamReaderUtil.nextElementContent(reader) != XMLStreamConstants.END_ELEMENT) {
        QName name = reader.getName();
        if (name.equals(WSDLConstants.QNAME_INPUT)) {
            parsePortTypeOperationInput(reader, operation);
        } else if (name.equals(WSDLConstants.QNAME_OUTPUT)) {
            parsePortTypeOperationOutput(reader, operation);
        } else if (name.equals(WSDLConstants.QNAME_FAULT)) {
            parsePortTypeOperationFault(reader, operation);
        } else {
            extensionFacade.portTypeOperationElements(operation, reader);
        }
    }
}
 
Example 17
Source File: JwsImplGenerator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean equalsNSOptional(String strQName, QName checkQN) {
        if (strQName == null)
                return false;
        strQName = strQName.trim();
        QName reqQN = QName.valueOf(strQName);

        if (reqQN.getNamespaceURI() == null || reqQN.getNamespaceURI().equals(""))
                return reqQN.getLocalPart().equals(checkQN.getLocalPart());

        return reqQN.equals(checkQN);
}
 
Example 18
Source File: ManagedServiceAssertion.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private ImplementationRecord findImplementation(QName implementationName) {
    final Iterator<PolicyAssertion> parameters = getParametersIterator();
    while (parameters.hasNext()) {
        final PolicyAssertion parameter = parameters.next();
        if (implementationName.equals(parameter.getName())) {
            return getImplementation(parameter);
        }
    }
    return null;
}
 
Example 19
Source File: WSServiceDelegate.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param wsepr EndpointReference from which portName will be extracted.
 *      If EndpointName ( port name) is null in EPR, then it will try to get if from WSDLModel using portType QName
 * @param portTypeName
 *          should be null in dispatch case
 *          should be non null in SEI case
 * @return
 *      port name from EPR after validating various metadat elements.
 *      Also if service instance does n't have wsdl,
 *      then it gets the WSDL metadata from EPR and builds wsdl model.
 */
private QName getPortNameFromEPR(@NotNull WSEndpointReference wsepr, @Nullable QName portTypeName) {
    QName portName;
    WSEndpointReference.Metadata metadata = wsepr.getMetaData();
    QName eprServiceName = metadata.getServiceName();
    QName eprPortName = metadata.getPortName();
    if ((eprServiceName != null ) && !eprServiceName.equals(serviceName)) {
        throw new WebServiceException("EndpointReference WSDL ServiceName differs from Service Instance WSDL Service QName.\n"
                + " The two Service QNames must match");
    }
    if (wsdlService == null) {
        Source eprWsdlSource = metadata.getWsdlSource();
        if (eprWsdlSource == null) {
            throw new WebServiceException(ProviderApiMessages.NULL_WSDL());
        }
        try {
            WSDLModel eprWsdlMdl = parseWSDL(new URL(wsepr.getAddress()), eprWsdlSource, null);
            wsdlService = eprWsdlMdl.getService(serviceName);
            if (wsdlService == null)
                throw new WebServiceException(ClientMessages.INVALID_SERVICE_NAME(serviceName,
                        buildNameList(eprWsdlMdl.getServices().keySet())));
        } catch (MalformedURLException e) {
            throw new WebServiceException(ClientMessages.INVALID_ADDRESS(wsepr.getAddress()));
        }
    }
    portName = eprPortName;

    if (portName == null && portTypeName != null) {
        //get the first port corresponding to the SEI
        WSDLPort port = wsdlService.getMatchingPort(portTypeName);
        if (port == null)
            throw new WebServiceException(ClientMessages.UNDEFINED_PORT_TYPE(portTypeName));
        portName = port.getName();
    }
    if (portName == null)
        throw new WebServiceException(ProviderApiMessages.NULL_PORTNAME());
    if (wsdlService.get(portName) == null)
        throw new WebServiceException(ClientMessages.INVALID_EPR_PORT_NAME(portName, buildWsdlPortNames()));

    return portName;

}
 
Example 20
Source File: Bug6937964Test.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public final void testNewDurationYearMonthLexicalRepresentation1() {

    /**
     * Lexical test values to test.
     */
    final String[] TEST_VALUES_LEXICAL = { "P13M", "P1Y1M", "-P13M", "-P1Y1M", "P1Y", "P1Y", "-P1Y", "-P1Y", "P1Y25M", "P3Y1M", "-P1Y25M", "-P3Y1M" };

    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException datatypeConfigurationException) {
        Assert.fail(datatypeConfigurationException.toString());
    }

    if (DEBUG) {
        System.err.println("DatatypeFactory created: " + datatypeFactory.toString());
    }

    // test each value
    for (int onTestValue = 0; onTestValue < TEST_VALUES_LEXICAL.length; onTestValue = onTestValue + 2) {

        if (DEBUG) {
            System.err.println("testing value: \"" + TEST_VALUES_LEXICAL[onTestValue] + "\", expecting: \"" + TEST_VALUES_LEXICAL[onTestValue + 1] + "\"");
        }

        try {
            Duration duration = datatypeFactory.newDurationYearMonth(TEST_VALUES_LEXICAL[onTestValue]);

            if (DEBUG) {
                System.err.println("Duration created: \"" + duration.toString() + "\"");
            }

            // was this expected to fail?
            if (TEST_VALUES_LEXICAL[onTestValue + 1].equals(TEST_VALUE_FAIL)) {
                Assert.fail("the value \"" + TEST_VALUES_LEXICAL[onTestValue] + "\" is invalid yet it created the Duration \"" + duration.toString() + "\"");
            }

            // right XMLSchemaType?
            // TODO: enable test, it should pass, it fails with Exception(s)
            // for now due to a bug
            try {
                QName xmlSchemaType = duration.getXMLSchemaType();
                if (!xmlSchemaType.equals(DatatypeConstants.DURATION_YEARMONTH)) {
                    Assert.fail("Duration created with XMLSchemaType of\"" + xmlSchemaType + "\" was expected to be \""
                            + DatatypeConstants.DURATION_YEARMONTH + "\" and has the value \"" + duration.toString() + "\"");
                }
            } catch (IllegalStateException illegalStateException) {
                // TODO; this test really should pass
                System.err.println("Please fix this bug that is being ignored, for now: " + illegalStateException.getMessage());
            }

            // does it have the right value?
            if (!TEST_VALUES_LEXICAL[onTestValue + 1].equals(duration.toString())) {
                Assert.fail("Duration created with \"" + TEST_VALUES_LEXICAL[onTestValue] + "\" was expected to be \""
                        + TEST_VALUES_LEXICAL[onTestValue + 1] + "\" and has the value \"" + duration.toString() + "\"");
            }

            // Duration created with correct value
        } catch (Exception exception) {

            if (DEBUG) {
                System.err.println("Exception in creating duration: \"" + exception.toString() + "\"");
            }

            // was this expected to succed?
            if (!TEST_VALUES_LEXICAL[onTestValue + 1].equals(TEST_VALUE_FAIL)) {
                Assert.fail("the value \"" + TEST_VALUES_LEXICAL[onTestValue] + "\" is valid yet it failed with \"" + exception.toString() + "\"");
            }
            // expected failure
        }
    }
}