📄 modelservice.java
字号:
Object value = source.get(key); try { // no need to fail on type conversion; the validator will catch this value = ObjectType.simpleTypeConvert(value, param.type, null, locale, false); } catch (GeneralException e) { String errMsg = "Type conversion of field [" + key + "] to type [" + param.type + "] failed for value \"" + value + "\": " + e.toString(); Debug.logWarning("[ModelService.makeValid] : " + errMsg, module); if (errorMessages != null) { errorMessages.add(errMsg); } } target.put(key, value); } } } } } return target; } private Map makePrefixMap(Map source, ModelParam param) { Map paramMap = new HashMap(); Set sourceSet = source.keySet(); Iterator i = sourceSet.iterator(); while (i.hasNext()) { String key = (String) i.next(); if (key.startsWith(param.stringMapPrefix)) { paramMap.put(key, source.get(key)); } } return paramMap; } private List makeSuffixList(Map source, ModelParam param) { List paramList = FastList.newInstance(); Set sourceSet = source.keySet(); Iterator i = sourceSet.iterator(); while (i.hasNext()) { String key = (String) i.next(); if (key.endsWith(param.stringListSuffix)) { paramList.add(source.get(key)); } } return paramList; } public boolean containsPermissions() { if (this.permissionGroups != null && this.permissionGroups.size() > 0) { return true; } return false; } /** * Evaluates permissions for a service. * @param security The security object to use for permission checking * @param userLogin The logged in user's value object * @return true if all permissions evaluate true. */ public boolean evalPermissions(Security security, GenericValue userLogin) { if (this.containsPermissions()) { Iterator i = this.permissionGroups.iterator(); while (i.hasNext()) { ModelPermGroup group = (ModelPermGroup) i.next(); if (!group.evalPermissions(security, userLogin)) { return false; } } return true; } else { return true; } } /** * Gets a list of required IN parameters in sequence. * @return A list of required IN parameters in the order which they were defined. */ public List getInParameterSequence(Map source) { List target = FastList.newInstance(); if (source == null) { return target; } if (contextInfo == null || contextInfo.size() == 0) { return target; } Iterator contextParamIter = this.contextParamList.iterator(); while (contextParamIter.hasNext()) { ModelParam modelParam = (ModelParam) contextParamIter.next(); // don't include OUT parameters in this list, only IN and INOUT if ("OUT".equals(modelParam.mode)) continue; Object srcObject = source.get(modelParam.name); if (srcObject != null) { target.add(srcObject); } } return target; } /** * Returns a list of ModelParam objects in the order they were defined when * the service was created. */ public List getModelParamList() { List newList = FastList.newInstance(); newList.addAll(this.contextParamList); return newList; } /** * Returns a list of ModelParam objects in the order they were defined when * the service was created. */ public List getInModelParamList() { List inList = FastList.newInstance(); Iterator contactParamIter = this.contextParamList.iterator(); while (contactParamIter.hasNext()) { ModelParam modelParam = (ModelParam) contactParamIter.next(); // don't include OUT parameters in this list, only IN and INOUT if ("OUT".equals(modelParam.mode)) continue; inList.add(modelParam); } return inList; } /** * Run the interface update and inherit all interface parameters * @param dctx The DispatchContext to use for service lookups */ public synchronized void interfaceUpdate(DispatchContext dctx) throws GenericServiceException { if (!inheritedParameters) { // services w/ engine 'group' auto-implement the grouped services if (this.engineName.equals("group") && implServices.size() == 0) { GroupModel group = ServiceGroupReader.getGroupModel(this.location); if (group != null) { List groupedServices = group.getServices(); Iterator i = groupedServices.iterator(); while (i.hasNext()) { GroupServiceModel sm = (GroupServiceModel) i.next(); implServices.add(sm.getName()); if (Debug.verboseOn()) Debug.logVerbose("Adding service [" + sm.getName() + "] as interface of: [" + this.name + "]", module); } } } // handle interfaces if (implServices != null && implServices.size() > 0 && dctx != null) { Iterator implIter = implServices.iterator(); while (implIter.hasNext()) { String serviceName = (String) implIter.next(); ModelService model = dctx.getModelService(serviceName); if (model != null) { Iterator contextParamIter = model.contextParamList.iterator(); while (contextParamIter.hasNext()) { ModelParam newParam = (ModelParam) contextParamIter.next(); ModelParam existingParam = (ModelParam) this.contextInfo.get(newParam.name); if (existingParam != null) { // if the existing param is not INOUT and the newParam.mode is different from existingParam.mode, make the existing param optional and INOUT // TODO: this is another case where having different optional/required settings for IN and OUT would be quite valuable... if (!"INOUT".equals(existingParam.mode) && !existingParam.mode.equals(newParam.mode)) { existingParam.mode = "INOUT"; existingParam.optional = true; } } else { // instead of calling: addParamClone(param), do it here because we want to make the inputs optional and such because earlier services in a group may create the parameters for later ModelParam newParamClone = new ModelParam(newParam); newParamClone.optional = true; this.addParam(newParamClone); } } } else { Debug.logWarning("Inherited model [" + serviceName + "] not found for [" + this.name + "]", module); } } } // handle any override parameters if (overrideParameters != null && overrideParameters.size() > 0) { Iterator keySetIter = overrideParameters.iterator(); while (keySetIter.hasNext()) { ModelParam overrideParam = (ModelParam) keySetIter.next(); ModelParam existingParam = (ModelParam) contextInfo.get(overrideParam.name); // keep the list clean, remove it then add it back contextParamList.remove(existingParam); if (existingParam != null) { // now re-write the parameters if (overrideParam.type != null && overrideParam.type.length() > 0) { existingParam.type = overrideParam.type; } if (overrideParam.mode != null && overrideParam.mode.length() > 0) { existingParam.mode = overrideParam.mode; } if (overrideParam.entityName != null && overrideParam.entityName.length() > 0) { existingParam.entityName = overrideParam.entityName; } if (overrideParam.fieldName != null && overrideParam.fieldName.length() > 0) { existingParam.fieldName = overrideParam.fieldName; } if (overrideParam.formLabel != null && overrideParam.formLabel.length() > 0) { existingParam.formLabel = overrideParam.formLabel; } if (overrideParam.overrideFormDisplay) { existingParam.formDisplay = overrideParam.formDisplay; } if (overrideParam.overrideOptional) { existingParam.optional = overrideParam.optional; } addParam(existingParam); } else { Debug.logWarning("Override param found but no parameter existing; ignoring: " + overrideParam.name, module); } } } // set the flag so we don't do this again this.inheritedParameters = true; } } public Document toWSDL(String locationURI) throws WSDLException { WSDLFactory factory = WSDLFactory.newInstance(); Definition def = factory.newDefinition(); def.setTargetNamespace(TNS); def.addNamespace("xsd", XSD); def.addNamespace("tns", TNS); def.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/"); this.getWSDL(def, locationURI); return factory.newWSDLWriter().getDocument(def);} public void getWSDL(Definition def, String locationURI) throws WSDLException { // set the IN parameters Input input = def.createInput(); List inParam = this.getParameterNames(IN_PARAM, true, false); if (inParam != null) { Message inMessage = def.createMessage(); inMessage.setQName(new QName(TNS, this.name + "Request")); inMessage.setUndefined(false); Iterator i = inParam.iterator(); while (i.hasNext()) { String paramName = (String) i.next(); ModelParam param = this.getParam(paramName); if (!param.internal) { inMessage.addPart(param.getWSDLPart(def)); } } def.addMessage(inMessage); input.setMessage(inMessage); } // set the OUT parameters Output output = def.createOutput(); List outParam = this.getParameterNames(OUT_PARAM, true, false); if (outParam != null) { Message outMessage = def.createMessage(); outMessage.setQName(new QName(TNS, this.name + "Response")); outMessage.setUndefined(false); Iterator i = outParam.iterator(); while (i.hasNext()) { String paramName = (String) i.next(); ModelParam param = this.getParam(paramName); if (!param.internal) { outMessage.addPart(param.getWSDLPart(def)); } } def.addMessage(outMessage); output.setMessage(outMessage); } // set port type Operation operation = def.createOperation(); operation.setName(this.name); operation.setUndefined(false); operation.setOutput(output); operation.setInput(input); PortType portType = def.createPortType(); portType.setQName(new QName(TNS, this.name + "PortType")); portType.addOperation(operation); portType.setUndefined(false); def.addPortType(portType); // SOAP binding SOAPBinding soapBinding = new SOAPBindingImpl(); soapBinding.setStyle("document"); soapBinding.setTransportURI("http://schemas.xmlsoap.org/soap/http"); Binding binding = def.createBinding(); binding.setQName(new QName(TNS, this.name + "SoapBinding")); binding.setPortType(portType); binding.setUndefined(false); binding.addExtensibilityElement(soapBinding); BindingOperation bindingOperation = def.createBindingOperation(); bindingOperation.setName(operation.getName()); bindingOperation.setOperation(operation); SOAPBody soapBody = new SOAPBodyImpl(); soapBody.setUse("literal"); soapBody.setNamespaceURI(TNS); soapBody.setEncodingStyles(UtilMisc.toList("http://schemas.xmlsoap.org/soap/encoding/")); BindingOutput bindingOutput = def.createBindingOutput(); bindingOutput.addExtensibilityElement(soapBody); bindingOperation.setBindingOutput(bindingOutput); BindingInput bindingInput = def.createBindingInput(); bindingInput.addExtensibilityElement(soapBody); bindingOperation.setBindingInput(bindingInput); SOAPOperation soapOperation = new SOAPOperationImpl(); soapOperation.setSoapActionURI(""); // ? bindingOperation.addExtensibilityElement(soapOperation); binding.addBindingOperation(bindingOperation); def.addBinding(binding); // Service port Port port = def.createPort(); port.setBinding(binding); port.setName(this.name + "Port"); if (locationURI != null) { SOAPAddress soapAddress = new SOAPAddressImpl(); soapAddress.setLocationURI(locationURI); port.addExtensibilityElement(soapAddress); } Service service = def.createService(); service.setQName(new QName(TNS, this.name)); service.addPort(port); def.addService(service); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -