Example usage for org.w3c.dom Element getLocalName

List of usage examples for org.w3c.dom Element getLocalName

Introduction

In this page you can find the example usage for org.w3c.dom Element getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:org.apache.ode.bpel.compiler.bom.BpelObjectFactory.java

public BpelObject createBpelObject(Element el, URI uri) {
    QName type = new QName(el.getNamespaceURI(), el.getLocalName());
    Class cls = _mappings.get(type);
    if (cls == null) {
        __log.warn("Unrecognized element in BPEL dom: " + type);
        return new BpelObject(el);
    }//from  w  w w.  ja va2 s  .c o  m
    try {
        Constructor ctor = cls.getConstructor(__CTOR);
        BpelObject bo = (BpelObject) ctor.newInstance(new Object[] { el });
        bo.setURI(uri);
        return bo;
    } catch (Exception ex) {
        throw new RuntimeException("Internal compiler error", ex);
    }
}

From source file:org.apache.ode.bpel.epr.WSAEndpoint.java

public boolean accept(Node node) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element elmt = (Element) node;
        if (elmt.getLocalName().equals(SERVICE_REF_QNAME.getLocalPart())
                && elmt.getNamespaceURI().equals(SERVICE_REF_QNAME.getNamespaceURI()))
            elmt = DOMUtils.getFirstChildElement(elmt);
        if (elmt != null && elmt.getLocalName().equals("EndpointReference")
                && elmt.getNamespaceURI().equals(Namespaces.WS_ADDRESSING_NS))
            return true;
    }//w ww.j  a  va  2s .  co m
    return false;
}

From source file:org.apache.ode.bpel.rtrep.v1.ASSIGN.java

/**
  * Get the r-value. There are several possibilities:
  * <ul>//from w  w w  . j a  va2s.co m
  * <li>a message is selected - an element representing the whole message is
  * returned.</li>
  * <li>a (element) message part is selected - the element is returned.
  * </li>
  * <li>a (typed) message part is select - a wrapper element is returned.
  * </li>
  * <li>an attribute is selected - an attribute node is returned. </li>
  * <li>a text node/string expression is selected - a text node is returned.
  * </li>
  * </ul>
  *
  * @param from
  *
  * @return Either {@link Element}, {@link org.w3c.dom.Text}, or
  *         {@link org.w3c.dom.Attr} node representing the r-value.
  *
  * @throws FaultException
  *             DOCUMENTME
  * @throws UnsupportedOperationException
  *             DOCUMENTME
  * @throws IllegalStateException
  *             DOCUMENTME
  */
private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException {
    if (__log.isDebugEnabled())
        __log.debug("Evaluating FROM expression \"" + from + "\".");

    Node retVal;
    if (from instanceof DirectRef) {
        OAssign.DirectRef dref = (OAssign.DirectRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(dref.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false);
        retVal = DOMUtils.findChildByName((Element) data, dref.elName);
    } else if (from instanceof OAssign.VariableRef) {
        OAssign.VariableRef varRef = (OAssign.VariableRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(varRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false);
        retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PropertyRef) {
        OAssign.PropertyRef propRef = (OAssign.PropertyRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(propRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false);
        retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PartnerLinkRef) {
        OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from;
        PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink);
        Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntime().fetchMyRoleEndpointReferenceData(pLink)
                : getBpelRuntime().fetchPartnerRoleEndpointReferenceData(pLink);
        if (__log.isDebugEnabled())
            __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName()
                    + " has value " + DOMUtils.domToString(tempVal));
        retVal = tempVal;
    } else if (from instanceof OAssign.Expression) {
        OExpression expr = ((OAssign.Expression) from).expression;
        List<Node> l = getBpelRuntime().getExpLangRuntime().evaluate(expr, getEvaluationContext());
        if (l.size() == 0) {
            String msg = __msgs.msgRValueNoNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg,
                    new Throwable("ignoreMissingFromData"));
        } else if (l.size() > 1) {
            String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
        retVal = (Node) l.get(0);
    } else if (from instanceof OAssign.Literal) {
        Element literalRoot = ((OAssign.Literal) from).getXmlLiteral().getDocumentElement();
        assert literalRoot.getLocalName().equals("literal");
        // We'd like a single text node...

        literalRoot.normalize();
        retVal = literalRoot.getFirstChild();

        // Adjust for whitespace before an element.
        if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE
                && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) {
            retVal = retVal.getNextSibling();
        }

        if (retVal == null) {
            // Special case, no children --> empty TII
            retVal = literalRoot.getOwnerDocument().createTextNode("");
        } else if (retVal.getNodeType() == Node.ELEMENT_NODE) {
            // Make sure there is no more elements.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMultipleEIIs();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }
        } else if (retVal.getNodeType() == Node.TEXT_NODE) {
            // Make sure there are no elements following this text node.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMixedContent();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }

        }

        if (retVal == null) {
            String msg = __msgs.msgLiteralMustContainTIIorEII();
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
    } else {
        String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from);
        if (__log.isErrorEnabled())
            __log.error(from + ": " + msg);
        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now verify we got something.
    if (retVal == null) {
        String msg = __msgs.msgEmptyRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);
        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now check that we got the right thing.
    switch (retVal.getNodeType()) {
    case Node.TEXT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ELEMENT_NODE:
    case Node.CDATA_SECTION_NODE:
        break;
    default:
        String msg = __msgs.msgInvalidRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);

        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

    }

    return retVal;
}

