List of usage examples for org.w3c.dom Element getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:org.apache.ode.axis2.soapbinding.SoapMessageConverter.java
public Fault parseSoapFault(Element odeMsgEl, SOAPEnvelope envelope, Operation operation) throws AxisFault { SOAPFault flt = envelope.getBody().getFault(); SOAPFaultDetail detail = flt.getDetail(); Fault fdef = inferFault(operation, flt); if (fdef == null) return null; Part pdef = (Part) fdef.getMessage().getParts().values().iterator().next(); Element partel = odeMsgEl.getOwnerDocument().createElementNS(null, pdef.getName()); odeMsgEl.appendChild(partel);// w w w .j av a 2 s. c om if (detail.getFirstChildWithName(pdef.getElementName()) != null) { partel.appendChild(odeMsgEl.getOwnerDocument() .importNode(OMUtils.toDOM(detail.getFirstChildWithName(pdef.getElementName())), true)); } else { partel.appendChild(odeMsgEl.getOwnerDocument().importNode(OMUtils.toDOM(detail), true)); } return fdef; }
From source file:org.apache.ode.bpel.engine.BpelRuntimeContextImpl.java
private Element mergeHeaders(MessageDAO msg) { if (msg == null) return null; // Merging header data, it's all stored in the same variable Element data = msg.getData(); if (msg.getHeader() != null) { if (data == null) { Document doc = DOMUtils.newDocument(); data = doc.createElement("message"); doc.appendChild(data);//from ww w .j a v a 2 s . c o m } NodeList headerParts = msg.getHeader().getChildNodes(); for (int m = 0; m < headerParts.getLength(); m++) { if (headerParts.item(m).getNodeType() == Node.ELEMENT_NODE) { Element headerPart = (Element) headerParts.item(m); headerPart.setAttribute("headerPart", "true"); data.appendChild(data.getOwnerDocument().importNode(headerPart, true)); } } } return data; }
From source file:org.apache.ode.bpel.extvar.jdbc.DbExternalVariable.java
private void addElement(Element parent, QName varType, Column c, Object data) { Document doc = parent.getOwnerDocument(); Element cel = doc.createElementNS(varType.getNamespaceURI(), c.name); String strdat = c.toText(data); if (strdat != null) { cel.appendChild(doc.createTextNode(strdat)); } else if (c.nullok || c.isGenerated()) { cel.setAttributeNS(XSI_NS, "xsi:nil", "true"); }//from www . j ava2 s . c o m parent.appendChild(cel); }
From source file:org.apache.ode.bpel.rtrep.v1.ASSIGN.java
/** * Get the r-value. There are several possibilities: * <ul>/*from w ww.j a v a 2 s. 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 void copy(OAssign.Copy ocopy) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Assign.copy(" + ocopy + ")"); ScopeEvent se;//from w w w .j a v a2 s .c o 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
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; }/*from w w w . j a v a2s . c om*/ 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.v1.ASSIGN.java
private Element copyInto(Element lval, Element ptr, Element src) { ptr.appendChild(ptr.getOwnerDocument().importNode(src, true)); return lval;// w ww.j a v a2 s . c o m }
From source file:org.apache.ode.bpel.rtrep.v2.ASSIGN.java
/** * Get the r-value. There are several possibilities: * <ul>/* ww w .j ava 2s .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 void copy(OAssign.Copy ocopy) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Assign.copy(" + ocopy + ")"); ScopeEvent se;//from w w w. j av a 2 s . c o m // 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.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 . ja v a 2 s . c o m*/ 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; }