📄 modelservice.java
字号:
/* * $Id: ModelService.java 6582 2006-01-25 20:23:59Z jonesde $ * * 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.service;import java.util.*;import java.lang.reflect.Method;import java.io.Serializable;import javax.wsdl.*;import javax.wsdl.extensions.soap.SOAPBinding;import javax.wsdl.extensions.soap.SOAPBody;import javax.wsdl.extensions.soap.SOAPOperation;import javax.wsdl.extensions.soap.SOAPAddress;import javax.wsdl.factory.WSDLFactory;import javax.xml.namespace.QName;import javolution.util.FastList;import javolution.util.FastMap;import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;import com.ibm.wsdl.extensions.soap.SOAPBodyImpl;import com.ibm.wsdl.extensions.soap.SOAPOperationImpl;import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.ObjectType;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.collections.OrderedSet;import org.ofbiz.entity.GenericValue;import org.ofbiz.security.Security;import org.ofbiz.service.group.GroupModel;import org.ofbiz.service.group.GroupServiceModel;import org.ofbiz.service.group.ServiceGroupReader;import org.apache.commons.collections.set.ListOrderedSet;import org.w3c.dom.Document;/** * Generic Service Model Class * * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version $Rev: 6582 $ * @since 2.0 */public class ModelService implements Serializable { public static final String module = ModelService.class.getName(); public static final String XSD = "http://www.w3.org/2001/XMLSchema"; public static final String TNS = "http://www.ofbiz.org/service/"; public static final String OUT_PARAM = "OUT"; public static final String IN_PARAM = "IN"; public static final String RESPONSE_MESSAGE = "responseMessage"; public static final String RESPOND_SUCCESS = "success"; public static final String RESPOND_ERROR = "error"; public static final String RESPOND_FAIL = "fail"; public static final String ERROR_MESSAGE = "errorMessage"; public static final String ERROR_MESSAGE_LIST = "errorMessageList"; public static final String ERROR_MESSAGE_MAP = "errorMessageMap"; public static final String SUCCESS_MESSAGE = "successMessage"; public static final String SUCCESS_MESSAGE_LIST = "successMessageList"; public static final String resource = "ServiceErrorUiLabels"; /** The name of this service */ public String name; /** The description of this service */ public String description; /** The name of the service engine */ public String engineName; /** The namespace of this service */ public String nameSpace; /** The package name or location of this service */ public String location; /** The method or function to invoke for this service */ public String invoke; /** The default Entity to use for auto-attributes */ public String defaultEntityName; /** Does this service require authorization */ public boolean auth; /** Can this service be exported via RPC, RMI, SOAP, etc */ public boolean export; /** Enable verbose debugging when calling this service */ public boolean debug; /** Validate the context info for this service */ public boolean validate; /** Create a transaction for this service (if one is not already in place...)? */ public boolean useTransaction; /** Require a new transaction for this service */ public boolean requireNewTransaction; /** Override the default transaction timeout, only works if we start the transaction */ public int transactionTimeout; /** Sets the max number of times this service will retry when failed (persisted async only) */ public int maxRetry = -1; /** Set of services this service implements */ public Set implServices = new ListOrderedSet(); /** Set of override parameters */ public Set overrideParameters = new ListOrderedSet(); /** List of permission groups for service invocation */ public List permissionGroups = FastList.newInstance(); /** Context Information, a Map of parameters used by the service, contains ModelParam objects */ protected Map contextInfo = FastMap.newInstance(); /** Context Information, a List of parameters used by the service, contains ModelParam objects */ protected List contextParamList = FastList.newInstance(); /** Flag to say if we have pulled in our addition parameters from our implemented service(s) */ protected boolean inheritedParameters = false; public ModelService() {} public ModelService(ModelService model) { this.name = model.name; this.description = model.description; this.engineName = model.engineName; this.nameSpace = model.nameSpace; this.location = model.location; this.invoke = model.invoke; this.defaultEntityName = model.defaultEntityName; this.auth = model.auth; this.export = model.export; this.validate = model.validate; this.useTransaction = model.useTransaction || true; this.requireNewTransaction = model.requireNewTransaction || false; this.transactionTimeout = model.transactionTimeout; this.implServices = model.implServices; this.overrideParameters = model.overrideParameters; this.inheritedParameters = model.inheritedParameters(); List modelParamList = model.getModelParamList(); Iterator i = modelParamList.iterator(); while (i.hasNext()) { this.addParamClone((ModelParam) i.next()); } } public String toString() { StringBuffer buf = new StringBuffer(); buf.append(name).append("::"); buf.append(description + "::"); buf.append(engineName + "::"); buf.append(nameSpace + "::"); buf.append(location + "::"); buf.append(invoke + "::"); buf.append(defaultEntityName + "::"); buf.append(auth + "::"); buf.append(export + "::"); buf.append(validate + "::"); buf.append(useTransaction + "::"); buf.append(requireNewTransaction + "::"); buf.append(transactionTimeout + "::"); buf.append(implServices + "::"); buf.append(overrideParameters + "::"); buf.append(contextInfo + "::"); buf.append(contextParamList + "::"); buf.append(inheritedParameters + "::"); return buf.toString(); } public String debugInfo() { if (debug || Debug.verboseOn()) { return " [" + this.toString() + "]"; } return ""; } /** * Test if we have already inherited our interface parameters * @return boolean */ public boolean inheritedParameters() { return this.inheritedParameters; } /** * Gets the ModelParam by name * @param name The name of the parameter to get * @return ModelParam object with the specified name */ public ModelParam getParam(String name) { return (ModelParam) contextInfo.get(name); } /** * Adds a parameter definition to this service; puts on list in order added * then sorts by order if specified. */ public void addParam(ModelParam param) { if (param != null) { contextInfo.put(param.name, param); contextParamList.add(param); } } /* DEJ20060125 This is private but not used locally, so just commenting it out for now... may remove later private void copyParams(Collection params) { if (params != null) { Iterator i = params.iterator(); while (i.hasNext()) { ModelParam param = (ModelParam) i.next(); addParam(param); } } } */ /** * Adds a clone of a parameter definition to this service */ public void addParamClone(ModelParam param) { if (param != null) { ModelParam newParam = new ModelParam(param); addParam(newParam); } } public Set getAllParamNames() { Set nameList = new OrderedSet(); Iterator i = this.contextParamList.iterator(); while (i.hasNext()) { ModelParam p = (ModelParam) i.next(); nameList.add(p.name); } return nameList; } public Set getInParamNames() { Set nameList = new OrderedSet(); Iterator i = this.contextParamList.iterator(); while (i.hasNext()) { ModelParam p = (ModelParam) i.next(); // don't include OUT parameters in this list, only IN and INOUT if ("OUT".equals(p.mode)) continue; nameList.add(p.name); } return nameList; } public Set getOutParamNames() { Set nameList = new OrderedSet(); Iterator i = this.contextParamList.iterator(); while (i.hasNext()) { ModelParam p = (ModelParam) i.next(); // don't include IN parameters in this list, only OUT and INOUT if ("IN".equals(p.mode)) continue; nameList.add(p.name); } return nameList; } /** * Validates a Map against the IN or OUT parameter information * @param test The Map object to test * @param mode Test either mode IN or mode OUT */ public void validate(Map test, String mode, Locale locale) throws ServiceValidationException { Map requiredInfo = FastMap.newInstance(); Map optionalInfo = FastMap.newInstance(); boolean verboseOn = Debug.verboseOn(); if (verboseOn) Debug.logVerbose("[ModelService.validate] : {" + this.name + "} : Validating context - " + test, module); // do not validate results with errors if (mode.equals(OUT_PARAM) && test != null && test.containsKey(RESPONSE_MESSAGE)) { if (RESPOND_ERROR.equals(test.get(RESPONSE_MESSAGE)) || RESPOND_FAIL.equals(test.get(RESPONSE_MESSAGE))) { if (verboseOn) Debug.logVerbose("[ModelService.validate] : {" + this.name + "} : response was an error, not validating.", module); return; } } // get the info values Iterator contextParamIter = this.contextParamList.iterator(); while (contextParamIter.hasNext()) { ModelParam modelParam = (ModelParam) contextParamIter.next(); // Debug.logInfo("In ModelService.validate preparing parameter [" + modelParam.name + (modelParam.optional?"(optional):":"(required):") + modelParam.mode + "] for service [" + this.name + "]", module); if ("INOUT".equals(modelParam.mode) || mode.equals(modelParam.mode)) { if (modelParam.optional) { optionalInfo.put(modelParam.name, modelParam.type); } else { requiredInfo.put(modelParam.name, modelParam.type); } } } // get the test values Map requiredTest = FastMap.newInstance(); Map optionalTest = FastMap.newInstance(); if (test == null) test = FastMap.newInstance(); requiredTest.putAll(test); List requiredButNull = FastList.newInstance(); if (requiredTest != null) { List keyList = FastList.newInstance(); keyList.addAll(requiredTest.keySet());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -