List of usage examples for org.w3c.dom Node CDATA_SECTION_NODE
short CDATA_SECTION_NODE
To view the source code for org.w3c.dom Node CDATA_SECTION_NODE.
Click Source Link
CDATASection
. From source file:org.apache.ode.bpel.rtrep.v1.ASSIGN.java
/** * Get the r-value. There are several possibilities: * <ul>/*from www .j a 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 ? 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.v2.ASSIGN.java
/** * Get the r-value. There are several possibilities: * <ul>// w w w . ja v a 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.AssignHelper.java
/** * Get the r-value. There are several possibilities: * <ul>//from w ww .j av a 2s . 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> * (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.runtime.ASSIGN.java
/** * Get the r-value. There are several possibilities: * <ul>// w w w . 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 ? 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 ww w . j av a2 s.c o 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 ? 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; }
From source file:org.apache.ode.il.OMUtils.java
public static OMElement toOM(Element src, OMFactory omf, OMContainer parent) { OMElement omElement = parent == null ? omf.createOMElement(src.getLocalName(), null) : omf.createOMElement(src.getLocalName(), null, parent); if (src.getNamespaceURI() != null) { if (src.getPrefix() != null) omElement.setNamespace(omf.createOMNamespace(src.getNamespaceURI(), src.getPrefix())); else//from ww w . j a v a2 s.c o m omElement.declareDefaultNamespace(src.getNamespaceURI()); } if (parent == null) { NSContext nscontext = DOMUtils.getMyNSContext(src); injectNamespaces(omElement, nscontext.toMap()); } else { Map<String, String> nss = DOMUtils.getMyNamespaces(src); injectNamespaces(omElement, nss); } NamedNodeMap attrs = src.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Attr attr = (Attr) attrs.item(i); if (attr.getLocalName().equals("xmlns") || (attr.getNamespaceURI() != null && attr.getNamespaceURI().equals(DOMUtils.NS_URI_XMLNS))) continue; OMNamespace attrOmNs = null; String attrNs = attr.getNamespaceURI(); String attrPrefix = attr.getPrefix(); if (attrNs != null) attrOmNs = omElement.findNamespace(attrNs, null); if (attrOmNs == null && attrPrefix != null) attrOmNs = omElement.findNamespace(null, attrPrefix); omElement.addAttribute(attr.getLocalName(), attr.getValue(), attrOmNs); } NodeList children = src.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); switch (n.getNodeType()) { case Node.CDATA_SECTION_NODE: omElement.addChild(omf.createOMText(((CDATASection) n).getTextContent(), XMLStreamConstants.CDATA)); break; case Node.TEXT_NODE: omElement.addChild(omf.createOMText(((Text) n).getTextContent(), XMLStreamConstants.CHARACTERS)); break; case Node.ELEMENT_NODE: toOM((Element) n, omf, omElement); break; } } return omElement; }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Concat all the text and cdata node children of this elem and return the * resulting text./*from www . j a va 2s .co m*/ * * @param parentEl the element whose cdata/text node values are to be * combined. * * @return the concatanated string. */ static public String getChildCharacterData(Element parentEl) { if (parentEl == null) { return null; } Node tempNode = parentEl.getFirstChild(); StringBuffer strBuf = new StringBuffer(); CharacterData charData; while (tempNode != null) { switch (tempNode.getNodeType()) { case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: charData = (CharacterData) tempNode; strBuf.append(charData.getData()); break; } tempNode = tempNode.getNextSibling(); } return strBuf.toString(); }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Check that an element is empty, i.e., it contains no non-whitespace text or * elements as children.// w ww . j a v a2s . com * @param el the element * @return <code>true</code> if the element is empty, <code>false</code> if not. */ public static boolean isEmptyElement(Element el) { NodeList nl = el.getChildNodes(); int len = nl.getLength(); for (int i = 0; i < len; ++i) { switch (nl.item(i).getNodeType()) { case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: String s = nl.item(i).getNodeValue(); if (s != null && s.trim().length() > 0) { return false; } break; case Node.ELEMENT_NODE: return false; } } return true; }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Deep clone, but don't fry, the given node in the context of the given document. * For all intents and purposes, the clone is the exact same copy of the node, * except that it might have a different owner document. * * This method is fool-proof, unlike the <code>adoptNode</code> or <code>adoptNode</code> methods, * in that it doesn't assume that the given node has a parent or a owner document. * * @param document// www . j a v a 2s . c o m * @param sourceNode * @return a clone of node */ public static Node cloneNode(Document document, Node sourceNode) { Node clonedNode = null; // what is my name? QName sourceQName = getNodeQName(sourceNode); String nodeName = sourceQName.getLocalPart(); String namespaceURI = sourceQName.getNamespaceURI(); // if the node is unqualified, don't assume that it inherits the WS-BPEL target namespace if (Namespaces.WSBPEL2_0_FINAL_EXEC.equals(namespaceURI)) { namespaceURI = null; } switch (sourceNode.getNodeType()) { case Node.ATTRIBUTE_NODE: if (namespaceURI == null) { clonedNode = document.createAttribute(nodeName); } else { String prefix = ((Attr) sourceNode).lookupPrefix(namespaceURI); // the prefix for the XML namespace can't be looked up, hence this... if (prefix == null && namespaceURI.equals(NS_URI_XMLNS)) { prefix = "xmlns"; } // if a prefix exists, qualify the name with it if (prefix != null && !"".equals(prefix)) { nodeName = prefix + ":" + nodeName; } // create the appropriate type of attribute if (prefix != null) { clonedNode = document.createAttributeNS(namespaceURI, nodeName); } else { clonedNode = document.createAttribute(nodeName); } } break; case Node.CDATA_SECTION_NODE: clonedNode = document.createCDATASection(((CDATASection) sourceNode).getData()); break; case Node.COMMENT_NODE: clonedNode = document.createComment(((Comment) sourceNode).getData()); break; case Node.DOCUMENT_FRAGMENT_NODE: clonedNode = document.createDocumentFragment(); break; case Node.DOCUMENT_NODE: clonedNode = document; break; case Node.ELEMENT_NODE: // create the appropriate type of element if (namespaceURI == null) { clonedNode = document.createElement(nodeName); } else { String prefix = namespaceURI.equals(Namespaces.XMLNS_URI) ? "xmlns" : ((Element) sourceNode).lookupPrefix(namespaceURI); if (prefix != null && !"".equals(prefix)) { nodeName = prefix + ":" + nodeName; clonedNode = document.createElementNS(namespaceURI, nodeName); } else { clonedNode = document.createElement(nodeName); } } // attributes are not treated as child nodes, so copy them explicitly NamedNodeMap attributes = ((Element) sourceNode).getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attributeClone = (Attr) cloneNode(document, attributes.item(i)); if (attributeClone.getNamespaceURI() == null) { ((Element) clonedNode).setAttributeNode(attributeClone); } else { ((Element) clonedNode).setAttributeNodeNS(attributeClone); } } break; case Node.ENTITY_NODE: // TODO break; case Node.ENTITY_REFERENCE_NODE: clonedNode = document.createEntityReference(nodeName); // TODO break; case Node.NOTATION_NODE: // TODO break; case Node.PROCESSING_INSTRUCTION_NODE: clonedNode = document.createProcessingInstruction(((ProcessingInstruction) sourceNode).getData(), nodeName); break; case Node.TEXT_NODE: clonedNode = document.createTextNode(((Text) sourceNode).getData()); break; default: break; } // clone children of element and attribute nodes NodeList sourceChildren = sourceNode.getChildNodes(); if (sourceChildren != null) { for (int i = 0; i < sourceChildren.getLength(); i++) { Node sourceChild = sourceChildren.item(i); Node clonedChild = cloneNode(document, sourceChild); clonedNode.appendChild(clonedChild); // if the child has a textual value, parse it for any embedded prefixes if (clonedChild.getNodeType() == Node.TEXT_NODE || clonedChild.getNodeType() == Node.CDATA_SECTION_NODE) { parseEmbeddedPrefixes(sourceNode, clonedNode, clonedChild); } } } return clonedNode; }
From source file:org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory.java
/** * Returns the text of the element//www. j av a 2 s .c o m */ public static String getElementText(Element element) { StringBuffer buffer = new StringBuffer(); NodeList nodeList = element.getChildNodes(); for (int i = 0, size = nodeList.getLength(); i < size; i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { buffer.append(node.getNodeValue()); } } return buffer.toString(); }