Example usage for org.w3c.dom Node getParentNode

List of usage examples for org.w3c.dom Node getParentNode

Introduction

In this page you can find the example usage for org.w3c.dom Node getParentNode.

Prototype

public Node getParentNode();

Source Link

Document

The parent of this node.

Usage

From source file:org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBindingParser.java

void parseElement(JAXWSBinding jaxwsBinding, Element element) {
    Node child = element.getFirstChild();
    if (child == null) {
        // global binding
        if (isAsyncElement(element)) {
            jaxwsBinding.setEnableAsyncMapping(getNodeValue(element));
        }/*from w ww.  j  a v  a 2 s.  c o m*/
        if (isMIMEElement(element)) {
            jaxwsBinding.setEnableMime(getNodeValue(element));
        }
        if (isPackageElement(element)) {
            jaxwsBinding.setPackage(getPackageName(element));
        }

        if (isWrapperStyle(element)) {
            jaxwsBinding.setEnableWrapperStyle(getNodeValue(element));
        }
    } else {
        // other binding
        while (child != null) {
            if (isAsyncElement(child)) {
                jaxwsBinding.setEnableAsyncMapping(getNodeValue(child));
            } else if (isMIMEElement(child)) {
                jaxwsBinding.setEnableMime(getNodeValue(child));
            } else if (isWrapperStyle(child)) {
                jaxwsBinding.setEnableWrapperStyle(getNodeValue(child));
            } else if (isPackageElement(child)) {
                jaxwsBinding.setPackage(getPackageName(child));
                Node docChild = DOMUtils.getChild(child, Element.ELEMENT_NODE);
                if (docChild != null && this.isJAXWSClassDoc(docChild)) {
                    jaxwsBinding.setPackageJavaDoc(StringEscapeUtils.escapeHtml(DOMUtils.getContent(docChild)));
                }
            } else if (isJAXWSMethodElement(child)) {
                jaxwsBinding.setMethodName(getMethodName(child));
                Node docChild = DOMUtils.getChild(child, Element.ELEMENT_NODE);

                if (docChild != null && this.isJAXWSClassDoc(docChild)) {
                    jaxwsBinding.setMethodJavaDoc(StringEscapeUtils.escapeHtml(DOMUtils.getContent(docChild)));
                }
            } else if (isJAXWSParameterElement(child)) {
                Element childElement = (Element) child;
                String partPath = "//" + childElement.getAttribute("part");
                Node node = queryXPathNode(element.getOwnerDocument().getDocumentElement(), partPath);
                String messageName = "";
                String partName = "";
                if (node != null) {
                    partName = ((Element) node).getAttribute("name");
                    Node messageNode = node.getParentNode();
                    if (messageNode != null) {
                        Element messageEle = (Element) messageNode;
                        messageName = messageEle.getAttribute("name");
                    }
                }

                String name = childElement.getAttribute("name");
                String elementNameString = childElement.getAttribute("childElementName");
                QName elementName = null;
                if (!StringUtils.isEmpty(elementNameString)) {
                    String ns = "";
                    if (elementNameString.indexOf(':') != -1) {
                        ns = elementNameString.substring(0, elementNameString.indexOf(':'));
                        ns = childElement.lookupNamespaceURI(ns);
                        elementNameString = elementNameString.substring(elementNameString.indexOf(':') + 1);
                    }
                    elementName = new QName(ns, elementNameString);
                }
                JAXWSParameter jpara = new JAXWSParameter(messageName, partName, elementName, name);
                jaxwsBinding.addJaxwsPara(jpara);
            } else if (isJAXWSClass(child)) {
                Element childElement = (Element) child;
                String clzName = childElement.getAttribute("name");
                String javadoc = "";
                Node docChild = DOMUtils.getChild(child, Element.ELEMENT_NODE);

                if (docChild != null && this.isJAXWSClassDoc(docChild)) {
                    javadoc = StringEscapeUtils.escapeHtml(DOMUtils.getContent(docChild));
                }

                JAXWSClass jaxwsClass = new JAXWSClass(clzName, javadoc);
                jaxwsBinding.setJaxwsClass(jaxwsClass);
            }
            child = child.getNextSibling();
        }
    }

}

