jaxencontexts.java

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

JAVA
395
字号
                    try {                        return Double.valueOf(text);                    } catch (NumberFormatException e) { }                    return text;                } else {                    return variableNode;                }            }catch(FaultException e){                __log.error("bpws:getVariableValue threw FaultException", e);                throw new WrappedFaultException.JaxenUnresolvableException(e);            }        }    }    /**     * bpws:getVariableData()     */    class BpelVariableDataFunction implements Function {        public Object call(Context context, List args)                throws FunctionCallException {            if (__log.isDebugEnabled()) {                __log.debug("call(context=" + context + " args=" + args + ")");            }            String varname  = (String) args.get(0);            String partname = args.size() > 1 ? (String) args.get(1) : null;            String xpathStr = args.size() > 2 ? (String)args.get(2) : null;            OXPath10Expression.OSigGetVariableData sig = _oxpath.resolveGetVariableDataSig(varname,partname,xpathStr);            if (sig == null) {                String msg = "InternalError: Attempt to use an unknown getVariableData signature: " + args;                if (__log.isFatalEnabled())                    __log.fatal(msg);                throw new FunctionCallException(msg);            }            try {                Node ret = _xpathEvalCtx.readVariable(sig.variable, sig.part);                if (sig.location != null)                    ret = _xpathEvalCtx.evaluateQuery(ret, sig.location);                if (__log.isDebugEnabled()) {                    __log.debug("bpws:getVariableData(" + args +  ")' = " + ret);                }                return ret;            } catch (FaultException e) {                __log.error("bpws:getVariableData(" + args + ") threw FaultException", e);                throw new WrappedFaultException.JaxenFunctionException(e);            }        }    }    /**     * bpws:getVariableProperty()     */    class BpelVariablePropertyFunction implements Function {        public Object call(Context context, List args)                throws FunctionCallException {            if (args.size() != 2) {                throw new FunctionCallException("missing required arguments");            }            OScope.Variable var = _oxpath.vars.get(args.get(0));            OProcess.OProperty property = _oxpath.properties.get(args.get(1));            if (__log.isDebugEnabled()) {                __log.debug("function call:'bpws:getVariableProperty(" + var + ","                        + property + ")'");            }            try {                return _xpathEvalCtx.readMessageProperty(var, property);            } catch (FaultException e) {                __log.error("bpws:getVariableProperty(" + args + ") threw FaultException", e);                throw new WrappedFaultException.JaxenFunctionException(e);            }        }    }    class GetLinkStatusFunction implements Function {        public Object call(Context context, List args)                throws FunctionCallException {            assert args.size() == 1;            OLink olink = _oxpath.links.get(args.get(0));            try {                return _xpathEvalCtx.isLinkActive(olink) ? Boolean.TRUE : Boolean.FALSE;            } catch (FaultException e) {                __log.error("bpws:getLinkStatus(" + args + ") threw FaultException", e);                throw new WrappedFaultException.JaxenFunctionException(e);            }        }    }    class DoXslTransformFunction implements Function {        public Object call(Context context, List args) throws FunctionCallException {            assert args.size() >= 2;            assert args.size() % 2 == 0;            if (__log.isDebugEnabled()) {                __log.debug("call(context=" + context + " args=" + args + ")");            }            if(!(_oxpath instanceof OXPath10ExpressionBPEL20)) {                throw new IllegalStateException("XPath function bpws:doXslTransform not supported in " +                        "BPEL 1.1!");            }            Element varElmt;            try {                if (args.get(1) instanceof List) {                    List elmts = (List)args.get(1);                    if (elmts.size() != 1) throw new WrappedFaultException.JaxenFunctionException(                            new FaultException(_oxpath.getOwner().constants.qnXsltInvalidSource,                                    "Second parameter of the bpws:doXslTransform function MUST point to a single " +                                            "element node."));                    varElmt = (Element) elmts.get(0);                } else {                    if (args.get(1) instanceof NodeWrapper)                        varElmt = (Element) ((NodeWrapper)args.get(1)).getUnderlyingNode();                    else varElmt = (Element) args.get(1);                    //                    varElmt = (Element) args.get(1);                }            } catch (ClassCastException e) {                throw new WrappedFaultException.JaxenFunctionException(                        new FaultException(_oxpath.getOwner().constants.qnXsltInvalidSource,                                "Second parameter of the bpws:doXslTransform function MUST point to a single " +                                        "element node."));            }            URI xslUri;            try {                xslUri = new URI((String) args.get(0));            } catch (URISyntaxException use) {                // Shouldn't happen, checked at compilation time                throw new FunctionCallException("First parameter of the bpws:doXslTransform isn't a valid URI!", use);            }            OXslSheet xslSheet = _oxpath.xslSheets.get(xslUri);            // Shouldn't happen, checked at compilation time            if (xslSheet == null) throw new FunctionCallException("Couldn't find the XSL sheet " + args.get(0)                    + ", process compilation or deployment was probably incomplete!");            if (!(varElmt instanceof Element)) {                throw new WrappedFaultException.JaxenFunctionException(                        new FaultException(_oxpath.getOwner().constants.qnXsltInvalidSource,                                "Second parameter of the bpws:doXslTransform function MUST point to a single " +                                        "element node."));            }            HashMap<QName, Object> parametersMap = null;            if (args.size() > 2) {                parametersMap = new HashMap<QName, Object>();                for (int idx = 2; idx < args.size(); idx+=2) {                    QName keyQName = _oxpath.namespaceCtx.derefQName((String) args.get(idx));                    parametersMap.put(keyQName, args.get(idx + 1));                }            }            Document varDoc = DOMUtils.newDocument();            varDoc.appendChild(varDoc.importNode(varElmt, true));            DOMSource source = new DOMSource(varDoc);            // Using a StreamResult as a DOMResult doesn't behaves properly when the result            // of the transformation is just a string.            StringWriter writerResult = new StringWriter();            StreamResult result = new StreamResult(writerResult);            XslRuntimeUriResolver resolver = new XslRuntimeUriResolver(_oxpath, _xpathEvalCtx.getBaseResourceURI());            XslTransformHandler.getInstance().cacheXSLSheet(xslUri, xslSheet.sheetBody, resolver);            try {                XslTransformHandler.getInstance().transform(xslUri, source, result, parametersMap, resolver);            } catch (Exception e) {                throw new WrappedFaultException.JaxenFunctionException(                        new FaultException(_oxpath.getOwner().constants.qnSubLanguageExecutionFault,                                e.toString()));            }            writerResult.flush();            String output = writerResult.toString();            // I'm not really proud of that but hey, it does the job and I don't think there's            // any other easy way.            if (output.startsWith("<?xml")) {                try {                    return DOMUtils.stringToDOM(writerResult.toString());                } catch (SAXException e) {                    throw new FunctionCallException(e);                } catch (IOException e) {                    throw new FunctionCallException(e);                }            } else {                return output;            }        }    }}

⌨️ 快捷键说明

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