From source file:org.apache.ode.bpel.rtrep.v1.ASSIGN.java

private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }/* w w w.j  a v a2s .  c o m*/

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName());
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (!attr.getName().startsWith("xmlns")) {
            replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true));
            // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually
            int colonIdx = attr.getValue().indexOf(":");
            if (colonIdx > 0) {
                String prefix = attr.getValue().substring(0, colonIdx);
                String attrValNs = src.lookupPrefix(prefix);
                if (attrValNs != null)
                    replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs);
            }
        }
    }
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}

From source file:org.apache.ode.bpel.rtrep.v2.ASSIGN.java

/**
 * Get the r-value. There are several possibilities:
 * <ul>/* w w  w .j  av  a  2 s. c  om*/
 * <li>a message is selected - an element representing the whole message is
 * returned.</li>
 * <li>a (element) message part is selected - the element is returned.
 * </li>
 * <li>a (typed) message part is select - a wrapper element is returned.
 * </li>
 * <li>an attribute is selected - an attribute node is returned. </li>
 * <li>a text node/string expression is selected - a text node is returned.
 * </li>
 * </ul>
 *
 * @param from
 *
 * @return Either {@link Element}, {@link org.w3c.dom.Text}, or
 *         {@link org.w3c.dom.Attr} node representing the r-value.
 *
 * @throws FaultException
 *             DOCUMENTME
 * @throws UnsupportedOperationException
 *             DOCUMENTME
 * @throws IllegalStateException
 *             DOCUMENTME
 */
private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException {
    if (__log.isDebugEnabled())
        __log.debug("Evaluating FROM expression \"" + from + "\".");

    Node retVal;
    if (from instanceof OAssign.DirectRef) {
        OAssign.DirectRef dref = (OAssign.DirectRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(dref.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false);
        retVal = DOMUtils.findChildByName((Element) data, dref.elName);
    } else if (from instanceof OAssign.VariableRef) {
        OAssign.VariableRef varRef = (OAssign.VariableRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(varRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false);
        retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PropertyRef) {
        OAssign.PropertyRef propRef = (OAssign.PropertyRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(propRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false);
        retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PartnerLinkRef) {
        OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from;
        PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink);
        Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntime().fetchMyRoleEndpointReferenceData(pLink)
                : getBpelRuntime().fetchPartnerRoleEndpointReferenceData(pLink);
        if (__log.isDebugEnabled())
            __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName()
                    + " has value " + DOMUtils.domToString(tempVal));
        retVal = tempVal;
    } else if (from instanceof OAssign.Expression) {
        OExpression expr = ((OAssign.Expression) from).expression;
        List<Node> l = getBpelRuntime().getExpLangRuntime().evaluate(expr, getEvaluationContext());

        if (l.size() == 0) {
            String msg = __msgs.msgRValueNoNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg,
                    new Throwable("ignoreMissingFromData"));
        } else if (l.size() > 1) {
            String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
        retVal = l.get(0);
    } else if (from instanceof OAssign.Literal) {
        Element literalRoot = ((OAssign.Literal) from).getXmlLiteral().getDocumentElement();
        assert literalRoot.getLocalName().equals("literal");
        // We'd like a single text node...

        literalRoot.normalize();
        retVal = literalRoot.getFirstChild();

        // Adjust for whitespace before an element.
        if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE
                && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) {
            retVal = retVal.getNextSibling();
        }

        if (retVal == null) {
            // Special case, no children --> empty TII
            retVal = literalRoot.getOwnerDocument().createTextNode("");
        } else if (retVal.getNodeType() == Node.ELEMENT_NODE) {
            // Make sure there is no more elements.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMultipleEIIs();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }
        } else if (retVal.getNodeType() == Node.TEXT_NODE) {
            // Make sure there are no elements following this text node.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMixedContent();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }

        }

        if (retVal == null) {
            String msg = __msgs.msgLiteralMustContainTIIorEII();
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
    } else {
        String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from);
        if (__log.isErrorEnabled())
            __log.error(from + ": " + msg);
        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now verify we got something.
    if (retVal == null) {
        String msg = __msgs.msgEmptyRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);
        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now check that we got the right thing.
    switch (retVal.getNodeType()) {
    case Node.TEXT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ELEMENT_NODE:
    case Node.CDATA_SECTION_NODE:
        break;
    default:
        String msg = __msgs.msgInvalidRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);

        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

    }

    return retVal;
}

From source file:org.apache.ode.bpel.rtrep.v2.ASSIGN.java

private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }/* ww w  .ja va  2  s.  com*/

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName());
    if (ptr.getPrefix() != null) {
        replacement.setPrefix(ptr.getPrefix());
    }
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (!attr.getName().startsWith("xmlns")) {
            replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true));
            // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually
            int colonIdx = attr.getValue().indexOf(":");
            if (colonIdx > 0) {
                String prefix = attr.getValue().substring(0, colonIdx);
                String attrValNs = src.lookupPrefix(prefix);
                if (attrValNs != null)
                    replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs);
            }
        }
    }
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}

From source file:org.apache.ode.bpel.rtrep.v2.AssignHelper.java

/**
 * Get the r-value. There are several possibilities:
 * <ul>//from   ww w.  ja v  a 2 s  .com
 * <li>a message is selected - an element representing the whole message is
 * returned.</li>
 * <li>a (element) message part is selected - the element is returned.
 * </li>
 * <li>a (typed) message part is select - a wrapper element is returned.
 * </li>
 * <li>an attribute is selected - an attribute node is returned. </li>
 * <li>a text node/string expression is selected - a text node is returned.
 * </li>
 * </ul>
 * (madars.vitolins _at gmail.com - 2009.04.17 - moved from ASSIGN here)
 * @param from
 *
 * @return Either {@link Element}, {@link org.w3c.dom.Text}, or
 *         {@link org.w3c.dom.Attr} node representing the r-value.
 *
 * @throws FaultException
 *             DOCUMENTME
 * @throws UnsupportedOperationException
 *             DOCUMENTME
 * @throws IllegalStateException
 *             DOCUMENTME
 */
public Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException {
    if (__log.isDebugEnabled())
        __log.debug("Evaluating FROM expression \"" + from + "\".");

    Node retVal;
    if (from instanceof OAssign.DirectRef) {
        OAssign.DirectRef dref = (OAssign.DirectRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(dref.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false);
        retVal = DOMUtils.findChildByName((Element) data, dref.elName);
    } else if (from instanceof OAssign.VariableRef) {
        OAssign.VariableRef varRef = (OAssign.VariableRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(varRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false);
        retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PropertyRef) {
        OAssign.PropertyRef propRef = (OAssign.PropertyRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(propRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false);
        retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PartnerLinkRef) {
        OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from;
        PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink);
        Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntime().fetchMyRoleEndpointReferenceData(pLink)
                : getBpelRuntime().fetchPartnerRoleEndpointReferenceData(pLink);
        if (__log.isDebugEnabled())
            __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName()
                    + " has value " + DOMUtils.domToString(tempVal));
        retVal = tempVal;
    } else if (from instanceof OAssign.ContextRef) {
        OAssign.ContextRef ctxRef = (OAssign.ContextRef) from;
        ContextData cdata = getBpelRuntime().fetchContextData(_scopeFrame.resolve(ctxRef.partnerLink));
        retVal = evalQuery(cdata.toXML(ctxRef.contexts), null, ctxRef.location, getEvaluationContext());
    } else if (from instanceof OAssign.Expression) {
        OExpression expr = ((OAssign.Expression) from).expression;
        List<Node> l = getBpelRuntime().getExpLangRuntime().evaluate(expr, getEvaluationContext());

        if (l.size() == 0) {
            String msg = __msgs.msgRValueNoNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg,
                    new Throwable("ignoreMissingFromData"));
        } else if (l.size() > 1) {
            String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
        retVal = l.get(0);
    } else if (from instanceof OAssign.Literal) {
        Element literalRoot = ((OAssign.Literal) from).getXmlLiteral().getDocumentElement();
        assert literalRoot.getLocalName().equals("literal");
        // We'd like a single text node...

        literalRoot.normalize();
        retVal = literalRoot.getFirstChild();

        // Adjust for whitespace before an element.
        if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE
                && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) {
            retVal = retVal.getNextSibling();
        }

        if (retVal == null) {
            // Special case, no children --> empty TII
            retVal = literalRoot.getOwnerDocument().createTextNode("");
        } else if (retVal.getNodeType() == Node.ELEMENT_NODE) {
            // Make sure there is no more elements.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMultipleEIIs();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }
        } else if (retVal.getNodeType() == Node.TEXT_NODE) {
            // Make sure there are no elements following this text node.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMixedContent();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }

        }

        if (retVal == null) {
            String msg = __msgs.msgLiteralMustContainTIIorEII();
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
    } else {
        String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from);
        if (__log.isErrorEnabled())
            __log.error(from + ": " + msg);
        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now verify we got something.
    if (retVal == null) {
        String msg = __msgs.msgEmptyRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);
        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now check that we got the right thing.
    switch (retVal.getNodeType()) {
    case Node.TEXT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ELEMENT_NODE:
    case Node.CDATA_SECTION_NODE:
        break;
    default:
        String msg = __msgs.msgInvalidRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);

        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

    }

    return retVal;
}

From source file:org.apache.ode.bpel.rtrep.v2.AssignHelper.java

/**
 * madars.vitolins _at gmail.com - 2009.04.17 - moved from ASSIGN here
 *///from  ww  w .  j ava2s  .  c  o m
public Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName());
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (!attr.getName().startsWith("xmlns")) {
            replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true));
            // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually
            int colonIdx = attr.getValue().indexOf(":");
            if (colonIdx > 0) {
                String prefix = attr.getValue().substring(0, colonIdx);
                String attrValNs = src.lookupPrefix(prefix);
                if (attrValNs != null)
                    replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs);
            }
        }
    }
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}

From source file:org.apache.ode.bpel.runtime.ASSIGN.java

/**
 * Get the r-value. There are several possibilities:
 * <ul>/*w w w.ja  va 2 s .c om*/
 * <li>a message is selected - an element representing the whole message is
 * returned.</li>
 * <li>a (element) message part is selected - the element is returned.
 * </li>
 * <li>a (typed) message part is select - a wrapper element is returned.
 * </li>
 * <li>an attribute is selected - an attribute node is returned. </li>
 * <li>a text node/string expression is selected - a text node is returned.
 * </li>
 * </ul>
 *
 * @param from
 *
 * @return Either {@link Element}, {@link org.w3c.dom.Text}, or
 *         {@link org.w3c.dom.Attr} node representing the r-value.
 *
 * @throws FaultException
 *             DOCUMENTME
 * @throws UnsupportedOperationException
 *             DOCUMENTME
 * @throws IllegalStateException
 *             DOCUMENTME
 */
