Example usage for javax.xml.namespace QName equals

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

Introduction

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

Prototype

public final boolean equals(Object objectToTest) 

Source Link

Document

Test this QName for equality with another Object.

If the Object to be tested is not a QName or is null, then this method returns false.

Two QNames are considered equal if and only if both the Namespace URI and local part are equal.

Usage

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Test
public void testCreateFault1() {
    try {//from  www. j a  v  a 2s .c o m
        //SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        SOAPFactory factory = SOAPFactory.newInstance();
        SOAPFault sf = factory.createFault("This is the fault reason.", SOAPConstants.SOAP_RECEIVER_FAULT);
        assertNotNull(sf);
        QName fc = sf.getFaultCodeAsQName();
        Iterator i = sf.getFaultReasonTexts();

        String reason = "";
        while (i.hasNext()) {
            reason += (String) i.next();
        }
        log.info("Actual ReasonText=" + reason);
        assertNotNull(reason);
        assertTrue(reason.indexOf("This is the fault reason.") > -1);
        assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT));
    } catch (SOAPException e) {
        //Caught expected SOAPException
    } catch (Exception e) {
        fail("Exception: " + e);
    }
}

From source file:org.apache.axis2.schema.SchemaCompiler.java

/**
 *
 * @param parentElementQName - this could either be the complex type parentElementQName or element parentElementQName
 * @param items/*w w  w .j  a v  a 2  s.c om*/
 * @param metainfHolder
 * @param order
 * @param parentSchema
 * @throws SchemaCompilationException
 */