From source file:org.apache.geode.management.internal.configuration.utils.XmlUtils.java

/*****
 * Deletes all the node from the document which match the definition provided by xmlEntity
 * /*from   w ww . j  a v a2  s . com*/
 * @param doc
 * @param xmlEntity
 * @throws Exception
 */
public static void deleteNode(Document doc, XmlEntity xmlEntity) throws Exception {
    NodeList nodes = getNodes(doc, xmlEntity);
    if (nodes != null) {
        int length = nodes.getLength();

        for (int i = 0; i < length; i++) {
            Node node = nodes.item(i);
            node.getParentNode().removeChild(node);
        }
    }
}

From source file:org.apache.nutch.parse.html.DOMContentUtils.java

private boolean getTextHelper(StringBuffer sb, Node node, boolean abortOnNestedAnchors, int anchorDepth) {
    boolean abort = false;
    NodeWalker walker = new NodeWalker(node);

    while (walker.hasNext()) {

        Node currentNode = walker.nextNode();
        String nodeName = currentNode.getNodeName();
        short nodeType = currentNode.getNodeType();

        if ("script".equalsIgnoreCase(nodeName)) {
            walker.skipChildren();// w w  w. j  a v a 2 s  .  c om
        }
        if ("style".equalsIgnoreCase(nodeName)) {
            walker.skipChildren();
        }
        if (abortOnNestedAnchors && "a".equalsIgnoreCase(nodeName)) {
            anchorDepth++;
            if (anchorDepth > 1) {
                abort = true;
                break;
            }
        }
        if (nodeType == Node.COMMENT_NODE) {
            walker.skipChildren();
        }
        if (nodeType == Node.TEXT_NODE) {
            // cleanup and trim the value
            String text = currentNode.getNodeValue();
            String element = currentNode.getParentNode().getNodeName();
            text = text.replaceAll("\\s+", " ");
            text = text.trim();
            if (text.length() > 0) {
                if (sb.length() > 0)
                    sb.append(' ');
                if (StringUtils.isNotBlank(element))
                    //custom code to retain the html tag surrounding this text element 
                    sb.append("<" + element + ">").append(text).append("</" + element + ">");
                else
                    sb.append(text);
            }
        }
    }

    return abort;
}

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

private void copy(OAssign.Copy ocopy) throws FaultException, ExternalVariableModuleException {

    if (__log.isDebugEnabled())
        __log.debug("Assign.copy(" + ocopy + ")");

    ScopeEvent se;/*from w  ww  .  ja  va 2  s .co m*/

    // Check for message to message - copy, we can do this efficiently in
    // the database.
    if ((ocopy.to instanceof VariableRef && ((VariableRef) ocopy.to).isMessageRef())
            || (ocopy.from instanceof VariableRef && ((VariableRef) ocopy.from).isMessageRef())) {

        if ((ocopy.to instanceof VariableRef && ((VariableRef) ocopy.to).isMessageRef())
                && ocopy.from instanceof VariableRef && ((VariableRef) ocopy.from).isMessageRef()) {

            final VariableInstance lval = _scopeFrame.resolve(ocopy.to.getVariable());
            final VariableInstance rval = _scopeFrame.resolve(((VariableRef) ocopy.from).getVariable());
            Element lvalue = (Element) fetchVariableData(rval, false);
            initializeVariable(lval, lvalue);
            se = new VariableModificationEvent(lval.declaration.name);
            ((VariableModificationEvent) se).setNewValue(lvalue);
        } else {
            // This really should have been caught by the compiler.
            __log.fatal("Message/Non-Message Assignment, should be caught by compiler:" + ocopy);
            throw new FaultException(ocopy.getOwner().constants.qnSelectionFailure,
                    "Message/Non-Message Assignment:  " + ocopy);
        }
    } else {
        // Conventional Assignment logic.
        Node rvalue = evalRValue(ocopy.from);
        Node lvalue = evalLValue(ocopy.to);
        if (__log.isDebugEnabled()) {
            __log.debug("lvalue after eval " + lvalue);
            if (lvalue != null)
                __log.debug("content " + DOMUtils.domToString(lvalue));
        }

        // Get a pointer within the lvalue.
        Node lvaluePtr = lvalue;
        boolean headerAssign = false;
        if (ocopy.to instanceof OAssign.DirectRef) {
            DirectRef dref = ((DirectRef) ocopy.to);
            Element el = DOMUtils.findChildByName((Element) lvalue, dref.elName);
            if (el == null) {
                el = (Element) ((Element) lvalue).appendChild(lvalue.getOwnerDocument()
                        .createElementNS(dref.elName.getNamespaceURI(), dref.elName.getLocalPart()));
            }
            lvaluePtr = el;
        } else if (ocopy.to instanceof OAssign.VariableRef) {
            VariableRef varRef = ((VariableRef) ocopy.to);
            if (varRef.headerPart != null)
                headerAssign = true;
            lvaluePtr = evalQuery(lvalue, varRef.part != null ? varRef.part : varRef.headerPart,
                    varRef.location, new EvaluationContextProxy(varRef.getVariable(), lvalue));
        } else if (ocopy.to instanceof OAssign.PropertyRef) {
            PropertyRef propRef = ((PropertyRef) ocopy.to);
            lvaluePtr = evalQuery(lvalue, propRef.propertyAlias.part, propRef.propertyAlias.location,
                    new EvaluationContextProxy(propRef.getVariable(), lvalue));
        } else if (ocopy.to instanceof OAssign.LValueExpression) {
            LValueExpression lexpr = (LValueExpression) ocopy.to;
            lvaluePtr = evalQuery(lvalue, null, lexpr.expression,
                    new EvaluationContextProxy(lexpr.getVariable(), lvalue));
            if (__log.isDebugEnabled())
                __log.debug("lvaluePtr expr res " + lvaluePtr);
        }

        // For partner link assignmenent, the whole content is assigned.
        if (ocopy.to instanceof OAssign.PartnerLinkRef) {
            OAssign.PartnerLinkRef pLinkRef = ((OAssign.PartnerLinkRef) ocopy.to);
            PartnerLinkInstance plval = _scopeFrame.resolve(pLinkRef.partnerLink);
            replaceEndpointRefence(plval, rvalue);
            se = new PartnerLinkModificationEvent(((OAssign.PartnerLinkRef) ocopy.to).partnerLink.getName());
        } else {
            // Sneakily converting the EPR if it's not the format expected by the lvalue
            if (ocopy.from instanceof OAssign.PartnerLinkRef) {
                rvalue = getBpelRuntime().convertEndpointReference((Element) rvalue, lvaluePtr);
                if (rvalue.getNodeType() == Node.DOCUMENT_NODE)
                    rvalue = ((Document) rvalue).getDocumentElement();
            }

            if (headerAssign && lvaluePtr.getParentNode().getNodeName().equals("message")
                    && rvalue.getNodeType() == Node.ELEMENT_NODE) {
                lvalue = copyInto((Element) lvalue, (Element) lvaluePtr, (Element) rvalue);
            } else if (rvalue.getNodeType() == Node.ELEMENT_NODE
                    && lvaluePtr.getNodeType() == Node.ELEMENT_NODE) {
                lvalue = replaceElement((Element) lvalue, (Element) lvaluePtr, (Element) rvalue,
                        ocopy.keepSrcElementName);
            } else {
                lvalue = replaceContent(lvalue, lvaluePtr, rvalue.getTextContent());
            }
            final VariableInstance lval = _scopeFrame.resolve(ocopy.to.getVariable());
            if (__log.isDebugEnabled())
                __log.debug("ASSIGN Writing variable '" + lval.declaration.name + "' value '"
                        + DOMUtils.domToString(lvalue) + "'");
            commitChanges(lval, lvalue);
            se = new VariableModificationEvent(lval.declaration.name);
            ((VariableModificationEvent) se).setNewValue(lvalue);
        }
    }

    if (ocopy.debugInfo != null)
        se.setLineNo(ocopy.debugInfo.startLine);
    sendEvent(se);
}

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