private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException {
    if (__log.isDebugEnabled())
        __log.debug("Evaluating FROM expression \"" + from + "\".");

    Node retVal;
    if (from instanceof DirectRef) {
        OAssign.DirectRef dref = (OAssign.DirectRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(dref.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false);
        retVal = DOMUtils.findChildByName((Element) data, dref.elName);
    } else if (from instanceof OAssign.VariableRef) {
        OAssign.VariableRef varRef = (OAssign.VariableRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(varRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false);
        retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PropertyRef) {
        OAssign.PropertyRef propRef = (OAssign.PropertyRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(propRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false);
        retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PartnerLinkRef) {
        OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from;
        PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink);
        Node tempVal = pLinkRef.isMyEndpointReference
                ? getBpelRuntimeContext().fetchMyRoleEndpointReferenceData(pLink)
                : getBpelRuntimeContext().fetchPartnerRoleEndpointReferenceData(pLink);
        if (__log.isDebugEnabled())
            __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName()
                    + " has value " + DOMUtils.domToString(tempVal));
        retVal = tempVal;
    } else if (from instanceof OAssign.Expression) {
        List<Node> l;
        OExpression expr = ((OAssign.Expression) from).expression;
        try {
            l = getBpelRuntimeContext().getExpLangRuntime().evaluate(expr, getEvaluationContext());
            if (l.size() == 0 || l.get(0) == null || !(l.get(0) instanceof Element)) {
                if (__log.isTraceEnabled()) {
                    __log.trace("evalRValue: OAssign.Expression: eval reult not Element or node=null");
                }
            } else {
                Element element = (Element) l.get(0);
                for (Map.Entry<String, String> entry : DOMUtils.getMyNSContext(element).toMap().entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    if (entry.getKey() == null || entry.getKey().length() == 0) {
                        element.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns", value);
                    } else {
                        element.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + key, value);
                    }
                }
            }
        } catch (EvaluationException e) {
            String msg = __msgs.msgEvalException(from.toString(), e.getMessage());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            if (e.getCause() instanceof FaultException)
                throw (FaultException) e.getCause();
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
        if (l.size() == 0) {
            String msg = __msgs.msgRValueNoNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg,
                    new Throwable("ignoreMissingFromData"));
        } else if (l.size() > 1) {
            String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
        retVal = (Node) l.get(0);
    } else if (from instanceof OAssign.Literal) {
        String literal = ((OAssign.Literal) from).getXmlLiteral();
        Element literalRoot;
        try {
            literalRoot = DOMUtils.stringToDOM(literal);
        } catch (Exception e) {
            throw new RuntimeException("XML literal parsing failed " + literal, e);
        }
        assert literalRoot.getLocalName().equals("literal");
        // We'd like a single text node...

        literalRoot.normalize();
        retVal = literalRoot.getFirstChild();

        // Adjust for whitespace before an element.
        if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE
                && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) {
            retVal = retVal.getNextSibling();
        }

        if (retVal == null) {
            // Special case, no children --> empty TII
            retVal = literalRoot.getOwnerDocument().createTextNode("");
        } else if (retVal.getNodeType() == Node.ELEMENT_NODE) {
            // Make sure there is no more elements.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMultipleEIIs();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }
        } else if (retVal.getNodeType() == Node.TEXT_NODE) {
            // Make sure there are no elements following this text node.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMixedContent();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }

        }

        if (retVal == null) {
            String msg = __msgs.msgLiteralMustContainTIIorEII();
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
    } else {
        String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from);
        if (__log.isErrorEnabled())
            __log.error(from + ": " + msg);
        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now verify we got something.
    if (retVal == null) {
        String msg = __msgs.msgEmptyRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);
        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now check that we got the right thing.
    switch (retVal.getNodeType()) {
    case Node.TEXT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ELEMENT_NODE:
    case Node.CDATA_SECTION_NODE:
        break;
    default:
        String msg = __msgs.msgInvalidRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);

        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

    }

    return retVal;
}

From source file:org.apache.ode.bpel.runtime.AssignHelper.java