private void process(QName parentElementQName, XmlSchemaObjectCollection items,
        BeanWriterMetaInfoHolder metainfHolder, boolean order, XmlSchema parentSchema)
        throws SchemaCompilationException {
    int count = items.getCount();
    Map<XmlSchemaObject, Boolean> processedElementArrayStatusMap = new LinkedHashMap<XmlSchemaObject, Boolean>();
    Map processedElementTypeMap = new LinkedHashMap(); // TODO: not sure what is the correct generic type here
    List<QName> localNillableList = new ArrayList<QName>();

    Map<XmlSchemaObject, QName> particleQNameMap = new HashMap<XmlSchemaObject, QName>();

    // this list is used to keep the details of the
    // elements within a choice withing sequence
    List<QName> innerChoiceElementList = new ArrayList<QName>();

    Map<XmlSchemaObject, Integer> elementOrderMap = new HashMap<XmlSchemaObject, Integer>();

    int sequenceCounter = 0;
    for (int i = 0; i < count; i++) {
        XmlSchemaObject item = items.getItem(i);

        if (item instanceof XmlSchemaElement) {
            //recursively process the element
            XmlSchemaElement xsElt = (XmlSchemaElement) item;

            boolean isArray = isArray(xsElt);
            processElement(xsElt, processedElementTypeMap, localNillableList, parentSchema); //we know for sure this is not an outer type
            processedElementArrayStatusMap.put(xsElt, isArray);
            if (order) {
                //we need to keep the order of the elements. So push the elements to another
                //hashmap with the order number
                elementOrderMap.put(xsElt, sequenceCounter);
            }

            //handle xsd:any ! We place an OMElement (or an array of OMElements) in the generated class
        } else if (item instanceof XmlSchemaAny) {
            XmlSchemaAny any = (XmlSchemaAny) item;
            processedElementTypeMap.put(new QName(ANY_ELEMENT_FIELD_NAME), any);
            //any can also be inside a sequence
            if (order) {
                elementOrderMap.put(any, new Integer(sequenceCounter));
            }
            //we do not register the array status for the any type
            processedElementArrayStatusMap.put(any, isArray(any));
        } else if (item instanceof XmlSchemaSequence) {
            // we have to process many sequence types

            XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) item;
            if (xmlSchemaSequence.getItems().getCount() > 0) {
                BeanWriterMetaInfoHolder beanWriterMetaInfoHolder = new BeanWriterMetaInfoHolder();
                process(parentElementQName, xmlSchemaSequence.getItems(), beanWriterMetaInfoHolder, true,
                        parentSchema);
                beanWriterMetaInfoHolder.setParticleClass(true);
                String localName = parentElementQName.getLocalPart() + "Sequence";
                QName sequenceQName = new QName(parentElementQName.getNamespaceURI(),
                        localName + getNextTypeSuffix(localName));
                String javaClassName = writeComplexParticle(sequenceQName, beanWriterMetaInfoHolder);
                processedTypemap.put(sequenceQName, javaClassName);

                //put the partical to array
                Boolean isArray = xmlSchemaSequence.getMaxOccurs() > 1 ? Boolean.TRUE : Boolean.FALSE;
                processedElementArrayStatusMap.put(item, isArray);
                particleQNameMap.put(item, sequenceQName);

                if (order) {
                    elementOrderMap.put(item, new Integer(sequenceCounter));
                }
            }

        } else if (item instanceof XmlSchemaChoice) {
            // we have to process many sequence types

            XmlSchemaChoice xmlSchemaChoice = (XmlSchemaChoice) item;
            if (xmlSchemaChoice.getItems().getCount() > 0) {
                BeanWriterMetaInfoHolder beanWriterMetaInfoHolder = new BeanWriterMetaInfoHolder();
                beanWriterMetaInfoHolder.setChoice(true);
                process(parentElementQName, xmlSchemaChoice.getItems(), beanWriterMetaInfoHolder, false,
                        parentSchema);
                beanWriterMetaInfoHolder.setParticleClass(true);
                String localName = parentElementQName.getLocalPart() + "Choice";
                QName choiceQName = new QName(parentElementQName.getNamespaceURI(),
                        localName + getNextTypeSuffix(localName));
                String javaClassName = writeComplexParticle(choiceQName, beanWriterMetaInfoHolder);
                processedTypemap.put(choiceQName, javaClassName);

                //put the partical to array
                Boolean isArray = xmlSchemaChoice.getMaxOccurs() > 1 ? Boolean.TRUE : Boolean.FALSE;
                processedElementArrayStatusMap.put(item, isArray);
                particleQNameMap.put(item, choiceQName);

                if (order) {
                    elementOrderMap.put(item, new Integer(sequenceCounter));
                }
            }

        } else if (item instanceof XmlSchemaGroupRef) {

            XmlSchemaGroupRef xmlSchemaGroupRef = (XmlSchemaGroupRef) item;
            QName groupQName = xmlSchemaGroupRef.getRefName();
            if (groupQName != null) {
                if (!processedGroupTypeMap.containsKey(groupQName)) {
                    // processe the schema here
                    XmlSchema resolvedParentSchema = getParentSchema(parentSchema, groupQName, COMPONENT_GROUP);
                    if (resolvedParentSchema == null) {
                        throw new SchemaCompilationException("Can not find the group with the qname"
                                + groupQName + " from the parent schema " + parentSchema.getTargetNamespace());
                    } else {
                        XmlSchemaGroup xmlSchemaGroup = (XmlSchemaGroup) resolvedParentSchema.getGroups()
                                .getItem(groupQName);
                        if (xmlSchemaGroup != null) {
                            processGroup(xmlSchemaGroup, groupQName, resolvedParentSchema);
                        }
                    }
                }

                Boolean isArray = xmlSchemaGroupRef.getMaxOccurs() > 1 ? Boolean.TRUE : Boolean.FALSE;
                processedElementArrayStatusMap.put(item, isArray);
                particleQNameMap.put(item, groupQName);

                if (order) {
                    elementOrderMap.put(item, new Integer(sequenceCounter));
                }

            } else {
                throw new SchemaCompilationException("Referenced name is null");
            }
        } else {
            //there may be other types to be handled here. Add them
            //when we are ready
        }
        sequenceCounter++;
    }

    // loop through the processed items and add them to the matainf object
    int startingItemNumberOrder = metainfHolder.getOrderStartPoint();
    for (XmlSchemaObject child : processedElementArrayStatusMap.keySet()) {

        // process the XmlSchemaElement
        if (child instanceof XmlSchemaElement) {
            XmlSchemaElement elt = (XmlSchemaElement) child;
            QName referencedQName = null;

            if (elt.getQName() != null) {
                referencedQName = elt.getQName();
                QName schemaTypeQName = elt.getSchemaType() != null ? elt.getSchemaType().getQName()
                        : elt.getSchemaTypeName();
                if (schemaTypeQName != null) {
                    String clazzName = (String) processedElementTypeMap.get(elt.getQName());
                    metainfHolder.registerMapping(referencedQName, schemaTypeQName, clazzName,
                            processedElementArrayStatusMap.get(elt) ? SchemaConstants.ARRAY_TYPE
                                    : SchemaConstants.ELEMENT_TYPE);
                    if (innerChoiceElementList.contains(referencedQName)) {
                        metainfHolder.addtStatus(referencedQName, SchemaConstants.INNER_CHOICE_ELEMENT);
                    }
                    // register the default value as well
                    if (elt.getDefaultValue() != null) {
                        metainfHolder.registerDefaultValue(referencedQName, elt.getDefaultValue());
                    }

                }
            }

            if (elt.getRefName() != null) { //probably this is referenced
                referencedQName = elt.getRefName();
                boolean arrayStatus = processedElementArrayStatusMap.get(elt);
                String clazzName = findRefClassName(referencedQName, arrayStatus);
                if (clazzName == null) {
                    clazzName = findClassName(referencedQName, arrayStatus);
                }
                XmlSchema resolvedParentSchema = getParentSchema(parentSchema, referencedQName,
                        COMPONENT_ELEMENT);
                if (resolvedParentSchema == null) {
                    throw new SchemaCompilationException("Can not find the element " + referencedQName
                            + " from the parent schema " + parentSchema.getTargetNamespace());
                } else {
                    XmlSchemaElement refElement = resolvedParentSchema.getElementByName(referencedQName);

                    // register the mapping if we found the referenced element
                    // else throw an exception
                    if (refElement != null) {
                        metainfHolder.registerMapping(referencedQName, refElement.getSchemaTypeName(),
                                clazzName,
                                arrayStatus ? SchemaConstants.ARRAY_TYPE : SchemaConstants.ELEMENT_TYPE);
                    } else {
                        if (referencedQName.equals(SchemaConstants.XSD_SCHEMA)) {
                            metainfHolder.registerMapping(referencedQName, null, writer.getDefaultClassName(),
                                    SchemaConstants.ANY_TYPE);
                        } else {
                            throw new SchemaCompilationException(SchemaCompilerMessages.getMessage(
                                    "schema.referencedElementNotFound", referencedQName.toString()));
                        }
                    }
                }
            }

            if (referencedQName == null) {
                throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("schema.emptyName"));
            }

            //register the occurence counts
            metainfHolder.addMaxOccurs(referencedQName, elt.getMaxOccurs());
            // if the strict validation off then we consider all elements have minOccurs zero on it
            if (this.options.isOffStrictValidation()) {
                metainfHolder.addMinOccurs(referencedQName, 0);
            } else {
                metainfHolder.addMinOccurs(referencedQName, elt.getMinOccurs());
            }
            //we need the order to be preserved. So record the order also
            if (order) {
                //record the order in the metainf holder
                metainfHolder.registerQNameIndex(referencedQName,
                        startingItemNumberOrder + elementOrderMap.get(elt));
            }

            //get the nillable state and register that on the metainf holder
            if (localNillableList.contains(elt.getQName())) {
                metainfHolder.registerNillableQName(elt.getQName());
            }

            //get the binary state and add that to the status map
            if (isBinary(elt)) {
                metainfHolder.addtStatus(elt.getQName(), SchemaConstants.BINARY_TYPE);
            }
            // process the XMLSchemaAny
        } else if (child instanceof XmlSchemaAny) {
            XmlSchemaAny any = (XmlSchemaAny) child;

            //since there is only one element here it does not matter
            //for the constant. However the problem occurs if the users
            //uses the same name for an element decalration
            QName anyElementFieldName = new QName(ANY_ELEMENT_FIELD_NAME);

            //this can be an array or a single element
            boolean isArray = processedElementArrayStatusMap.get(any);
            metainfHolder.registerMapping(anyElementFieldName, null,
                    isArray ? writer.getDefaultClassArrayName() : writer.getDefaultClassName(),
                    SchemaConstants.ANY_TYPE);
            //if it's an array register an extra status flag with the system
            if (isArray) {
                metainfHolder.addtStatus(anyElementFieldName, SchemaConstants.ARRAY_TYPE);
            }
            metainfHolder.addMaxOccurs(anyElementFieldName, any.getMaxOccurs());
            metainfHolder.addMinOccurs(anyElementFieldName, any.getMinOccurs());

            if (order) {
                //record the order in the metainf holder for the any
                metainfHolder.registerQNameIndex(anyElementFieldName,
                        startingItemNumberOrder + elementOrderMap.get(any));
            }
        } else if (child instanceof XmlSchemaSequence) {
            XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) child;
            QName sequenceQName = particleQNameMap.get(child);
            boolean isArray = xmlSchemaSequence.getMaxOccurs() > 1;

            // add this as an array to the original class
            metainfHolder.registerMapping(sequenceQName, sequenceQName, findClassName(sequenceQName, isArray));
            if (isArray) {
                metainfHolder.addtStatus(sequenceQName, SchemaConstants.ARRAY_TYPE);
            }
            metainfHolder.addtStatus(sequenceQName, SchemaConstants.PARTICLE_TYPE_ELEMENT);
            metainfHolder.addMaxOccurs(sequenceQName, xmlSchemaSequence.getMaxOccurs());
            metainfHolder.addMinOccurs(sequenceQName, xmlSchemaSequence.getMinOccurs());
            metainfHolder.setHasParticleType(true);

            if (order) {
                //record the order in the metainf holder for the any
                metainfHolder.registerQNameIndex(sequenceQName,
                        startingItemNumberOrder + elementOrderMap.get(child));
            }
        } else if (child instanceof XmlSchemaChoice) {
            XmlSchemaChoice xmlSchemaChoice = (XmlSchemaChoice) child;
            QName choiceQName = particleQNameMap.get(child);
            boolean isArray = xmlSchemaChoice.getMaxOccurs() > 1;

            // add this as an array to the original class
            metainfHolder.registerMapping(choiceQName, choiceQName, findClassName(choiceQName, isArray));
            if (isArray) {
                metainfHolder.addtStatus(choiceQName, SchemaConstants.ARRAY_TYPE);
            }
            metainfHolder.addtStatus(choiceQName, SchemaConstants.PARTICLE_TYPE_ELEMENT);
            metainfHolder.addMaxOccurs(choiceQName, xmlSchemaChoice.getMaxOccurs());
            metainfHolder.addMinOccurs(choiceQName, xmlSchemaChoice.getMinOccurs());
            metainfHolder.setHasParticleType(true);

            if (order) {
                //record the order in the metainf holder for the any
                metainfHolder.registerQNameIndex(choiceQName,
                        startingItemNumberOrder + elementOrderMap.get(child));
            }
        } else if (child instanceof XmlSchemaGroupRef) {
            XmlSchemaGroupRef xmlSchemaGroupRef = (XmlSchemaGroupRef) child;
            QName groupQName = particleQNameMap.get(child);
            boolean isArray = xmlSchemaGroupRef.getMaxOccurs() > 1;

            // add this as an array to the original class
            String groupClassName = processedGroupTypeMap.get(groupQName);
            if (isArray) {
                groupClassName = groupClassName + "[]";
            }
            metainfHolder.registerMapping(groupQName, groupQName, groupClassName);
            if (isArray) {
                metainfHolder.addtStatus(groupQName, SchemaConstants.ARRAY_TYPE);
            }
            metainfHolder.addtStatus(groupQName, SchemaConstants.PARTICLE_TYPE_ELEMENT);
            metainfHolder.addMaxOccurs(groupQName, xmlSchemaGroupRef.getMaxOccurs());
            metainfHolder.addMinOccurs(groupQName, xmlSchemaGroupRef.getMinOccurs());
            metainfHolder.setHasParticleType(true);

            if (order) {
                //record the order in the metainf holder for the any
                metainfHolder.registerQNameIndex(groupQName,
                        startingItemNumberOrder + elementOrderMap.get(child));
            }
        }
    }

    //set the ordered flag in the metainf holder
    metainfHolder.setOrdered(order);
}

