assign.java

来自「bpel执行引擎用来执行bpel业务流程」· Java 代码 · 共 662 行 · 第 1/2 页

JAVA
662
字号
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements.  See the NOTICE file * distributed with this work for additional information * regarding copyright ownership.  The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License.  You may obtain a copy of the License at * *    http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied.  See the License for the * specific language governing permissions and limitations * under the License. */package org.apache.ode.bpel.runtime;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.ode.bpel.common.FaultException;import org.apache.ode.bpel.evt.PartnerLinkModificationEvent;import org.apache.ode.bpel.evt.ScopeEvent;import org.apache.ode.bpel.evt.VariableModificationEvent;import org.apache.ode.bpel.explang.EvaluationContext;import org.apache.ode.bpel.explang.EvaluationException;import org.apache.ode.bpel.o.OAssign;import org.apache.ode.bpel.o.OAssign.DirectRef;import org.apache.ode.bpel.o.OAssign.LValueExpression;import org.apache.ode.bpel.o.OAssign.PropertyRef;import org.apache.ode.bpel.o.OAssign.VariableRef;import org.apache.ode.bpel.o.OElementVarType;import org.apache.ode.bpel.o.OExpression;import org.apache.ode.bpel.o.OLink;import org.apache.ode.bpel.o.OMessageVarType;import org.apache.ode.bpel.o.OMessageVarType.Part;import org.apache.ode.bpel.o.OProcess.OProperty;import org.apache.ode.bpel.o.OScope;import org.apache.ode.bpel.o.OScope.Variable;import org.apache.ode.bpel.runtime.channels.FaultData;import org.apache.ode.utils.DOMUtils;import org.apache.ode.utils.Namespaces;import org.apache.ode.utils.msg.MessageBundle;import org.apache.ode.bpel.evar.ExternalVariableModuleException;import org.w3c.dom.Attr;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.w3c.dom.Text;import javax.xml.namespace.QName;import java.net.URI;import java.util.List;/** * Assign activity run-time template. */class ASSIGN extends ACTIVITY {    private static final long serialVersionUID = 1L;    private static final Log __log = LogFactory.getLog(ASSIGN.class);    private static final ASSIGNMessages __msgs = MessageBundle            .getMessages(ASSIGNMessages.class);    public ASSIGN(ActivityInfo self, ScopeFrame scopeFrame, LinkFrame linkFrame) {        super(self, scopeFrame, linkFrame);    }    public void run() {        OAssign oassign = getOAsssign();        FaultData faultData = null;        for (OAssign.Copy aCopy : oassign.copy) {            try {                copy(aCopy);            } catch (FaultException fault) {                faultData = createFault(fault.getQName(), aCopy, fault                        .getMessage());                break;            } catch (ExternalVariableModuleException e) {            	__log.error("Exception while initializing external variable", e);                _self.parent.failure(e.toString(), null);                return;            }        }        if (faultData != null) {            __log.error("Assignment Fault: " + faultData.getFaultName()                    + ",lineNo=" + faultData.getFaultLineNo()                    + ",faultExplanation=" + faultData.getExplanation());            _self.parent.completed(faultData, CompensationHandler.emptySet());        } else {            _self.parent.completed(null, CompensationHandler.emptySet());        }    }    protected Log log() {        return __log;    }    private OAssign getOAsssign() {        return (OAssign) _self.o;    }    private Node evalLValue(OAssign.LValue to) throws FaultException, ExternalVariableModuleException {        final BpelRuntimeContext napi = getBpelRuntimeContext();        Node lval = null;        if (!(to instanceof OAssign.PartnerLinkRef)) {            VariableInstance lvar = _scopeFrame.resolve(to.getVariable());            if (!napi.isVariableInitialized(lvar)) {                Document doc = DOMUtils.newDocument();                Node val = to.getVariable().type.newInstance(doc);                if (val.getNodeType() == Node.TEXT_NODE) {                    Element tempwrapper = doc.createElementNS(null, "temporary-simple-type-wrapper");                    doc.appendChild(tempwrapper);                    tempwrapper.appendChild(val);                    val = tempwrapper;                } else doc.appendChild(val);                // Only external variables need to be initialized, others are new and going to be overwtitten                if (lvar.declaration.extVar != null) lval = initializeVariable(lvar, val);                else lval = val;            } else                lval = fetchVariableData(lvar, true);        }        return lval;    }	/**     * Get the r-value. There are several possibilities:     * <ul>     * <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(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);            } 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;    }	private void copy(OAssign.Copy ocopy) throws FaultException, ExternalVariableModuleException {        if (__log.isDebugEnabled())            __log.debug("Assign.copy(" + ocopy + ")");        ScopeEvent se;        // 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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?