/**
 * Get the r-value. There are several possibilities:
 * <ul>//from   w w w  .j ava 2  s. c om
 * <li>a message is selected - an element representing the whole message is
 * returned.</li>
 * <li>a (element) message part is selected - the element is returned.
 * </li>
 * <li>a (typed) message part is select - a wrapper element is returned.
 * </li>
 * <li>an attribute is selected - an attribute node is returned. </li>
 * <li>a text node/string expression is selected - a text node is returned.
 * </li>
 * </ul>
 *
 * @param from
 *
 * @return Either {@link Element}, {@link org.w3c.dom.Text}, or
 *         {@link org.w3c.dom.Attr} node representing the r-value.
 *
 * @throws FaultException
 *             DOCUMENTME
 * @throws UnsupportedOperationException
 *             DOCUMENTME
 * @throws IllegalStateException
 *             DOCUMENTME
 */
private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException {
    if (__log.isDebugEnabled())
        __log.debug("Evaluating FROM expression \"" + from + "\".");

    Node retVal;
    if (from instanceof DirectRef) {
        OAssign.DirectRef dref = (OAssign.DirectRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(dref.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false);
        retVal = DOMUtils.findChildByName((Element) data, dref.elName);
    } else if (from instanceof OAssign.VariableRef) {
        OAssign.VariableRef varRef = (OAssign.VariableRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(varRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false);
        retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PropertyRef) {
        OAssign.PropertyRef propRef = (OAssign.PropertyRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(propRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false);
        retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PartnerLinkRef) {
        OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from;
        PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink);
        Node tempVal = pLinkRef.isMyEndpointReference
                ? getBpelRuntimeContext().fetchMyRoleEndpointReferenceData(pLink)
                : getBpelRuntimeContext().fetchPartnerRoleEndpointReferenceData(pLink);
        if (__log.isDebugEnabled())
            __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName()
                    + " has value " + DOMUtils.domToString(tempVal));
        retVal = tempVal;
    } else if (from instanceof OAssign.Expression) {
        List<Node> l;
        OExpression expr = ((OAssign.Expression) from).expression;
        try {
            l = getBpelRuntimeContext().getExpLangRuntime().evaluate(expr, getEvaluationContext());
        } catch (EvaluationException e) {
            String msg = __msgs.msgEvalException(from.toString(), e.getMessage());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            if (e.getCause() instanceof FaultException)
                throw (FaultException) e.getCause();
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
        if (l.size() == 0) {
            String msg = __msgs.msgRValueNoNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg,
                    new Throwable("ignoreMissingFromData"));
        } else if (l.size() > 1) {
            String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
        retVal = (Node) l.get(0);
    } else if (from instanceof OAssign.Literal) {
        String literal = ((OAssign.Literal) from).getXmlLiteral();
        Element literalRoot;
        try {
            literalRoot = DOMUtils.stringToDOM(literal);
        } catch (Exception e) {
            throw new RuntimeException("XML literal parsing failed " + literal, e);
        }
        assert literalRoot.getLocalName().equals("literal");
        // We'd like a single text node...

        literalRoot.normalize();
        retVal = literalRoot.getFirstChild();

        // Adjust for whitespace before an element.
        if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE
                && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) {
            retVal = retVal.getNextSibling();
        }

        if (retVal == null) {
            // Special case, no children --> empty TII
            retVal = literalRoot.getOwnerDocument().createTextNode("");
        } else if (retVal.getNodeType() == Node.ELEMENT_NODE) {
            // Make sure there is no more elements.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMultipleEIIs();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }
        } else if (retVal.getNodeType() == Node.TEXT_NODE) {
            // Make sure there are no elements following this text node.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMixedContent();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }

        }

        if (retVal == null) {
            String msg = __msgs.msgLiteralMustContainTIIorEII();
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
    } else {
        String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from);
        if (__log.isErrorEnabled())
            __log.error(from + ": " + msg);
        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now verify we got something.
    if (retVal == null) {
        String msg = __msgs.msgEmptyRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);
        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now check that we got the right thing.
    switch (retVal.getNodeType()) {
    case Node.TEXT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ELEMENT_NODE:
    case Node.CDATA_SECTION_NODE:
        break;
    default:
        String msg = __msgs.msgInvalidRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);

        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

    }

    return retVal;
}