From source file:org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.ServiceProcessor.java

private MessageInfo getMessage(QName operationName, boolean isIn) {
    for (OperationInfo operation : service.getInterface().getOperations()) {
        if (operationName.equals(operation.getName()) && isIn) {
            return operation.getInput();
        } else {/* ww w.ja va  2  s  .  c o m*/
            return operation.getOutput();
        }
    }
    return null;
}

From source file:org.apache.cxf.ws.security.sts.provider.SecurityTokenServiceProvider.java

public Source invoke(Source request) {
    Source response = null;//from  w  ww.java  2  s.  c  o m
    try {
        RequestSecurityTokenType rst = convertToJAXBObject(request);
        Object operationImpl = null;
        List<?> objectList = rst.getAny();
        for (int i = 0; i < objectList.size(); i++) {
            Object obj = objectList.get(i);
            if (obj instanceof JAXBElement) {
                QName qname = ((JAXBElement<?>) obj).getName();
                if (qname.equals(new QName(WSTRUST_13_NAMESPACE, WSTRUST_REQUESTTYPE_ELEMENTNAME))) {
                    operationImpl = operationMap.get(((JAXBElement<?>) obj).getValue().toString());
                    break;
                }

            }
        }

        if (operationImpl == null) {
            throw new Exception("Implementation for this operation not found.");
        }
        Method[] methods = operationImpl.getClass().getMethods();
        for (int x = 0; x < methods.length; x++) {
            Class<?>[] paramClass = methods[x].getParameterTypes();
            if (paramClass.length == 1 && paramClass[0].equals(rst.getClass())) {
                RequestSecurityTokenResponseCollectionType tokenResponse = (RequestSecurityTokenResponseCollectionType) methods[x]
                        .invoke(operationImpl, rst);
                if (tokenResponse == null) {
                    throw new Exception("Error in implementation class.");
                }

                response = new JAXBSource(jaxbContext,
                        new ObjectFactory().createRequestSecurityTokenResponseCollection(tokenResponse));
                return response;
            }
        }

    } catch (Exception e) {
        LOG.error(e);
        try {
            SOAPFault fault = soapFactory.createFault();
            if (e.getMessage() == null) {
                fault.setFaultString(e.getCause().getMessage());
            } else {
                fault.setFaultString(e.getMessage());
            }
            Detail detail = fault.addDetail();
            detail = fault.getDetail();
            QName qName = new QName(WSTRUST_13_NAMESPACE, "Fault", "ns");
            DetailEntry de = detail.addDetailEntry(qName);
            qName = new QName(WSTRUST_13_NAMESPACE, "ErrorCode", "ns");
            SOAPElement errorElement = de.addChildElement(qName);
            StackTraceElement[] ste = e.getStackTrace();
            errorElement.setTextContent(ste[0].toString());
            throw new SOAPFaultException(fault);
        } catch (SOAPException e1) {
            LOG.error(e1);
        }

    }

    return response;
}

