Author: jaz
Date: Fri Jan 5 10:26:51 2007 New Revision: 493117 URL: http://svn.apache.org/viewvc?view=rev&rev=493117 Log: refactor of service groups; implemented in-line group definition in standard service defs, this removes the need to create two definitions for a service group. Old group definition files are still supported, but need to be updated to change 'service' to 'invoke'. Update to existing group files will follow in next commit. Modified: ofbiz/trunk/framework/service/dtd/service-group.xsd ofbiz/trunk/framework/service/dtd/services.xsd ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java ofbiz/trunk/framework/service/src/org/ofbiz/service/group/GroupModel.java ofbiz/trunk/framework/service/src/org/ofbiz/service/group/GroupServiceModel.java ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupEngine.java Modified: ofbiz/trunk/framework/service/dtd/service-group.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/dtd/service-group.xsd?view=diff&rev=493117&r1=493116&r2=493117 ============================================================================== --- ofbiz/trunk/framework/service/dtd/service-group.xsd (original) +++ ofbiz/trunk/framework/service/dtd/service-group.xsd Fri Jan 5 10:26:51 2007 @@ -25,13 +25,13 @@ <xs:element name="group"> <xs:complexType> <xs:sequence> - <xs:element maxOccurs="unbounded" ref="service"/> + <xs:element maxOccurs="unbounded" ref="invoke"/> </xs:sequence> <xs:attributeGroup ref="attlist.group"/> </xs:complexType> </xs:element> <xs:attributeGroup name="attlist.group"> - <xs:attribute type="xs:string" name="name" use="required"/> + <xs:attribute type="xs:string" name="name" use="optional"/> <xs:attribute name="send-mode" default="all"> <xs:simpleType> <xs:restriction base="xs:token"> @@ -44,12 +44,12 @@ </xs:simpleType> </xs:attribute> </xs:attributeGroup> - <xs:element name="service"> + <xs:element name="invoke"> <xs:complexType> - <xs:attributeGroup ref="attlist.service"/> + <xs:attributeGroup ref="attlist.invoke"/> </xs:complexType> </xs:element> - <xs:attributeGroup name="attlist.service"> + <xs:attributeGroup name="attlist.invoke"> <xs:attribute type="xs:string" name="name" use="required"/> <xs:attribute name="mode" default="sync"> <xs:simpleType> @@ -59,6 +59,14 @@ </xs:restriction> </xs:simpleType> </xs:attribute> + <xs:attribute name="parameters" default="preserve"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="optional"/> + <xs:enumeration value="preserve"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> <xs:attribute name="result-to-context" default="false"> <xs:simpleType> <xs:restriction base="xs:token"> @@ -72,8 +80,8 @@ <!-- <service-group> <group name="testOne" send-mode="none"> - <service name="testScv" mode="async"/> - <service name="testScv" mode="sync"/> + <invoke name="testScv" mode="async"/> + <invoke name="testScv" mode="sync"/> </group> </service-group> --> Modified: ofbiz/trunk/framework/service/dtd/services.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/dtd/services.xsd?view=diff&rev=493117&r1=493116&r2=493117 ============================================================================== --- ofbiz/trunk/framework/service/dtd/services.xsd (original) +++ ofbiz/trunk/framework/service/dtd/services.xsd Fri Jan 5 10:26:51 2007 @@ -15,6 +15,7 @@ under the License. --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> + <xs:include schemaLocation="http://www.ofbiz.org/dtds/service-group.xsd"/> <xs:element name="services"> <xs:complexType> <xs:sequence> @@ -38,8 +39,13 @@ <xs:element minOccurs="0" ref="namespace"/> <xs:element minOccurs="0" maxOccurs="unbounded" ref="required-permissions"/> <xs:element minOccurs="0" maxOccurs="unbounded" ref="implements"/> - <xs:element minOccurs="0" maxOccurs="unbounded" ref="auto-attributes"/> - <xs:element minOccurs="0" maxOccurs="unbounded" ref="attribute"/> + <xs:choice maxOccurs="1" minOccurs="0"> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element ref="auto-attributes"/> + <xs:element ref="attribute"/> + </xs:choice> + <xs:element ref="group"/> + </xs:choice> <xs:element minOccurs="0" maxOccurs="unbounded" ref="override"/> </xs:sequence> <xs:attributeGroup ref="attlist.service"/> @@ -145,7 +151,7 @@ </xs:element> <xs:attributeGroup name="attlist.implements"> <xs:attribute type="xs:string" name="service" use="required"/> - <xs:attribute type="xs:string" name="optional" default="true"> + <xs:attribute name="optional" default="true"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="true"/> Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java?view=diff&rev=493117&r1=493116&r2=493117 ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java Fri Jan 5 10:26:51 2007 @@ -129,6 +129,9 @@ /** List of permission groups for service invocation */ public List permissionGroups = FastList.newInstance(); + /** Internal Service Group */ + public GroupModel internalGroup = null; + /** Context Information, a Map of parameters used by the service, contains ModelParam objects */ protected Map contextInfo = FastMap.newInstance(); @@ -808,13 +811,16 @@ 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); + GroupModel group = internalGroup; + if (group == null) { + 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(new ModelServiceIface(sm.getName(), true)); + implServices.add(new ModelServiceIface(sm.getName(), sm.isOptional())); if (Debug.verboseOn()) Debug.logVerbose("Adding service [" + sm.getName() + "] as interface of: [" + this.name + "]", module); } } Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java?view=diff&rev=493117&r1=493116&r2=493117 ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java Fri Jan 5 10:26:51 2007 @@ -41,6 +41,7 @@ import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelField; import org.ofbiz.entity.model.ModelFieldType; +import org.ofbiz.service.group.GroupModel; import org.apache.commons.collections.map.LinkedMap; import org.w3c.dom.Document; @@ -321,7 +322,17 @@ service.description = getCDATADef(serviceElement, "description"); service.nameSpace = getCDATADef(serviceElement, "namespace"); - + + // check or an internal group + List group = UtilXml.childElementList(serviceElement, "group"); + if (group != null && group.size() > 0) { + Element groupElement = (Element) group.get(0); + groupElement.setAttribute("name", "_" + service.name + ".group"); + service.internalGroup = new GroupModel(groupElement); + service.invoke = service.internalGroup.getGroupName(); + } + + // contruct the context service.contextInfo = FastMap.newInstance(); this.createPermGroups(serviceElement, service); this.createImplDefs(serviceElement, service); Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/group/GroupModel.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/group/GroupModel.java?view=diff&rev=493117&r1=493116&r2=493117 ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/group/GroupModel.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/group/GroupModel.java Fri Jan 5 10:26:51 2007 @@ -38,6 +38,7 @@ private String groupName, sendMode; private List services; + private boolean optional = false; private int lastServiceRan; /** @@ -45,17 +46,30 @@ * @param group DOM element for the group */ public GroupModel(Element group) { - this.lastServiceRan = -1; + this.sendMode = group.getAttribute("send-mode"); + this.groupName = group.getAttribute("name"); this.services = new LinkedList(); - List serviceList = UtilXml.childElementList(group, "service"); - Iterator i = serviceList.iterator(); - while (i.hasNext()) { - Element service = (Element) i.next(); - services.add(new GroupServiceModel(service)); + this.lastServiceRan = -1; + + if (groupName == null) { + throw new IllegalArgumentException("Group Definition found with no name attribute! : " + group); } - this.groupName = group.getAttribute("name"); - this.sendMode = group.getAttribute("send-mode"); - if (Debug.verboseOn()) Debug.logVerbose("Created Service Group Model --> " + this, module); + + List serviceList = UtilXml.childElementList(group, "invoke"); + if (serviceList != null && serviceList.size() > 0) { + Iterator i = serviceList.iterator(); + while (i.hasNext()) { + Element service = (Element) i.next(); + services.add(new GroupServiceModel(service)); + } + } else { + List oldServiceTags = UtilXml.childElementList(group, "service"); + if (oldServiceTags != null && oldServiceTags.size() > 0) { + Debug.logWarning("Service Group Definition : [" + group.getAttribute("name") + "] found with OLD 'service' attribute, change to use 'invoke'", module); + } + } + + if (Debug.verboseOn()) Debug.logVerbose("Created Service Group Model --> " + this, module); } /** Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/group/GroupServiceModel.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/group/GroupServiceModel.java?view=diff&rev=493117&r1=493116&r2=493117 ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/group/GroupServiceModel.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/group/GroupServiceModel.java Fri Jan 5 10:26:51 2007 @@ -35,6 +35,7 @@ private String serviceName, serviceMode; private boolean resultToContext = false; + private boolean optionalParams = false; /** * Constructor using DOM element @@ -43,8 +44,9 @@ public GroupServiceModel(Element service) { this.serviceName = service.getAttribute("name"); this.serviceMode = service.getAttribute("mode"); - this.resultToContext = service.getAttribute("result-to-context").equalsIgnoreCase("true") ? true : false; - } + this.resultToContext = service.getAttribute("result-to-context").equalsIgnoreCase("true"); + this.optionalParams = service.getAttribute("parameters").equalsIgnoreCase("optional"); + } /** * Basic constructor @@ -78,6 +80,14 @@ */ public boolean resultToContext() { return this.resultToContext; + } + + /** + * Returns true of the parameters for this service are to be included as optional + * @return boolean + */ + public boolean isOptional() { + return this.optionalParams; } /** Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupEngine.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupEngine.java?view=diff&rev=493117&r1=493116&r2=493117 ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupEngine.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupEngine.java Fri Jan 5 10:26:51 2007 @@ -39,9 +39,13 @@ * @see org.ofbiz.service.engine.GenericEngine#runSync(java.lang.String, org.ofbiz.service.ModelService, java.util.Map) */ public Map runSync(String localName, ModelService modelService, Map context) throws GenericServiceException { - GroupModel groupModel = ServiceGroupReader.getGroupModel(this.getLocation(modelService)); + GroupModel groupModel = modelService.internalGroup; + if (groupModel == null) { + groupModel = ServiceGroupReader.getGroupModel(this.getLocation(modelService)); + } if (groupModel == null) throw new GenericServiceException("GroupModel was null; not a valid ServiceGroup!"); + return groupModel.run(dispatcher, localName, context); } |
Free forum by Nabble | Edit this page |