/**
 * isInsert flag desginates this as an 'element' type insertion, which
 * requires insert the actual element value, rather than it's children
 *
 * @return//from   w  ww  . ja va2 s .co m
 * @throws FaultException
 */
private Node replaceContent(Node lvalue, Node lvaluePtr, String rvalue) throws FaultException {
    Document d = lvaluePtr.getOwnerDocument();

    if (__log.isDebugEnabled()) {
        __log.debug("lvaluePtr type " + lvaluePtr.getNodeType());
        __log.debug("lvaluePtr " + DOMUtils.domToString(lvaluePtr));
        __log.debug("lvalue " + lvalue);
        __log.debug("rvalue " + rvalue);
    }

    switch (lvaluePtr.getNodeType()) {
    case Node.ELEMENT_NODE:

        // Remove all the children.
        while (lvaluePtr.hasChildNodes())
            lvaluePtr.removeChild(lvaluePtr.getFirstChild());

        // Append a new text node.
        lvaluePtr.appendChild(d.createTextNode(rvalue));

        // If lvalue is a text, removing all lvaluePtr children had just removed it
        // so we need to rebuild it as a child of lvaluePtr
        if (lvalue instanceof Text)
            lvalue = lvaluePtr.getFirstChild();
        break;

    case Node.TEXT_NODE:

        Node newval = d.createTextNode(rvalue);
        // Replace ourselves .
        lvaluePtr.getParentNode().replaceChild(newval, lvaluePtr);

        // A little kludge, let our caller know that the root element has changed.
        // (used for assignment to a simple typed variable)
        if (lvalue.getNodeType() == Node.ELEMENT_NODE) {
            // No children, adding an empty text children to point to
            if (lvalue.getFirstChild() == null) {
                Text txt = lvalue.getOwnerDocument().createTextNode("");
                lvalue.appendChild(txt);
            }
            if (lvalue.getFirstChild().getNodeType() == Node.TEXT_NODE)
                lvalue = lvalue.getFirstChild();
        }
        if (lvalue.getNodeType() == Node.TEXT_NODE
                && ((Text) lvalue).getWholeText().equals(((Text) lvaluePtr).getWholeText()))
            lvalue = lvaluePtr = newval;
        break;

    case Node.ATTRIBUTE_NODE:

        ((Attr) lvaluePtr).setValue(rvalue);
        break;

    default:
        // This could occur if the expression language selects something
        // like
        // a PI or a CDATA.
        String msg = __msgs.msgInvalidLValue();
        if (__log.isDebugEnabled())
            __log.debug(lvaluePtr + ": " + msg);
        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
    }

    return lvalue;
}

From source file:org.apache.ode.bpel.rtrep.v1.xpath10.jaxp.JaxpVariableResolver.java

private Object getSimpleContent(Node simpleNode, QName type) {
    String text = simpleNode.getTextContent();
    try {/*from  w  ww .  j a v a  2 s .  c om*/
        return XSTypes.toJavaObject(type, text);
    } catch (Exception e) {
    }
    // Elegant way failed, trying brute force
    try {
        return Integer.valueOf(text);
    } catch (NumberFormatException e) {
    }
    try {
        return Double.valueOf(text);
    } catch (NumberFormatException e) {
    }
    // Remember: always a node set
    if (simpleNode.getParentNode() != null)
        return simpleNode.getParentNode().getChildNodes();
    else
        return text;
}

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