From source file:org.apache.ddlutils.io.DatabaseIO.java

/**
 * Compares the given qnames. This specifically ignores the namespace
 * uri of the other qname if the namespace of the current element is
 * empty./*from  w ww . ja v a 2s  . co m*/
 * 
 * @param curElemQName The qname of the current element
 * @param qName        The qname to compare to
 * @return <code>true</code> if they are the same
 */
private boolean isSameAs(QName curElemQName, QName qName) {
    if (StringUtils.isEmpty(curElemQName.getNamespaceURI())) {
        return qName.getLocalPart().equals(curElemQName.getLocalPart());
    } else {
        return qName.equals(curElemQName);
    }
}

From source file:org.apache.hadoop.util.ConfTest.java

private static List<NodeInfo> parseConf(InputStream in) throws XMLStreamException {
    QName configuration = new QName("configuration");
    QName property = new QName("property");

    List<NodeInfo> nodes = new ArrayList<NodeInfo>();
    Stack<NodeInfo> parsed = new Stack<NodeInfo>();

    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLEventReader reader = factory.createXMLEventReader(in);

    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        if (event.isStartElement()) {
            StartElement currentElement = event.asStartElement();
            NodeInfo currentNode = new NodeInfo(currentElement);
            if (parsed.isEmpty()) {
                if (!currentElement.getName().equals(configuration)) {
                    return null;
                }//from  w w w  .j av a  2s . c  o  m
            } else {
                NodeInfo parentNode = parsed.peek();
                QName parentName = parentNode.getStartElement().getName();
                if (parentName.equals(configuration)
                        && currentNode.getStartElement().getName().equals(property)) {
                    @SuppressWarnings("unchecked")
                    Iterator<Attribute> it = currentElement.getAttributes();
                    while (it.hasNext()) {
                        currentNode.addAttribute(it.next());
                    }
                } else if (parentName.equals(property)) {
                    parentNode.addElement(currentElement);
                }
            }
            parsed.push(currentNode);
        } else if (event.isEndElement()) {
            NodeInfo node = parsed.pop();
            if (parsed.size() == 1) {
                nodes.add(node);
            }
        } else if (event.isCharacters()) {
            if (2 < parsed.size()) {
                NodeInfo parentNode = parsed.pop();
                StartElement parentElement = parentNode.getStartElement();
                NodeInfo grandparentNode = parsed.peek();
                if (grandparentNode.getElement(parentElement) == null) {
                    grandparentNode.setElement(parentElement, event.asCharacters());
                }
                parsed.push(parentNode);
            }
        }
    }

    return nodes;
}

