⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplemethod.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * $Id: SimpleMethod.java 6248 2005-12-06 00:08:52Z jaz $ * *  Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org * *  Permission is hereby granted, free of charge, to any person obtaining a *  copy of this software and associated documentation files (the "Software"), *  to deal in the Software without restriction, including without limitation *  the rights to use, copy, modify, merge, publish, distribute, sublicense, *  and/or sell copies of the Software, and to permit persons to whom the *  Software is furnished to do so, subject to the following conditions: * *  The above copyright notice and this permission notice shall be included *  in all copies or substantial portions of the Software. * *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *  THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.minilang;import java.net.MalformedURLException;import java.net.URL;import java.util.Iterator;import java.util.List;import java.util.Locale;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javolution.util.FastList;import javolution.util.FastMap;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.ofbiz.base.location.FlexibleLocation;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.UtilXml;import org.ofbiz.base.util.cache.UtilCache;import org.ofbiz.entity.GenericEntity;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.transaction.GenericTransactionException;import org.ofbiz.entity.transaction.TransactionUtil;import org.ofbiz.minilang.method.MethodContext;import org.ofbiz.minilang.method.MethodOperation;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.ModelService;/** * SimpleMethod Mini Language Core Object * * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>  * @version    $Rev: 6248 $ * @since      2.0 */public class SimpleMethod {        public static final String module = SimpleMethod.class.getName();    public static final String err_resource = "MiniLangErrorUiLabels";    protected static UtilCache simpleMethodsDirectCache = new UtilCache("minilang.SimpleMethodsDirect", 0, 0);    protected static UtilCache simpleMethodsResourceCache = new UtilCache("minilang.SimpleMethodsResource", 0, 0);    protected static UtilCache simpleMethodsURLCache = new UtilCache("minilang.SimpleMethodsURL", 0, 0);    // ----- Event Context Invokers -----    public static String runSimpleEvent(String xmlResource, String methodName, HttpServletRequest request, HttpServletResponse response) throws MiniLangException {        return runSimpleMethod(xmlResource, methodName, new MethodContext(request, response, null));    }    public static String runSimpleEvent(String xmlResource, String methodName, HttpServletRequest request, HttpServletResponse response, ClassLoader loader) throws MiniLangException {        return runSimpleMethod(xmlResource, methodName, new MethodContext(request, response, loader));    }    public static String runSimpleEvent(URL xmlURL, String methodName, HttpServletRequest request, HttpServletResponse response, ClassLoader loader) throws MiniLangException {        return runSimpleMethod(xmlURL, methodName, new MethodContext(request, response, loader));    }    // ----- Service Context Invokers -----    public static Map runSimpleService(String xmlResource, String methodName, DispatchContext ctx, Map context) throws MiniLangException {        MethodContext methodContext = new MethodContext(ctx, context, null);        runSimpleMethod(xmlResource, methodName, methodContext);        return methodContext.getResults();    }    public static Map runSimpleService(String xmlResource, String methodName, DispatchContext ctx, Map context, ClassLoader loader) throws MiniLangException {        MethodContext methodContext = new MethodContext(ctx, context, loader);        runSimpleMethod(xmlResource, methodName, methodContext);        return methodContext.getResults();    }    public static Map runSimpleService(URL xmlURL, String methodName, DispatchContext ctx, Map context, ClassLoader loader) throws MiniLangException {        MethodContext methodContext = new MethodContext(ctx, context, loader);        runSimpleMethod(xmlURL, methodName, methodContext);        return methodContext.getResults();    }    // ----- General Method Invokers -----    public static String runSimpleMethod(String xmlResource, String methodName, MethodContext methodContext) throws MiniLangException {        Map simpleMethods = getSimpleMethods(xmlResource, methodName, methodContext.getLoader());        SimpleMethod simpleMethod = (SimpleMethod) simpleMethods.get(methodName);        if (simpleMethod == null) {            throw new MiniLangException("Could not find SimpleMethod " + methodName + " in XML document in resource: " + xmlResource);        }        return simpleMethod.exec(methodContext);    }    public static String runSimpleMethod(URL xmlURL, String methodName, MethodContext methodContext) throws MiniLangException {        Map simpleMethods = getSimpleMethods(xmlURL, methodName);        SimpleMethod simpleMethod = (SimpleMethod) simpleMethods.get(methodName);        if (simpleMethod == null) {            throw new MiniLangException("Could not find SimpleMethod " + methodName + " in XML document from URL: " + xmlURL.toString());        }        return simpleMethod.exec(methodContext);    }    public static Map getSimpleMethods(String xmlResource, String methodName, ClassLoader loader) throws MiniLangException {        Map simpleMethods = (Map) simpleMethodsResourceCache.get(xmlResource);        if (simpleMethods == null) {            synchronized (SimpleMethod.class) {                simpleMethods = (Map) simpleMethodsResourceCache.get(xmlResource);                if (simpleMethods == null) {                    //URL xmlURL = UtilURL.fromResource(xmlResource, loader);                    URL xmlURL = null;                    try {                        xmlURL = FlexibleLocation.resolveLocation(xmlResource, loader);                    } catch (MalformedURLException e) {                        throw new MiniLangException("Could not find SimpleMethod XML document in resource: " + xmlResource + "; error was: " + e.toString(), e);                    }                    if (xmlURL == null) {                        throw new MiniLangException("Could not find SimpleMethod XML document in resource: " + xmlResource);                    }                    simpleMethods = getAllSimpleMethods(xmlURL);                    // put it in the cache                    simpleMethodsResourceCache.put(xmlResource, simpleMethods);                }            }        }        return simpleMethods;    }    public static Map getSimpleMethods(URL xmlURL, String methodName) throws MiniLangException {        Map simpleMethods = (Map) simpleMethodsURLCache.get(xmlURL);        if (simpleMethods == null) {            synchronized (SimpleMethod.class) {                simpleMethods = (Map) simpleMethodsURLCache.get(xmlURL);                if (simpleMethods == null) {                    simpleMethods = getAllSimpleMethods(xmlURL);                    // put it in the cache                    simpleMethodsURLCache.put(xmlURL, simpleMethods);                }            }        }        return simpleMethods;    }    protected static Map getAllSimpleMethods(URL xmlURL) throws MiniLangException {        Map simpleMethods = FastMap.newInstance();        // read in the file        Document document = null;        try {            document = UtilXml.readXmlDocument(xmlURL, true);        } catch (java.io.IOException e) {            throw new MiniLangException("Could not read XML file", e);        } catch (org.xml.sax.SAXException e) {            throw new MiniLangException("Could not parse XML file", e);        } catch (javax.xml.parsers.ParserConfigurationException e) {            throw new MiniLangException("XML parser not setup correctly", e);        }        if (document == null) {            throw new MiniLangException("Could not find SimpleMethod XML document: " + xmlURL.toString());        }        Element rootElement = document.getDocumentElement();        List simpleMethodElements = UtilXml.childElementList(rootElement, "simple-method");        Iterator simpleMethodIter = simpleMethodElements.iterator();        while (simpleMethodIter.hasNext()) {            Element simpleMethodElement = (Element) simpleMethodIter.next();            SimpleMethod simpleMethod = new SimpleMethod(simpleMethodElement, simpleMethods, xmlURL.toString());            simpleMethods.put(simpleMethod.getMethodName(), simpleMethod);        }        return simpleMethods;    }    public static Map getDirectSimpleMethods(String name, String content, String fromLocation) throws MiniLangException {        Map simpleMethods = (Map) simpleMethodsDirectCache.get(name);        if (simpleMethods == null) {            synchronized (SimpleMethod.class) {                simpleMethods = (Map) simpleMethodsDirectCache.get(name);                if (simpleMethods == null) {                    simpleMethods = getAllDirectSimpleMethods(name, content, fromLocation);                    // put it in the cache                    simpleMethodsDirectCache.put(name, simpleMethods);                }            }        }        return simpleMethods;    }    protected static Map getAllDirectSimpleMethods(String name, String content, String fromLocation) throws MiniLangException {        if (UtilValidate.isEmpty(fromLocation)) {            fromLocation = "<location not known>";        }                Map simpleMethods = FastMap.newInstance();        // read in the file        Document document = null;        try {            if (content != null) {

⌨️ 快捷键说明

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