private Object getSimpleContent(Node simpleNode, QName type) {
    Document doc = (simpleNode instanceof Document) ? ((Document) simpleNode) : simpleNode.getOwnerDocument();
    String text = simpleNode.getTextContent();
    try {//from  www. j av  a 2s.  com
        Object jobj = XSTypes.toJavaObject(type, text);
        if (jobj instanceof Calendar) {
            // Saxon 9.x prefers Dates over Calendars.
            return ((Calendar) jobj).getTime();
        } else if (jobj instanceof String) {
            // Saxon 9.x has a bug for which this is a workaround.
            return doc.createTextNode(jobj.toString());
        }
        return jobj;
    } catch (Exception e) {
        // Elegant way failed, trying brute force 
        try {
            return Integer.valueOf(text);
        } catch (NumberFormatException nfe) {
        }
        try {
            return Double.valueOf(text);
        } catch (NumberFormatException nfe) {
        }

        // Remember: always a node set
        if (simpleNode.getParentNode() != null)
            return simpleNode.getParentNode().getChildNodes();
        else {
            return doc.createTextNode(text);
        }
    }
}

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

private void copy(OAssign.Copy ocopy) throws FaultException, ExternalVariableModuleException {

    if (__log.isDebugEnabled())
        __log.debug("Assign.copy(" + ocopy + ")");

    ScopeEvent se;/*from   w w  w.  ja  v  a  2 s .  com*/

    // Check for message to message - copy, we can do this efficiently in
    // the database.
    if ((ocopy.to instanceof OAssign.VariableRef && ((OAssign.VariableRef) ocopy.to).isMessageRef())
            || (ocopy.from instanceof OAssign.VariableRef
                    && ((OAssign.VariableRef) ocopy.from).isMessageRef())) {

        if ((ocopy.to instanceof OAssign.VariableRef && ((OAssign.VariableRef) ocopy.to).isMessageRef())
                && ocopy.from instanceof OAssign.VariableRef
                && ((OAssign.VariableRef) ocopy.from).isMessageRef()) {

            final VariableInstance lval = _scopeFrame.resolve(ocopy.to.getVariable());
            final VariableInstance rval = _scopeFrame.resolve(((OAssign.VariableRef) ocopy.from).getVariable());
            Element lvalue = (Element) fetchVariableData(rval, false);
            initializeVariable(lval, lvalue);
            se = new VariableModificationEvent(lval.declaration.name);
            ((VariableModificationEvent) se).setNewValue(lvalue);
        } else {
            // This really should have been caught by the compiler.
            __log.fatal("Message/Non-Message Assignment, should be caught by compiler:" + ocopy);
            throw new FaultException(ocopy.getOwner().constants.qnSelectionFailure,
                    "Message/Non-Message Assignment:  " + ocopy);
        }
    } else {
        // Conventional Assignment logic.
        Node rvalue = evalRValue(ocopy.from);
        Node lvalue = evalLValue(ocopy.to);
        if (__log.isDebugEnabled()) {
            __log.debug("lvalue after eval " + lvalue);
            if (lvalue != null)
                __log.debug("content " + DOMUtils.domToString(lvalue));
        }

        // Get a pointer within the lvalue.
        Node lvaluePtr = lvalue;
        boolean headerAssign = false;
        if (ocopy.to instanceof OAssign.DirectRef) {
            OAssign.DirectRef dref = ((OAssign.DirectRef) ocopy.to);
            Element el = DOMUtils.findChildByName((Element) lvalue, dref.elName);
            if (el == null) {
                el = (Element) ((Element) lvalue).appendChild(lvalue.getOwnerDocument()
                        .createElementNS(dref.elName.getNamespaceURI(), dref.elName.getLocalPart()));
            }
            lvaluePtr = el;
        } else if (ocopy.to instanceof OAssign.VariableRef) {
            OAssign.VariableRef varRef = ((OAssign.VariableRef) ocopy.to);
            if (varRef.headerPart != null)
                headerAssign = true;
            lvaluePtr = evalQuery(lvalue, varRef.part != null ? varRef.part : varRef.headerPart,
                    varRef.location, new EvaluationContextProxy(varRef.getVariable(), lvalue));
        } else if (ocopy.to instanceof OAssign.PropertyRef) {
            OAssign.PropertyRef propRef = ((OAssign.PropertyRef) ocopy.to);
            lvaluePtr = evalQuery(lvalue, propRef.propertyAlias.part, propRef.propertyAlias.location,
                    new EvaluationContextProxy(propRef.getVariable(), lvalue));
        } else if (ocopy.to instanceof OAssign.LValueExpression) {
            OAssign.LValueExpression lexpr = (OAssign.LValueExpression) ocopy.to;
            lexpr.setInsertMissingToData(ocopy.insertMissingToData);
            lvaluePtr = evalQuery(lvalue, null, lexpr.expression,
                    new EvaluationContextProxy(lexpr.getVariable(), lvalue));
            if (__log.isDebugEnabled())
                __log.debug("lvaluePtr expr res " + lvaluePtr);
        }

        // For partner link assignmenent, the whole content is assigned.
        if (ocopy.to instanceof OAssign.PartnerLinkRef) {
            OAssign.PartnerLinkRef pLinkRef = ((OAssign.PartnerLinkRef) ocopy.to);
            PartnerLinkInstance plval = _scopeFrame.resolve(pLinkRef.partnerLink);
            replaceEndpointRefence(plval, rvalue);
            se = new PartnerLinkModificationEvent(((OAssign.PartnerLinkRef) ocopy.to).partnerLink.getName());
        } else if (ocopy.to.getVariable().type instanceof OPropertyVarType) {
            // For poperty assignment, the property, the variable that points to it and the correlation set
            // all have the same name
            CorrelationSetInstance csetInstance = _scopeFrame.resolve(ocopy.to.getVariable().name);
            CorrelationKey ckey = new CorrelationKey(csetInstance.declaration.getId(),
                    new String[] { rvalue.getTextContent() });
            if (__log.isDebugEnabled())
                __log.debug("Writing correlation " + csetInstance.getName() + " using value "
                        + rvalue.getTextContent());
            getBpelRuntime().writeCorrelation(csetInstance, ckey);
            se = new CorrelationSetWriteEvent(csetInstance.declaration.name, ckey);
        } else {
            // Sneakily converting the EPR if it's not the format expected by the lvalue
            if (ocopy.from instanceof OAssign.PartnerLinkRef) {
                rvalue = getBpelRuntime().convertEndpointReference((Element) rvalue, lvaluePtr);
                if (rvalue.getNodeType() == Node.DOCUMENT_NODE)
                    rvalue = ((Document) rvalue).getDocumentElement();
            }

            if (headerAssign && lvaluePtr.getParentNode().getNodeName().equals("message")
                    && rvalue.getNodeType() == Node.ELEMENT_NODE) {
                lvalue = copyInto((Element) lvalue, (Element) lvaluePtr, (Element) rvalue);
            } else if (rvalue.getNodeType() == Node.ELEMENT_NODE
                    && lvaluePtr.getNodeType() == Node.ELEMENT_NODE) {
                lvalue = replaceElement((Element) lvalue, (Element) lvaluePtr, (Element) rvalue,
                        ocopy.keepSrcElementName);
            } else {
                lvalue = replaceContent(lvalue, lvaluePtr, rvalue.getTextContent());
            }
            final VariableInstance lval = _scopeFrame.resolve(ocopy.to.getVariable());
            if (__log.isDebugEnabled())
                __log.debug("ASSIGN Writing variable '" + lval.declaration.name + "' value '"
                        + DOMUtils.domToString(lvalue) + "'");
            commitChanges(lval, lvalue);
            se = new VariableModificationEvent(lval.declaration.name);
            ((VariableModificationEvent) se).setNewValue(lvalue);
        }
    }

    if (ocopy.debugInfo != null)
        se.setLineNo(ocopy.debugInfo.startLine);
    sendEvent(se);
}

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