From source file:org.apache.hadoop.util.ConfTest.java

public static List<String> checkConf(InputStream in) {
    List<NodeInfo> nodes = null;
    List<String> errors = new ArrayList<String>();

    try {//w ww  .  ja v  a2  s .  c o  m
        nodes = parseConf(in);
        if (nodes == null) {
            errors.add("bad conf file: top-level element not <configuration>");
        }
    } catch (XMLStreamException e) {
        errors.add("bad conf file: " + e.getMessage());
    }

    if (!errors.isEmpty()) {
        return errors;
    }

    Map<String, List<Integer>> duplicatedProperties = new HashMap<String, List<Integer>>();

    for (NodeInfo node : nodes) {
        StartElement element = node.getStartElement();
        int line = element.getLocation().getLineNumber();

        if (!element.getName().equals(new QName("property"))) {
            errors.add(String.format("Line %d: element not <property>", line));
            continue;
        }

        List<XMLEvent> events = node.getXMLEventsForQName(new QName("name"));
        if (events == null) {
            errors.add(String.format("Line %d: <property> has no <name>", line));
        } else {
            String v = null;
            for (XMLEvent event : events) {
                if (event.isAttribute()) {
                    v = ((Attribute) event).getValue();
                } else {
                    Characters c = node.getElement(event.asStartElement());
                    if (c != null) {
                        v = c.getData();
                    }
                }
                if (v == null || v.isEmpty()) {
                    errors.add(String.format("Line %d: <property> has an empty <name>", line));
                }
            }
            if (v != null && !v.isEmpty()) {
                List<Integer> lines = duplicatedProperties.get(v);
                if (lines == null) {
                    lines = new ArrayList<Integer>();
                    duplicatedProperties.put(v, lines);
                }
                lines.add(node.getStartElement().getLocation().getLineNumber());
            }
        }

        events = node.getXMLEventsForQName(new QName("value"));
        if (events == null) {
            errors.add(String.format("Line %d: <property> has no <value>", line));
        }

        for (QName qName : node.getDuplicatedQNames()) {
            if (!qName.equals(new QName("source"))) {
                errors.add(String.format("Line %d: <property> has duplicated <%s>s", line, qName));
            }
        }
    }

    for (Entry<String, List<Integer>> e : duplicatedProperties.entrySet()) {
        List<Integer> lines = e.getValue();
        if (1 < lines.size()) {
            errors.add(String.format("Line %s: duplicated <property>s for %s", StringUtils.join(", ", lines),
                    e.getKey()));
        }
    }

    return errors;
}

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

public static Element findElement(QName elementName, List<Object> content) {
    for (Object o : content) {
        if (o instanceof Element) {
            Element u = (Element) o;
            QName n = new QName(u.getNamespaceURI(), u.getLocalName());
            if (n.equals(elementName)) {
                return u;
            }//from   w  w w  .j a v  a 2 s  .c  o m
        }
    }
    return null;
}

From source file:org.apache.hise.utils.TaskXmlUtils.java

/**
 * Creates {@link XPath} aware of request namespaces.
 *//*from w  w  w .ja  v  a2 s  . co m*/
synchronized XPath createXPathInstance() {

    XPath xpath = this.xPathFactory.newXPath();

    xpath.setNamespaceContext(this.namespaceContext);
    xpath.setXPathFunctionResolver(new XPathFunctionResolver() {

        public XPathFunction resolveFunction(QName functionName, int arity) {

            if (functionName == null) {
                throw new NullPointerException("The function name cannot be null.");
            }

            if (functionName.equals(new QName("http://www.example.org/WS-HT", "getInput", "htd"))) {

                return new GetXPathFunction(input);
            }

            if (functionName.equals(new QName("http://www.example.org/WS-HT", "getOutput", "htd"))) {

                return new GetXPathFunction(output);
            }

            return null;
        }
    });

    return xpath;
}