/**
 * isInsert flag desginates this as an 'element' type insertion, which
 * requires insert the actual element value, rather than it's children
 * (madars.vitolins _at gmail.com - 2009.04.17 - moved from ASSIGN here)
 * @return// w w  w.j  a v  a 2 s  . com
 * @throws FaultException
 */
public Node replaceContent(Node lvalue, Node lvaluePtr, String rvalue) throws FaultException {
    Document d = lvaluePtr.getOwnerDocument();

    if (__log.isDebugEnabled()) {
        __log.debug("lvaluePtr type " + lvaluePtr.getNodeType());
        __log.debug("lvaluePtr " + DOMUtils.domToString(lvaluePtr));
        __log.debug("lvalue " + lvalue);
        __log.debug("rvalue " + rvalue);
    }

    switch (lvaluePtr.getNodeType()) {
    case Node.ELEMENT_NODE:

        // Remove all the children.
        while (lvaluePtr.hasChildNodes())
            lvaluePtr.removeChild(lvaluePtr.getFirstChild());

        // Append a new text node.
        lvaluePtr.appendChild(d.createTextNode(rvalue));

        // If lvalue is a text, removing all lvaluePtr children had just removed it
        // so we need to rebuild it as a child of lvaluePtr
        if (lvalue instanceof Text)
            lvalue = lvaluePtr.getFirstChild();
        break;

    case Node.TEXT_NODE:

        Node newval = d.createTextNode(rvalue);
        // Replace ourselves .
        lvaluePtr.getParentNode().replaceChild(newval, lvaluePtr);

        // A little kludge, let our caller know that the root element has changed.
        // (used for assignment to a simple typed variable)
        if (lvalue.getNodeType() == Node.ELEMENT_NODE) {
            // No children, adding an empty text children to point to
            if (lvalue.getFirstChild() == null) {
                Text txt = lvalue.getOwnerDocument().createTextNode("");
                lvalue.appendChild(txt);
            }
            if (lvalue.getFirstChild().getNodeType() == Node.TEXT_NODE)
                lvalue = lvalue.getFirstChild();
        }
        if (lvalue.getNodeType() == Node.TEXT_NODE
                && ((Text) lvalue).getWholeText().equals(((Text) lvaluePtr).getWholeText()))
            lvalue = lvaluePtr = newval;
        break;

    case Node.ATTRIBUTE_NODE:

        ((Attr) lvaluePtr).setValue(rvalue);
        break;

    default:
        // This could occur if the expression language selects something
        // like
        // a PI or a CDATA.
        String msg = __msgs.msgInvalidLValue();
        if (__log.isDebugEnabled())
            __log.debug(lvaluePtr + ": " + msg);
        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
    }

    return lvalue;
}

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

private void copy(OAssign.Copy ocopy) throws FaultException, ExternalVariableModuleException {

    if (__log.isDebugEnabled())
        __log.debug("Assign.copy(" + ocopy + ")");

    ScopeEvent se;//from   w  ww.  j a  v  a 2s .co m

    // Check for message to message - copy, we can do this efficiently in
    // the database.
    if ((ocopy.to instanceof VariableRef && ((VariableRef) ocopy.to).isMessageRef())
            || (ocopy.from instanceof VariableRef && ((VariableRef) ocopy.from).isMessageRef())) {

        if ((ocopy.to instanceof VariableRef && ((VariableRef) ocopy.to).isMessageRef())
                && ocopy.from instanceof VariableRef && ((VariableRef) ocopy.from).isMessageRef()) {

            final VariableInstance lval = _scopeFrame.resolve(ocopy.to.getVariable());
            final VariableInstance rval = _scopeFrame.resolve(((VariableRef) ocopy.from).getVariable());
            Element lvalue = (Element) fetchVariableData(rval, false);
            initializeVariable(lval, lvalue);
            se = new VariableModificationEvent(lval.declaration.name);
            ((VariableModificationEvent) se).setNewValue(lvalue);
        } else {
            // This really should have been caught by the compiler.
            __log.fatal("Message/Non-Message Assignment, should be caught by compiler:" + ocopy);
            throw new FaultException(ocopy.getOwner().constants.qnSelectionFailure,
                    "Message/Non-Message Assignment:  " + ocopy);
        }
    } else {
        // Conventional Assignment logic.
        Node rvalue = evalRValue(ocopy.from);
        Node lvalue = evalLValue(ocopy.to);
        if (__log.isDebugEnabled()) {
            __log.debug("lvalue after eval " + lvalue);
            if (lvalue != null)
                __log.debug("content " + DOMUtils.domToString(lvalue));
        }

        // Get a pointer within the lvalue.
        Node lvaluePtr = lvalue;
        boolean headerAssign = false;
        if (ocopy.to instanceof OAssign.DirectRef) {
            DirectRef dref = ((DirectRef) ocopy.to);
            Element el = DOMUtils.findChildByName((Element) lvalue, dref.elName);
            if (el == null) {
                el = (Element) ((Element) lvalue).appendChild(lvalue.getOwnerDocument()
                        .createElementNS(dref.elName.getNamespaceURI(), dref.elName.getLocalPart()));
            }
            lvaluePtr = el;
        } else if (ocopy.to instanceof OAssign.VariableRef) {
            VariableRef varRef = ((VariableRef) ocopy.to);
            if (varRef.headerPart != null)
                headerAssign = true;
            lvaluePtr = evalQuery(lvalue, varRef.part != null ? varRef.part : varRef.headerPart,
                    varRef.location, new EvaluationContextProxy(varRef.getVariable(), lvalue));
        } else if (ocopy.to instanceof OAssign.PropertyRef) {
            PropertyRef propRef = ((PropertyRef) ocopy.to);
            lvaluePtr = evalQuery(lvalue, propRef.propertyAlias.part, propRef.propertyAlias.location,
                    new EvaluationContextProxy(propRef.getVariable(), lvalue));
        } else if (ocopy.to instanceof OAssign.LValueExpression) {
            LValueExpression lexpr = (LValueExpression) ocopy.to;
            lexpr.setInsertMissingToData(ocopy.insertMissingToData);
            lvaluePtr = evalQuery(lvalue, null, lexpr.expression,
                    new EvaluationContextProxy(lexpr.getVariable(), lvalue));
            if (__log.isDebugEnabled())
                __log.debug("lvaluePtr expr res " + lvaluePtr);
        }

        // For partner link assignmenent, the whole content is assigned.
        if (ocopy.to instanceof OAssign.PartnerLinkRef) {
            OAssign.PartnerLinkRef pLinkRef = ((OAssign.PartnerLinkRef) ocopy.to);
            PartnerLinkInstance plval = _scopeFrame.resolve(pLinkRef.partnerLink);
            replaceEndpointRefence(plval, rvalue);
            se = new PartnerLinkModificationEvent(((OAssign.PartnerLinkRef) ocopy.to).partnerLink.getName());
        } else {
            // Sneakily converting the EPR if it's not the format expected by the lvalue
            if (ocopy.from instanceof OAssign.PartnerLinkRef) {
                rvalue = getBpelRuntimeContext().convertEndpointReference((Element) rvalue, lvaluePtr);
                if (rvalue.getNodeType() == Node.DOCUMENT_NODE)
                    rvalue = ((Document) rvalue).getDocumentElement();
            }

            Node parentNode = lvaluePtr.getParentNode();
            if (headerAssign && parentNode != null && "message".equals(parentNode.getNodeName())
                    && rvalue.getNodeType() == Node.ELEMENT_NODE) {
                lvalue = copyInto((Element) lvalue, (Element) lvaluePtr, (Element) rvalue);
            } else if (rvalue.getNodeType() == Node.ELEMENT_NODE
                    && lvaluePtr.getNodeType() == Node.ELEMENT_NODE) {
                lvalue = replaceElement((Element) lvalue, (Element) lvaluePtr, (Element) rvalue,
                        ocopy.keepSrcElementName);
            } else {
                lvalue = replaceContent(lvalue, lvaluePtr, rvalue.getTextContent());
            }
            final VariableInstance lval = _scopeFrame.resolve(ocopy.to.getVariable());
            if (__log.isDebugEnabled())
                __log.debug("ASSIGN Writing variable '" + lval.declaration.name + "' value '"
                        + DOMUtils.domToString(lvalue) + "'");
            commitChanges(lval, lvalue);
            se = new VariableModificationEvent(lval.declaration.name);
            ((VariableModificationEvent) se).setNewValue(lvalue);
        }
    }

    if (ocopy.debugInfo != null)
        se.setLineNo(ocopy.debugInfo.startLine);
    sendEvent(se);
}