From source file:org.apache.ode.bpel.compiler.AssignGenerator.java

/**
 * Verify that a copy follows the correct form.
 *
 * @param ocopy/*  ww w . j a v a  2  s .  co  m*/
 */
private void verifyCopy(OAssign.Copy ocopy) {
    if (__log.isDebugEnabled())
        __log.debug("verifying copy: " + ocopy);

    // If direct Message->Message copy
    if (ocopy.to instanceof OAssign.VariableRef && ((OAssign.VariableRef) ocopy.to).isMessageRef()
            && ocopy.from instanceof OAssign.VariableRef && ((OAssign.VariableRef) ocopy.from).isMessageRef()) {
        // Check that the LValue/RValue message types match up.
        String lvar = ((OAssign.VariableRef) ocopy.to).variable.name;
        String rvar = ((OAssign.VariableRef) ocopy.from).variable.name;
        QName tlvalue = ((OMessageVarType) ((OAssign.VariableRef) ocopy.to).variable.type).messageType;
        QName trvalue = ((OMessageVarType) ((OAssign.VariableRef) ocopy.from).variable.type).messageType;

        if (!tlvalue.equals(trvalue))
            throw new CompilationException(
                    __cmsgs.errMismatchedMessageAssignment(lvar, tlvalue, rvar, trvalue));

    }

    // If Message->Non-Message copy
    else if (ocopy.from instanceof OAssign.VariableRef && ((OAssign.VariableRef) ocopy.from).isMessageRef()
            && (!(ocopy.to instanceof OAssign.VariableRef)
                    || !((OAssign.VariableRef) ocopy.to).isMessageRef())) {
        String rval = ((OAssign.VariableRef) ocopy.from).variable.name;
        throw new CompilationException(__cmsgs.errCopyFromMessageToNonMessage(rval));

    }

    // If Non-Message->Message copy
    else if (ocopy.to instanceof OAssign.VariableRef && ((OAssign.VariableRef) ocopy.to).isMessageRef()
            && (!(ocopy.from instanceof OAssign.VariableRef)
                    || !((OAssign.VariableRef) ocopy.from).isMessageRef())) {

        String lval = ((OAssign.VariableRef) ocopy.to).variable.name;
        throw new CompilationException(__cmsgs.errCopyToMessageFromNonMessage(lval));
    }

    // If *->Partner Link copy
    else if (ocopy.to instanceof OAssign.PartnerLinkRef
            && !((OAssign.PartnerLinkRef) ocopy.to).partnerLink.hasPartnerRole()) {
        String lval = ((OAssign.PartnerLinkRef) ocopy.to).partnerLink.getName();
        throw new CompilationException(__cmsgs.errCopyToUndeclaredPartnerRole(lval));
    }

    // If Partner Link->* copy
    else if (ocopy.from instanceof OAssign.PartnerLinkRef) {
        if (((OAssign.PartnerLinkRef) ocopy.from).isMyEndpointReference
                && !((OAssign.PartnerLinkRef) ocopy.from).partnerLink.hasMyRole()) {
            String lval = ((OAssign.PartnerLinkRef) ocopy.from).partnerLink.getName();
            throw new CompilationException(__cmsgs.errCopyFromUndeclaredPartnerRole(lval, "myRole"));
        }
        if (!((OAssign.PartnerLinkRef) ocopy.from).isMyEndpointReference
                && !((OAssign.PartnerLinkRef) ocopy.from).partnerLink.hasPartnerRole()) {
            String lval = ((OAssign.PartnerLinkRef) ocopy.from).partnerLink.getName();
            throw new CompilationException(__cmsgs.errCopyFromUndeclaredPartnerRole(lval, "partnerRole"));
        }
    }

    __log.debug("Copy verified OK: " + ocopy);
}