Modified: ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/definition/XpdlReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/definition/XpdlReader.java?rev=932317&r1=932316&r2=932317&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/definition/XpdlReader.java (original) +++ ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/definition/XpdlReader.java Fri Apr 9 09:40:02 2010 @@ -21,7 +21,6 @@ package org.ofbiz.workflow.definition; import java.io.IOException; import java.net.URL; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -33,8 +32,8 @@ import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilURL; -import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.DelegatorFactory; import org.ofbiz.entity.GenericEntityException; @@ -51,7 +50,7 @@ import org.xml.sax.SAXException; public class XpdlReader { protected Delegator delegator = null; - protected List values = null; + protected List<GenericValue> values = null; public static final String module = XpdlReader.class.getName(); @@ -62,7 +61,7 @@ public class XpdlReader { /** Imports an XPDL file at the given location and imports it into the * datasource through the given delegator */ public static void importXpdl(URL location, Delegator delegator) throws DefinitionParserException { - List values = readXpdl(location, delegator); + List<GenericValue> values = readXpdl(location, delegator); // attempt to start a transaction boolean beganTransaction = false; @@ -89,7 +88,7 @@ public class XpdlReader { /** Gets an XML file from the specified location and reads it into * GenericValue objects from the given delegator and returns them in a * List; does not write to the database, just gets the entities. */ - public static List readXpdl(URL location, Delegator delegator) throws DefinitionParserException { + public static List<GenericValue> readXpdl(URL location, Delegator delegator) throws DefinitionParserException { if (Debug.infoOn()) Debug.logInfo("Beginning XPDL File Parse: " + location.toString(), module); XpdlReader reader = new XpdlReader(delegator); @@ -110,8 +109,8 @@ public class XpdlReader { } } - public List readAll(Document document) throws DefinitionParserException { - values = new LinkedList(); + public List<GenericValue> readAll(Document document) throws DefinitionParserException { + values = new LinkedList<GenericValue>(); Element docElement; docElement = document.getDocumentElement(); @@ -119,7 +118,7 @@ public class XpdlReader { // puts everything in the values list for returning, etc later readPackage(docElement); - return (values); + return values; } // ---------------------------------------------------------------- @@ -179,40 +178,40 @@ public class XpdlReader { // Participants? Element participantsElement = UtilXml.firstChildElement(packageElement, "Participants"); - List participants = UtilXml.childElementList(participantsElement, "Participant"); + List<? extends Element> participants = UtilXml.childElementList(participantsElement, "Participant"); readParticipants(participants, packageId, packageVersion, "_NA_", "_NA_", packageValue); // ExternalPackages? Element externalPackagesElement = UtilXml.firstChildElement(packageElement, "ExternalPackages"); - List externalPackages = UtilXml.childElementList(externalPackagesElement, "ExternalPackage"); + List<? extends Element> externalPackages = UtilXml.childElementList(externalPackagesElement, "ExternalPackage"); readExternalPackages(externalPackages, packageId, packageVersion); // TypeDeclarations? Element typeDeclarationsElement = UtilXml.firstChildElement(packageElement, "TypeDeclarations"); - List typeDeclarations = UtilXml.childElementList(typeDeclarationsElement, "TypeDeclaration"); + List<? extends Element> typeDeclarations = UtilXml.childElementList(typeDeclarationsElement, "TypeDeclaration"); readTypeDeclarations(typeDeclarations, packageId, packageVersion); // Applications? Element applicationsElement = UtilXml.firstChildElement(packageElement, "Applications"); - List applications = UtilXml.childElementList(applicationsElement, "Application"); + List<? extends Element> applications = UtilXml.childElementList(applicationsElement, "Application"); readApplications(applications, packageId, packageVersion, "_NA_", "_NA_"); // DataFields? Element dataFieldsElement = UtilXml.firstChildElement(packageElement, "DataFields"); - List dataFields = UtilXml.childElementList(dataFieldsElement, "DataField"); + List<? extends Element> dataFields = UtilXml.childElementList(dataFieldsElement, "DataField"); readDataFields(dataFields, packageId, packageVersion, "_NA_", "_NA_"); } else { - values = new LinkedList(); + values = new LinkedList<GenericValue>(); } // WorkflowProcesses? Element workflowProcessesElement = UtilXml.firstChildElement(packageElement, "WorkflowProcesses"); - List workflowProcesses = UtilXml.childElementList(workflowProcessesElement, "WorkflowProcess"); + List<? extends Element> workflowProcesses = UtilXml.childElementList(workflowProcessesElement, "WorkflowProcess"); readWorkflowProcesses(workflowProcesses, packageId, packageVersion); } @@ -233,7 +232,7 @@ public class XpdlReader { // Responsibles? Element responsiblesElement = UtilXml.firstChildElement(redefinableHeaderElement, "Responsibles"); - List responsibles = UtilXml.childElementList(responsiblesElement, "Responsible"); + List<? extends Element> responsibles = UtilXml.childElementList(responsiblesElement, "Responsible"); readResponsibles(responsibles, valueObject, prefix); return true; @@ -284,7 +283,7 @@ public class XpdlReader { return true; } - protected void readResponsibles(List responsibles, GenericValue valueObject, String prefix) throws DefinitionParserException { + protected void readResponsibles(List<? extends Element> responsibles, GenericValue valueObject, String prefix) throws DefinitionParserException { if (UtilValidate.isEmpty(responsibles)) { return; } @@ -292,11 +291,8 @@ public class XpdlReader { String responsibleListId = delegator.getNextSeqId("WorkflowParticipantList"); valueObject.set("responsibleListId", responsibleListId); - Iterator responsibleIter = responsibles.iterator(); int responsibleIndex = 1; - - while (responsibleIter.hasNext()) { - Element responsibleElement = (Element) responsibleIter.next(); + for (Element responsibleElement : responsibles) { String responsibleId = UtilXml.elementValue(responsibleElement); GenericValue participantListValue = delegator.makeValue("WorkflowParticipantList"); @@ -317,13 +313,12 @@ public class XpdlReader { } } - protected void readExternalPackages(List externalPackages, String packageId, String packageVersion) { - if (UtilValidate.isEmpty(externalPackages)) + protected void readExternalPackages(List<? extends Element> externalPackages, String packageId, String packageVersion) { + if (UtilValidate.isEmpty(externalPackages)) { return; - Iterator externalPackageIter = externalPackages.iterator(); - - while (externalPackageIter.hasNext()) { - Element externalPackageElement = (Element) externalPackageIter.next(); + } + + for (Element externalPackageElement : externalPackages) { GenericValue externalPackageValue = delegator.makeValue("WorkflowPackageExternal"); values.add(externalPackageValue); @@ -333,13 +328,12 @@ public class XpdlReader { } } - protected void readTypeDeclarations(List typeDeclarations, String packageId, String packageVersion) throws DefinitionParserException { - if (UtilValidate.isEmpty(typeDeclarations)) + protected void readTypeDeclarations(List<? extends Element> typeDeclarations, String packageId, String packageVersion) throws DefinitionParserException { + if (UtilValidate.isEmpty(typeDeclarations)) { return; - Iterator typeDeclarationsIter = typeDeclarations.iterator(); - - while (typeDeclarationsIter.hasNext()) { - Element typeDeclarationElement = (Element) typeDeclarationsIter.next(); + } + + for (Element typeDeclarationElement : typeDeclarations) { GenericValue typeDeclarationValue = delegator.makeValue("WorkflowTypeDeclaration"); values.add(typeDeclarationValue); @@ -361,14 +355,12 @@ public class XpdlReader { // Process // ---------------------------------------------------------------- - protected void readWorkflowProcesses(List workflowProcesses, String packageId, String packageVersion) throws DefinitionParserException { - if (UtilValidate.isEmpty(workflowProcesses)) + protected void readWorkflowProcesses(List<? extends Element> workflowProcesses, String packageId, String packageVersion) throws DefinitionParserException { + if (UtilValidate.isEmpty(workflowProcesses)) { return; - Iterator workflowProcessIter = workflowProcesses.iterator(); - - while (workflowProcessIter.hasNext()) { - Element workflowProcessElement = (Element) workflowProcessIter.next(); - + } + + for (Element workflowProcessElement : workflowProcesses) { readWorkflowProcess(workflowProcessElement, packageId, packageVersion); } } @@ -486,7 +478,7 @@ public class XpdlReader { // FormalParameters? Element formalParametersElement = UtilXml.firstChildElement(workflowProcessElement, "FormalParameters"); - List formalParameters = UtilXml.childElementList(formalParametersElement, "FormalParameter"); + List<? extends Element> formalParameters = UtilXml.childElementList(formalParametersElement, "FormalParameter"); readFormalParameters(formalParameters, packageId, packageVersion, processId, processVersion, "_NA_"); @@ -494,31 +486,31 @@ public class XpdlReader { // DataFields? Element dataFieldsElement = UtilXml.firstChildElement(workflowProcessElement, "DataFields"); - List dataFields = UtilXml.childElementList(dataFieldsElement, "DataField"); + List<? extends Element> dataFields = UtilXml.childElementList(dataFieldsElement, "DataField"); readDataFields(dataFields, packageId, packageVersion, processId, processVersion); // Participants? Element participantsElement = UtilXml.firstChildElement(workflowProcessElement, "Participants"); - List participants = UtilXml.childElementList(participantsElement, "Participant"); + List<? extends Element> participants = UtilXml.childElementList(participantsElement, "Participant"); readParticipants(participants, packageId, packageVersion, processId, processVersion, workflowProcessValue); // Applications? Element applicationsElement = UtilXml.firstChildElement(workflowProcessElement, "Applications"); - List applications = UtilXml.childElementList(applicationsElement, "Application"); + List<? extends Element> applications = UtilXml.childElementList(applicationsElement, "Application"); readApplications(applications, packageId, packageVersion, processId, processVersion); // Activities Element activitiesElement = UtilXml.firstChildElement(workflowProcessElement, "Activities"); - List activities = UtilXml.childElementList(activitiesElement, "Activity"); + List<? extends Element> activities = UtilXml.childElementList(activitiesElement, "Activity"); readActivities(activities, packageId, packageVersion, processId, processVersion, workflowProcessValue); // Transitions Element transitionsElement = UtilXml.firstChildElement(workflowProcessElement, "Transitions"); - List transitions = UtilXml.childElementList(transitionsElement, "Transition"); + List<? extends Element> transitions = UtilXml.childElementList(transitionsElement, "Transition"); readTransitions(transitions, packageId, packageVersion, processId, processVersion); @@ -531,24 +523,22 @@ public class XpdlReader { // Activity // ---------------------------------------------------------------- - protected void readActivities(List activities, String packageId, String packageVersion, String processId, - String processVersion, GenericValue processValue) throws DefinitionParserException { - if (UtilValidate.isEmpty(activities)) + protected void readActivities(List<? extends Element> activities, String packageId, String packageVersion, String processId, + String processVersion, GenericValue processValue) throws DefinitionParserException { + if (UtilValidate.isEmpty(activities)) { return; - Iterator activitiesIter = activities.iterator(); - + } + // do the first one differently because it will be the defaultStart activity - if (activitiesIter.hasNext()) { - Element activityElement = (Element) activitiesIter.next(); + if (activities.size() > 0) { + Element activityElement = activities.get(0); String activityId = activityElement.getAttribute("Id"); processValue.set("defaultStartActivityId", activityId); readActivity(activityElement, packageId, packageVersion, processId, processVersion); } - while (activitiesIter.hasNext()) { - Element activityElement = (Element) activitiesIter.next(); - + for (Element activityElement : activities) { readActivity(activityElement, packageId, packageVersion, processId, processVersion); } } @@ -592,7 +582,7 @@ public class XpdlReader { Element noElement = UtilXml.firstChildElement(implementationElement, "No"); Element subFlowElement = UtilXml.firstChildElement(implementationElement, "SubFlow"); Element loopElement = UtilXml.firstChildElement(implementationElement, "Loop"); - List tools = UtilXml.childElementList(implementationElement, "Tool"); + List<? extends Element> tools = UtilXml.childElementList(implementationElement, "Tool"); if (noElement != null) { activityValue.set("activityTypeEnumId", "WAT_NO"); @@ -707,7 +697,7 @@ public class XpdlReader { // TransitionRestrictions? Element transitionRestrictionsElement = UtilXml.firstChildElement(activityElement, "TransitionRestrictions"); - List transitionRestrictions = UtilXml.childElementList(transitionRestrictionsElement, "TransitionRestriction"); + List<? extends Element> transitionRestrictions = UtilXml.childElementList(transitionRestrictionsElement, "TransitionRestriction"); readTransitionRestrictions(transitionRestrictions, activityValue); @@ -745,7 +735,7 @@ public class XpdlReader { // ActualParameters? Element actualParametersElement = UtilXml.firstChildElement(subFlowElement, "ActualParameters"); - List actualParameters = UtilXml.childElementList(actualParametersElement, "ActualParameter"); + List<? extends Element> actualParameters = UtilXml.childElementList(actualParametersElement, "ActualParameter"); subFlowValue.set("actualParameters", readActualParameters(actualParameters), false); } @@ -774,15 +764,13 @@ public class XpdlReader { loopValue.set("conditionExpr", UtilXml.childElementValue(loopElement, "Condition")); } - protected void readTools(List tools, String packageId, String packageVersion, String processId, + protected void readTools(List<? extends Element> tools, String packageId, String packageVersion, String processId, String processVersion, String activityId) throws DefinitionParserException { - if (UtilValidate.isEmpty(tools)) + if (UtilValidate.isEmpty(tools)) { return; - Iterator toolsIter = tools.iterator(); - - while (toolsIter.hasNext()) { - Element toolElement = (Element) toolsIter.next(); - + } + + for (Element toolElement : tools) { readTool(toolElement, packageId, packageVersion, processId, processVersion, activityId); } } @@ -814,36 +802,31 @@ public class XpdlReader { // ActualParameters/ExtendedAttributes? Element actualParametersElement = UtilXml.firstChildElement(toolElement, "ActualParameters"); Element extendedAttributesElement = UtilXml.firstChildElement(toolElement, "ExtendedAttributes"); - List actualParameters = UtilXml.childElementList(actualParametersElement, "ActualParameter"); - List extendedAttributes = UtilXml.childElementList(extendedAttributesElement, "ExtendedAttribute"); + List<? extends Element> actualParameters = UtilXml.childElementList(actualParametersElement, "ActualParameter"); + List<? extends Element> extendedAttributes = UtilXml.childElementList(extendedAttributesElement, "ExtendedAttribute"); toolValue.set("actualParameters", readActualParameters(actualParameters), false); toolValue.set("extendedAttributes", readExtendedAttributes(extendedAttributes), false); } - protected String readActualParameters(List actualParameters) { + protected String readActualParameters(List<? extends Element> actualParameters) { if (UtilValidate.isEmpty(actualParameters)) return null; - StringBuilder actualParametersBuf = new StringBuilder(); - Iterator actualParametersIter = actualParameters.iterator(); - while (actualParametersIter.hasNext()) { - Element actualParameterElement = (Element) actualParametersIter.next(); - - actualParametersBuf.append(UtilXml.elementValue(actualParameterElement)); - if (actualParametersIter.hasNext()) + StringBuilder actualParametersBuf = new StringBuilder(); + for (Element actualParameterElement : actualParameters) { + if (actualParametersBuf.length() > 0) { actualParametersBuf.append(','); + } + actualParametersBuf.append(UtilXml.elementValue(actualParameterElement)); } return actualParametersBuf.toString(); } - protected String readExtendedAttributes(List extendedAttributes) { + protected String readExtendedAttributes(List<? extends Element> extendedAttributes) { if (UtilValidate.isEmpty(extendedAttributes)) return null; - Map ea = new HashMap(); - Iterator i = extendedAttributes.iterator(); - - while (i.hasNext()) { - Element e = (Element) i.next(); + Map<Object, Object> ea = new HashMap<Object, Object>(); + for (Element e : extendedAttributes) { ea.put(e.getAttribute("Name"), e.getAttribute("Value")); } return StringUtil.mapToStr(ea); @@ -853,15 +836,13 @@ public class XpdlReader { // Transition // ---------------------------------------------------------------- - protected void readTransitions(List transitions, String packageId, String packageVersion, String processId, + protected void readTransitions(List<? extends Element> transitions, String packageId, String packageVersion, String processId, String processVersion) throws DefinitionParserException { - if (UtilValidate.isEmpty(transitions)) + if (UtilValidate.isEmpty(transitions)) { return; - Iterator transitionsIter = transitions.iterator(); - - while (transitionsIter.hasNext()) { - Element transitionElement = (Element) transitionsIter.next(); + } + for (Element transitionElement : transitions) { readTransition(transitionElement, packageId, packageVersion, processId, processVersion); } } @@ -902,7 +883,7 @@ public class XpdlReader { transitionValue.set("conditionTypeEnumId", "WTC_CONDITION"); // a Condition will have either a list of XPression elements, or plain PCDATA - List xPressions = UtilXml.childElementList(conditionElement, "XPression"); + List<? extends Element> xPressions = UtilXml.childElementList(conditionElement, "XPression"); if (UtilValidate.isNotEmpty(xPressions)) { throw new DefinitionParserException("XPression elements under Condition not yet supported, just use text inside Condition with the expression"); @@ -916,21 +897,21 @@ public class XpdlReader { // ExtendedAttributes? Element extendedAttributesElement = UtilXml.firstChildElement(transitionElement, "ExtendedAttributes"); - List extendedAttributes = UtilXml.childElementList(extendedAttributesElement, "ExtendedAttribute"); + List<? extends Element> extendedAttributes = UtilXml.childElementList(extendedAttributesElement, "ExtendedAttribute"); transitionValue.set("extendedAttributes", readExtendedAttributes(extendedAttributes), false); } - protected void readTransitionRestrictions(List transitionRestrictions, GenericValue activityValue) throws DefinitionParserException { - if (UtilValidate.isEmpty(transitionRestrictions)) + protected void readTransitionRestrictions(List<? extends Element> transitionRestrictions, GenericValue activityValue) throws DefinitionParserException { + if (UtilValidate.isEmpty(transitionRestrictions)) { return; - Iterator transitionRestrictionsIter = transitionRestrictions.iterator(); - - if (transitionRestrictionsIter.hasNext()) { - Element transitionRestrictionElement = (Element) transitionRestrictionsIter.next(); - + } + + + if (transitionRestrictions.size() > 0) { + Element transitionRestrictionElement = transitionRestrictions.get(0); readTransitionRestriction(transitionRestrictionElement, activityValue); } - if (transitionRestrictionsIter.hasNext()) { + if (transitionRestrictions.size() > 1) { throw new DefinitionParserException("Multiple TransitionRestriction elements found, this is not currently supported. Please remove extras."); } } @@ -979,19 +960,19 @@ public class XpdlReader { // TransitionRefs Element transitionRefsElement = UtilXml.firstChildElement(splitElement, "TransitionRefs"); - List transitionRefs = UtilXml.childElementList(transitionRefsElement, "TransitionRef"); + List<? extends Element> transitionRefs = UtilXml.childElementList(transitionRefsElement, "TransitionRef"); readTransitionRefs(transitionRefs, packageId, packageVersion, processId, processVersion, activityId); } } - protected void readTransitionRefs(List transitionRefs, String packageId, String packageVersion, String processId, String processVersion, String activityId) throws DefinitionParserException { - if (UtilValidate.isEmpty(transitionRefs)) + protected void readTransitionRefs(List<? extends Element> transitionRefs, String packageId, String packageVersion, String processId, + String processVersion, String activityId) throws DefinitionParserException { + if (UtilValidate.isEmpty(transitionRefs)) { return; - Iterator transitionRefsIter = transitionRefs.iterator(); + } - while (transitionRefsIter.hasNext()) { - Element transitionRefElement = (Element) transitionRefsIter.next(); + for (Element transitionRefElement : transitionRefs) { GenericValue transitionRefValue = delegator.makeValue("WorkflowTransitionRef"); values.add(transitionRefValue); @@ -1009,13 +990,13 @@ public class XpdlReader { // Others // ---------------------------------------------------------------- - protected void readParticipants(List participants, String packageId, String packageVersion, String processId, String processVersion, GenericValue valueObject) throws DefinitionParserException { - if (UtilValidate.isEmpty(participants)) + protected void readParticipants(List<? extends Element> participants, String packageId, String packageVersion, String processId, + String processVersion, GenericValue valueObject) throws DefinitionParserException { + if (UtilValidate.isEmpty(participants)) { return; - Iterator participantsIter = participants.iterator(); + } - while (participantsIter.hasNext()) { - Element participantElement = (Element) participantsIter.next(); + for (Element participantElement : participants) { String participantId = participantElement.getAttribute("Id"); GenericValue participantValue = delegator.makeValue("WorkflowParticipant"); @@ -1110,14 +1091,13 @@ public class XpdlReader { } */ - protected void readApplications(List applications, String packageId, String packageVersion, String processId, + protected void readApplications(List<? extends Element> applications, String packageId, String packageVersion, String processId, String processVersion) throws DefinitionParserException { - if (UtilValidate.isEmpty(applications)) + if (UtilValidate.isEmpty(applications)) { return; - Iterator applicationsIter = applications.iterator(); + } - while (applicationsIter.hasNext()) { - Element applicationElement = (Element) applicationsIter.next(); + for (Element applicationElement : applications) { GenericValue applicationValue = delegator.makeValue("WorkflowApplication"); values.add(applicationValue); @@ -1136,20 +1116,19 @@ public class XpdlReader { // FormalParameters? Element formalParametersElement = UtilXml.firstChildElement(applicationElement, "FormalParameters"); - List formalParameters = UtilXml.childElementList(formalParametersElement, "FormalParameter"); + List<? extends Element> formalParameters = UtilXml.childElementList(formalParametersElement, "FormalParameter"); readFormalParameters(formalParameters, packageId, packageVersion, processId, processVersion, applicationId); } } - protected void readDataFields(List dataFields, String packageId, String packageVersion, String processId, + protected void readDataFields(List<? extends Element> dataFields, String packageId, String packageVersion, String processId, String processVersion) throws DefinitionParserException { - if (UtilValidate.isEmpty(dataFields)) + if (UtilValidate.isEmpty(dataFields)) { return; - Iterator dataFieldsIter = dataFields.iterator(); + } - while (dataFieldsIter.hasNext()) { - Element dataFieldElement = (Element) dataFieldsIter.next(); + for (Element dataFieldElement : dataFields) { GenericValue dataFieldValue = delegator.makeValue("WorkflowDataField"); values.add(dataFieldValue); @@ -1196,15 +1175,14 @@ public class XpdlReader { } } - protected void readFormalParameters(List formalParameters, String packageId, String packageVersion, + protected void readFormalParameters(List<? extends Element> formalParameters, String packageId, String packageVersion, String processId, String processVersion, String applicationId) throws DefinitionParserException { - if (UtilValidate.isEmpty(formalParameters)) + if (UtilValidate.isEmpty(formalParameters)) { return; - Iterator formalParametersIter = formalParameters.iterator(); + } + long index = 1; - - while (formalParametersIter.hasNext()) { - Element formalParameterElement = (Element) formalParametersIter.next(); + for (Element formalParameterElement : formalParameters) { GenericValue formalParameterValue = delegator.makeValue("WorkflowFormalParam"); values.add(formalParameterValue); @@ -1286,15 +1264,13 @@ public class XpdlReader { if (extendedAttributesElement == null) return defaultValue; - List extendedAttributes = UtilXml.childElementList(extendedAttributesElement, "ExtendedAttribute"); + List<? extends Element> extendedAttributes = UtilXml.childElementList(extendedAttributesElement, "ExtendedAttribute"); - if (UtilValidate.isEmpty(extendedAttributes)) + if (UtilValidate.isEmpty(extendedAttributes)) { return defaultValue; + } - Iterator iter = extendedAttributes.iterator(); - - while (iter.hasNext()) { - Element extendedAttribute = (Element) iter.next(); + for (Element extendedAttribute : extendedAttributes) { String elementName = extendedAttribute.getAttribute("Name"); if (name.equals(elementName)) { @@ -1311,13 +1287,14 @@ public class XpdlReader { public static void main(String[] args) throws Exception { String sampleFileName = "../../docs/examples/sample.xpdl"; - if (args.length > 0) + if (args.length > 0) { sampleFileName = args[0]; - List values = readXpdl(UtilURL.fromFilename(sampleFileName), DelegatorFactory.getDelegator("default")); - Iterator viter = values.iterator(); - - while (viter.hasNext()) - System.out.println(viter.next().toString()); + } + + List<GenericValue> values = readXpdl(UtilURL.fromFilename(sampleFileName), DelegatorFactory.getDelegator("default")); + for (GenericValue value : values) { + System.out.println(value.toString()); + } } } Modified: ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/ServiceCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/ServiceCondition.java?rev=932317&r1=932316&r2=932317&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/ServiceCondition.java (original) +++ ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/ServiceCondition.java Fri Apr 9 09:40:02 2010 @@ -41,7 +41,7 @@ public class ServiceCondition implements /** * @see org.ofbiz.workflow.TransitionCondition#evaluateCondition(java.util.Map, java.util.Map, java.lang.String, org.ofbiz.service.DispatchContext) */ - public Boolean evaluateCondition(Map context, Map attrs, String expression, DispatchContext dctx) throws EvaluationException { + public Boolean evaluateCondition(Map<String, Object> context, Map<String, String> attrs, String expression, DispatchContext dctx) throws EvaluationException { // get the service to call String serviceName = (String) attrs.get("serviceName"); if (UtilValidate.isEmpty(serviceName)) @@ -53,11 +53,11 @@ public class ServiceCondition implements throw new EvaluationException("Bad LocalDispatcher found in the DispatchContext"); // create a map of all context and extended attributes, attributes will overwrite context values - Map newContext = new HashMap(context); + Map<String, Object> newContext = new HashMap<String, Object>(context); newContext.putAll(attrs); // build the context for the service - Map serviceContext = null; + Map<String, Object> serviceContext = null; ModelService model = null; try { model = dctx.getModelService(serviceName); @@ -67,7 +67,7 @@ public class ServiceCondition implements } // invoke the service - Map serviceResult = null; + Map<String, Object> serviceResult = null; try { serviceResult = dispatcher.runSync(serviceName, serviceContext); } catch (GenericServiceException e) { Modified: ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityAbstractImplementation.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityAbstractImplementation.java?rev=932317&r1=932316&r2=932317&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityAbstractImplementation.java (original) +++ ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityAbstractImplementation.java Fri Apr 9 09:40:02 2010 @@ -38,7 +38,7 @@ public abstract class WfActivityAbstract public static final String module = WfActivityAbstractImplementation.class.getName(); private WfActivityImpl wfActivity = null; - private Map resultContext = new HashMap(); + private Map<String, Object> resultContext = new HashMap<String, Object>(); private boolean complete = false; public WfActivityAbstractImplementation(WfActivityImpl wfActivity) { @@ -69,11 +69,11 @@ public abstract class WfActivityAbstract protected GenericResultWaiter runService(ModelService service, String params, String extend) throws WfException { LocalDispatcher dispatcher = getActivity().getDispatcher(); - List paramNames = service.getParameterNames(ModelService.IN_PARAM, true); + List<String> paramNames = service.getParameterNames(ModelService.IN_PARAM, true); if (paramNames != null && paramNames.size() == 0) paramNames = null; - Map ctx = getActivity().actualContext(params, extend, paramNames, false); + Map<String, Object> ctx = getActivity().actualContext(params, extend, paramNames, false); GenericResultWaiter waiter = new GenericResultWaiter(); Debug.logVerbose("[WfActivityAbstractImplementation.runService] : Invoking the service.", module); @@ -86,7 +86,7 @@ public abstract class WfActivityAbstract return waiter; } - protected void setResult(Map result) { + protected void setResult(Map<String, Object> result) { this.resultContext.putAll(result); } @@ -100,7 +100,7 @@ public abstract class WfActivityAbstract * Returns the result context. * @return Map */ - public Map getResult() { + public Map<String, Object> getResult() { return resultContext; } Modified: ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityImpl.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityImpl.java?rev=932317&r1=932316&r2=932317&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityImpl.java (original) +++ ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityImpl.java Fri Apr 9 09:40:02 2010 @@ -20,7 +20,6 @@ package org.ofbiz.workflow.impl; import java.util.ArrayList; import com.ibm.icu.util.Calendar; -import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -100,7 +99,7 @@ public class WfActivityImpl extends WfEx if (inheritPriority) { GenericValue runTime = getRuntimeObject(); - Map context = processContext(); + Map<String, Object> context = processContext(); if (context.containsKey("previousActivity")) { String previousActivity = (String) context.get("previousActivity"); @@ -122,7 +121,7 @@ public class WfActivityImpl extends WfEx try { performer = valueObject.getRelatedOne("PerformerWorkflowParticipant"); if (performer == null) { - Map performerFields = UtilMisc.toMap("packageId", valueObject.getString("packageId"), + Map<String, Object> performerFields = UtilMisc.toMap("packageId", (Object) valueObject.getString("packageId"), "packageVersion", valueObject.getString("packageVersion"), "processId", "_NA_", "processVersion", "_NA_", "participantId", valueObject.getString("performerParticipantId")); performer = delegator.findByPrimaryKey("WorkflowParticipant", performerFields); @@ -168,20 +167,20 @@ public class WfActivityImpl extends WfEx GenericValue groupType = null; try { - Map fields1 = UtilMisc.toMap("partyId", performer.getString("partyId")); + Map<String, Object> fields1 = UtilMisc.toMap("partyId", (Object) performer.getString("partyId")); GenericValue v1 = getDelegator().findByPrimaryKey("Party", fields1); partyType = v1.getRelatedOne("PartyType"); - Map fields2 = UtilMisc.toMap("partyTypeId", "PARTY_GROUP"); + Map<String, Object> fields2 = UtilMisc.toMap("partyTypeId", (Object) "PARTY_GROUP"); groupType = getDelegator().findByPrimaryKeyCache("PartyType", fields2); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } if (EntityTypeUtil.isType(partyType, groupType)) { // party is a group - Collection partyRelations = null; + List<GenericValue> partyRelations = null; try { - Map fields = UtilMisc.toMap("partyIdFrom", performer.getString("partyId"), + Map<String, Object> fields = UtilMisc.toMap("partyIdFrom", (Object) performer.getString("partyId"), "partyRelationshipTypeId", "GROUP_ROLLUP"); partyRelations = getDelegator().findByAnd("PartyRelationship", fields); } catch (GenericEntityException e) { @@ -190,10 +189,7 @@ public class WfActivityImpl extends WfEx // make assignments for these parties Debug.logVerbose("[WfActivity.createAssignments] : Group assignment", module); - Iterator i = partyRelations.iterator(); - - while (i.hasNext()) { - GenericValue value = (GenericValue) i.next(); + for (GenericValue value : partyRelations) { assign( WfFactory.getWfResource(getDelegator(), null, null, value.getString("partyIdTo"), null), true); @@ -207,10 +203,10 @@ public class WfActivityImpl extends WfEx // check for role types else if (performer.get("roleTypeId") != null && !performer.getString("roleTypeId").equals("_NA_")) { - Collection partyRoles = null; + List<GenericValue> partyRoles = null; try { - Map fields = UtilMisc.toMap("roleTypeId", performer.getString("roleTypeId")); + Map<String, Object> fields = UtilMisc.toMap("roleTypeId", (Object) performer.getString("roleTypeId")); partyRoles = getDelegator().findByAnd("PartyRole", fields); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); @@ -218,25 +214,20 @@ public class WfActivityImpl extends WfEx // loop through the roles and create assignments Debug.logVerbose("[WfActivity.createAssignments] : Role assignment", module); - Iterator i = partyRoles.iterator(); - - while (i.hasNext()) { - GenericValue value = (GenericValue) i.next(); + for (GenericValue value : partyRoles) { assign(WfFactory.getWfResource(value.getDelegator(), null, null, value.getString("partyId"), null), true); } } } - private List getAssignments() throws WfException { - List assignments = new ArrayList(); - List assignList = this.getAllAssignments(); + private List<WfAssignment> getAssignments() throws WfException { + List<WfAssignment> assignments = new ArrayList<WfAssignment>(); + List<GenericValue> assignList = this.getAllAssignments(); if (assignList == null) return assignments; - Iterator i = assignList.iterator(); - while (i.hasNext()) { - GenericValue value = (GenericValue) i.next(); + for (GenericValue value : assignList) { String party = value.getString("partyId"); String role = value.getString("roleTypeId"); String status = value.getString("statusId"); @@ -249,8 +240,8 @@ public class WfActivityImpl extends WfEx return assignments; } - private List getAllAssignments() throws WfException { - List assignList = null; + private List<GenericValue> getAllAssignments() throws WfException { + List<GenericValue> assignList = null; try { assignList = getDelegator().findByAnd("WorkEffortPartyAssignment", UtilMisc.toMap("workEffortId", runtimeKey())); } catch (GenericEntityException e) { @@ -260,7 +251,7 @@ public class WfActivityImpl extends WfEx if (assignList != null) { assignList = EntityUtil.filterByDate(assignList); } else { - return new ArrayList(); + return new ArrayList<GenericValue>(); } return assignList; } @@ -268,9 +259,7 @@ public class WfActivityImpl extends WfEx // create a new assignment private WfAssignment assign(WfResource resource, boolean append) throws WfException { if (!append) { - Iterator ai = getIteratorAssignment(); - while (ai.hasNext()) { - WfAssignment a = (WfAssignment) ai.next(); + for (WfAssignment a : getAssignments()) { a.remove(); } } @@ -282,7 +271,7 @@ public class WfActivityImpl extends WfEx // check the performer: dynamic; defined partyId/roleTypeId private GenericValue checkPerformer(GenericValue performer) throws WfException { GenericValue newPerformer = GenericValue.create(performer); - Map context = processContext(); + Map<String, Object> context = processContext(); String performerType = performer.getString("participantTypeId"); String partyId = performer.getString("partyId"); @@ -358,9 +347,9 @@ public class WfActivityImpl extends WfEx if (mode.equals("WAM_AUTOMATIC")) { Debug.logVerbose("Activity start mode is AUTO", module); - Iterator i = getIteratorAssignment(); - while (i.hasNext()) - ((WfAssignment) i.next()).changeStatus("CAL_ACCEPTED"); // accept all assignments (AUTO) + for (WfAssignment assignment : getAssignments()) { + assignment.changeStatus("CAL_ACCEPTED"); // accept all assignments (AUTO) + } Debug.logVerbose("All assignments accepted, starting activity: " + this.runtimeKey(), module); startActivity(); } else if (howManyAssignment() > 0 && checkAssignStatus(CHECK_ASSIGN)) { @@ -419,9 +408,7 @@ public class WfActivityImpl extends WfEx super.abort(); // cancel the active assignments - Iterator assignments = this.getAssignments().iterator(); - while (assignments.hasNext()) { - WfAssignment assignment = (WfAssignment) assignments.next(); + for (WfAssignment assignment : this.getAssignments()) { assignment.changeStatus("CAL_CANCELLED"); } } @@ -443,13 +430,13 @@ public class WfActivityImpl extends WfEx /** * @see org.ofbiz.workflow.WfActivity#setResult(java.util.Map) */ - public void setResult(Map newResult) throws WfException, InvalidData { + public void setResult(Map<String, Object> newResult) throws WfException, InvalidData { if (UtilValidate.isNotEmpty(newResult)) { if (Debug.verboseOn()) Debug.logVerbose( "[WfActivity.setResult]: putting (" + newResult.size() + ") keys into context.", module); - Map context = processContext(); + Map<String, Object> context = processContext(); context.putAll(newResult); setSerializedData(context); } @@ -465,18 +452,15 @@ public class WfActivityImpl extends WfEx /** * @see org.ofbiz.workflow.WfActivity#result() */ - public Map result() throws WfException, ResultNotAvailable { + public Map<String, Object> result() throws WfException, ResultNotAvailable { // Get the results from the signature. - Map resultSig = container().manager().resultSignature(); - Map results = new HashMap(); - Map context = processContext(); + Map<String, Object> resultSig = container().manager().resultSignature(); + Map<String, Object> results = new HashMap<String, Object>(); + Map<String, Object> context = processContext(); if (resultSig != null) { - Set resultKeys = resultSig.keySet(); - Iterator i = resultKeys.iterator(); - - while (i.hasNext()) { - Object key = i.next(); + Set<String> resultKeys = resultSig.keySet(); + for (String key : resultKeys) { if (context.containsKey(key)) results.put(key, context.get(key)); } @@ -487,7 +471,7 @@ public class WfActivityImpl extends WfEx /** * @see org.ofbiz.workflow.WfActivity#getSequenceAssignment(int) */ - public List getSequenceAssignment(int maxNumber) throws WfException { + public List<WfAssignment> getSequenceAssignment(int maxNumber) throws WfException { if (maxNumber > 0) return getAssignments().subList(0, (maxNumber - 1)); return getAssignments(); @@ -496,7 +480,7 @@ public class WfActivityImpl extends WfEx /** * @see org.ofbiz.workflow.WfActivity#getIteratorAssignment() */ - public Iterator getIteratorAssignment() throws WfException { + public Iterator<WfAssignment> getIteratorAssignment() throws WfException { return getAssignments().iterator(); } @@ -520,9 +504,9 @@ public class WfActivityImpl extends WfEx // check and make sure we are not suspended if (state().equals("open.running")) { // set the status of the assignments - Iterator i = getIteratorAssignment(); - while (i.hasNext()) - ((WfAssignment) i.next()).changeStatus("CAL_COMPLETED"); + for (WfAssignment assignment : getAssignments()) { + assignment.changeStatus("CAL_COMPLETED"); + } this.complete(); } } @@ -541,7 +525,7 @@ public class WfActivityImpl extends WfEx if (valueObject.get("completeAllAssignments") != null) completeAll = valueObject.getBoolean("completeAllAssignments").booleanValue(); - List validStatus = null; + List<String> validStatus = null; if (type == CHECK_ASSIGN) validStatus = UtilMisc.toList("CAL_ACCEPTED", "CAL_COMPLETED", "CAL_DELEGATED"); @@ -552,11 +536,7 @@ public class WfActivityImpl extends WfEx boolean foundOne = false; - List assignList = this.getAllAssignments(); - Iterator i = assignList.iterator(); - - while (i.hasNext()) { - GenericValue value = (GenericValue) i.next(); + for (GenericValue value : this.getAllAssignments()) { String party = value.getString("partyId"); String role = value.getString("roleTypeId"); java.sql.Timestamp from = value.getTimestamp("fromDate"); @@ -605,8 +585,7 @@ public class WfActivityImpl extends WfEx } // set the new previousActivity - Map context = processContext(); - + Map<String, Object> context = processContext(); context.put("previousActivity", workEffortId); this.setProcessContext(context); @@ -654,10 +633,10 @@ public class WfActivityImpl extends WfEx } // make the limit service context - List inList = new ArrayList(service.getInParamNames()); + List<String> inList = new ArrayList<String>(service.getInParamNames()); String inParams = StringUtil.join(inList, ","); - Map serviceContext = actualContext(inParams, null, null, true); + Map<String, Object> serviceContext = actualContext(inParams, null, null, true); Debug.logVerbose("Setting limit service with context: " + serviceContext, module); Double timeLimit = null; @@ -708,8 +687,8 @@ public class WfActivityImpl extends WfEx } long startTime = cal.getTime().getTime(); - Map context = new HashMap(); + Map<String, Object> context = new HashMap<String, Object>(); context.put("serviceName", limitService); context.put("serviceContext", serviceContext); context.put("workEffortId", runtimeKey()); @@ -724,12 +703,12 @@ public class WfActivityImpl extends WfEx } } - Map actualContext(String actualParameters, String extendedAttr, List serviceSignature, boolean ignoreUnknown) throws WfException { - Map actualContext = new HashMap(); - Map context = processContext(); + Map<String, Object> actualContext(String actualParameters, String extendedAttr, List<String> serviceSignature, boolean ignoreUnknown) throws WfException { + Map<String, Object> actualContext = new HashMap<String, Object>(); + Map<String, Object> context = processContext(); // extended attributes take priority over context attributes - Map extendedAttributes = StringUtil.strToMap(extendedAttr); + Map<String, String> extendedAttributes = StringUtil.strToMap(extendedAttr); if (UtilValidate.isNotEmpty(extendedAttributes)) { context.putAll(extendedAttributes); @@ -750,7 +729,7 @@ public class WfActivityImpl extends WfEx context.put("workEffortId", runtimeKey()); if (howManyAssignment() == 1) { Debug.logVerbose("Single assignment; getting assignment info.", module); - List assignments = getAssignments(); + List<WfAssignment> assignments = getAssignments(); WfAssignment assign = (WfAssignment) assignments.iterator().next(); WfResource res = assign.assignee(); context.put("assignedPartyId", res.resourcePartyId()); @@ -759,25 +738,20 @@ public class WfActivityImpl extends WfEx // first we will pull out the values from the context for the actual parameters if (actualParameters != null) { - List params = StringUtil.split(actualParameters, ","); - Iterator i = params.iterator(); - - while (i.hasNext()) { - Object key = i.next(); - String keyStr = (String) key; - - if (keyStr != null && keyStr.trim().toLowerCase().startsWith("expr:")) { + List<String> params = StringUtil.split(actualParameters, ","); + for (String key : params) { + if (key != null && key.trim().toLowerCase().startsWith("expr:")) { // check for bsh expressions; this does not place values into the context try { - BshUtil.eval(keyStr.trim().substring(5).trim(), context); + BshUtil.eval(key.trim().substring(5).trim(), context); } catch (bsh.EvalError e) { throw new WfException("Bsh evaluation error.", e); } - } else if (keyStr != null && keyStr.trim().toLowerCase().startsWith("name:")) { + } else if (key != null && key.trim().toLowerCase().startsWith("name:")) { // name mapping of context values - List couple = StringUtil.split(keyStr.trim().substring(5).trim(), "="); - String mName = (String) couple.get(0); // mapped name - String cName = (String) couple.get(1); // context name + List<String> couple = StringUtil.split(key.trim().substring(5).trim(), "="); + String mName = couple.get(0); // mapped name + String cName = couple.get(1); // context name // trim out blank space if (mName != null) mName = mName.trim(); @@ -798,12 +772,9 @@ public class WfActivityImpl extends WfEx // the serviceSignature should not limit which parameters are in the actualContext // so instead we will use this signature to pull out values so they do not all have to be defined if (serviceSignature != null) { - Iterator si = serviceSignature.iterator(); - while (si.hasNext()) { - Object key = si.next(); - String keyStr = (String) key; + for (String key : serviceSignature) { if (!actualContext.containsKey(key) && context.containsKey(key)) { - actualContext.put(keyStr, context.get(keyStr)); + actualContext.put(key, context.get(key)); } } } Modified: ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivitySubFlowImplementation.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivitySubFlowImplementation.java?rev=932317&r1=932316&r2=932317&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivitySubFlowImplementation.java (original) +++ ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivitySubFlowImplementation.java Fri Apr 9 09:40:02 2010 @@ -68,7 +68,7 @@ public class WfActivitySubFlowImplementa String actualParameters = subFlow.getString("actualParameters"); GenericResultWaiter waiter = runService(service, actualParameters, null); if (type.equals("WSE_SYNCHR")) { - Map subResult = waiter.waitForResult(); + Map<String, Object> subResult = waiter.waitForResult(); this.setResult(subResult); } setComplete(true); Modified: ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityToolImplementation.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityToolImplementation.java?rev=932317&r1=932316&r2=932317&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityToolImplementation.java (original) +++ ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfActivityToolImplementation.java Fri Apr 9 09:40:02 2010 @@ -19,9 +19,7 @@ package org.ofbiz.workflow.impl; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -49,8 +47,7 @@ public class WfActivityToolImplementatio */ @Override public void run() throws WfException { - Collection tools = null; - //Linea agregada por Oswin Ondarza + List<GenericValue> tools = null; String allParams = ""; try { tools = getActivity().getDefinitionObject().getRelated("WorkflowActivityTool"); @@ -64,36 +61,30 @@ public class WfActivityToolImplementatio if (Debug.verboseOn()) Debug.logVerbose("[WfActivity.runTool] : Running tools (" + tools.size() + ").", module); - List waiters = new ArrayList(); - Iterator i = tools.iterator(); - while (i.hasNext()) { - GenericValue thisTool = (GenericValue) i.next(); + List<GenericResultWaiter> waiters = new ArrayList<GenericResultWaiter>(); + for (GenericValue thisTool : tools) { String serviceName = null; String toolId = thisTool.getString("toolId"); String params = thisTool.getString("actualParameters"); String toolTypeEnumId = thisTool.getString("toolTypeEnumId"); - //Linea agregada por Oswin Ondarza allParams = allParams + "," + params; String extend = thisTool.getString("extendedAttributes"); - Map extendedAttr = StringUtil.strToMap(extend); - if (extendedAttr != null && extendedAttr.containsKey("serviceName")) + Map<String, String> extendedAttr = StringUtil.strToMap(extend); + if (extendedAttr != null && extendedAttr.containsKey("serviceName")) { serviceName = (String) extendedAttr.get("serviceName"); + } - serviceName = serviceName != null ? serviceName : (toolTypeEnumId.equals("WTT_APPLICATION") ? - "wfActivateApplication" : toolId); + serviceName = serviceName != null ? serviceName : (toolTypeEnumId.equals("WTT_APPLICATION") ? "wfActivateApplication" : toolId); waiters.add(runService(serviceName, params, extend)); } while (waiters.size() > 0) { - Iterator wi = waiters.iterator(); - Collection remove = new ArrayList(); - while (wi.hasNext()) { - GenericResultWaiter thw = (GenericResultWaiter) wi.next(); - + List<GenericResultWaiter> remove = new ArrayList<GenericResultWaiter>(); + for (GenericResultWaiter thw : waiters) { if (thw.isCompleted()) { - Map thwResult = null; + Map<String, Object> thwResult = null; if (thw.status() == GenericResultWaiter.SERVICE_FINISHED) { thwResult = thw.getResult(); Debug.logVerbose("Service finished.", module); @@ -123,18 +114,15 @@ public class WfActivityToolImplementatio setComplete(true); } - protected void setResult(Map result, String allParams) { - Map newResult = new HashMap(result); - List params = StringUtil.split(allParams, ","); - Iterator i = params.iterator(); - while (i.hasNext()) { - Object keyExpr = i.next(); - String keyExprStr = (String) keyExpr; - + protected void setResult(Map<String, Object> result, String allParams) { + Map<String, Object> newResult = new HashMap<String, Object>(result); + List<String> params = StringUtil.split(allParams, ","); + + for (String keyExprStr : params) { if (keyExprStr != null && keyExprStr.trim().toLowerCase().startsWith("name:")) { - List couple = StringUtil.split(keyExprStr.trim().substring(5).trim(), "="); - Object keyParam = ((String) couple.get(0)).trim(); - Object keyNewParam = ((String) couple.get(1)).trim(); + List<String> couple = StringUtil.split(keyExprStr.trim().substring(5).trim(), "="); + String keyParam = (couple.get(0)).trim(); + String keyNewParam = (couple.get(1)).trim(); if (result.containsKey(keyParam)) { newResult.put(keyNewParam, result.get(keyParam)); Modified: ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfAssignmentImpl.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfAssignmentImpl.java?rev=932317&r1=932316&r2=932317&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfAssignmentImpl.java (original) +++ ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfAssignmentImpl.java Fri Apr 9 09:40:02 2010 @@ -75,7 +75,7 @@ public class WfAssignmentImpl implements throw new WfException("From date cannot be null"); GenericValue value = null; - Map fields = new HashMap(); + Map<String, Object> fields = new HashMap<String, Object>(); fields.put("workEffortId", workEffortId); fields.put("partyId", partyId); @@ -122,7 +122,7 @@ public class WfAssignmentImpl implements // check for existing accepted assignment if (!activity.state().equals("open.not_running.not_started")) { // activity already running all assignments must be delegated in order to accept - Iterator ai = activity.getIteratorAssignment(); + Iterator<WfAssignment> ai = activity.getIteratorAssignment(); while (ai.hasNext() && allDelegated) { WfAssignment a = (WfAssignment) ai.next(); @@ -137,7 +137,7 @@ public class WfAssignmentImpl implements } else { // activity not running, auto change all assignments to delegated status Debug.logVerbose("[WfAssignment.accept] : setting other assignments to delegated status.", module); - Iterator ai = activity.getIteratorAssignment(); + Iterator<WfAssignment> ai = activity.getIteratorAssignment(); while (ai.hasNext()) { WfAssignment a = (WfAssignment) ai.next(); @@ -152,7 +152,7 @@ public class WfAssignmentImpl implements /** * @see org.ofbiz.workflow.WfAssignment#setResult(java.util.Map) */ - public void setResult(Map results) throws WfException { + public void setResult(Map<String, Object> results) throws WfException { activity.setResult(results); } @@ -258,7 +258,7 @@ public class WfAssignmentImpl implements private GenericValue valueObject() throws WfException { GenericValue value = null; - Map fields = new HashMap(); + Map<String, Object> fields = new HashMap<String, Object>(); fields.put("workEffortId", activity.runtimeKey()); fields.put("partyId", resource.resourcePartyId()); Modified: ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfExecutionObjectImpl.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfExecutionObjectImpl.java?rev=932317&r1=932316&r2=932317&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfExecutionObjectImpl.java (original) +++ ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfExecutionObjectImpl.java Fri Apr 9 09:40:02 2010 @@ -32,6 +32,7 @@ import java.util.Map; import org.ofbiz.base.util.BshUtil; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.ObjectType; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.string.FlexibleStringExpander; @@ -75,7 +76,7 @@ public abstract class WfExecutionObjectI protected String activityId = null; protected String workEffortId = null; protected Delegator delegator = null; - protected List history = null; + protected List<?> history = null; public WfExecutionObjectImpl(GenericValue valueObject, String parentId) throws WfException { this.packageId = valueObject.getString("packageId"); @@ -111,7 +112,7 @@ public abstract class WfExecutionObjectI GenericValue dataObject = null; workEffortId = getDelegator().getNextSeqId("WorkEffort"); - Map dataMap = new HashMap(); + Map<String, Object> dataMap = new HashMap<String, Object>(); String weType = activityId != null ? "ACTIVITY" : "WORK_FLOW"; dataMap.put("workEffortId", workEffortId); @@ -147,7 +148,7 @@ public abstract class WfExecutionObjectI } } - protected void parseDescriptions(Map parseContext) throws WfException { + protected void parseDescriptions(Map<String, Object> parseContext) throws WfException { GenericValue runtime = getRuntimeObject(); String name = runtime.getString("workEffortName"); String desc = runtime.getString("description"); @@ -242,14 +243,14 @@ public abstract class WfExecutionObjectI /** * @see org.ofbiz.workflow.WfExecutionObject#validStates() */ - public List validStates() throws WfException { + public List<String> validStates() throws WfException { String statesArr[] = {"open.running", "open.not_running.not_started", "open.not_running.suspended", "closed.completed", "closed.terminated", "closed.aborted"}; - ArrayList possibleStates = new ArrayList(Arrays.asList(statesArr)); + ArrayList<String> possibleStates = new ArrayList<String>(Arrays.asList(statesArr)); String currentState = state(); if (currentState.startsWith("closed")) - return new ArrayList(); + return new ArrayList<String>(); if (!currentState.startsWith("open")) throw new WfException("Currently in an unknown state."); if (currentState.equals("open.running")) { @@ -271,7 +272,7 @@ public abstract class WfExecutionObjectI possibleStates.remove("closed.terminated"); return possibleStates; } - return new ArrayList(); + return new ArrayList<String>(); } /** @@ -304,7 +305,7 @@ public abstract class WfExecutionObjectI /** * @see org.ofbiz.workflow.WfExecutionObject#whileOpenType() */ - public List whileOpenType() throws WfException { + public List<String> whileOpenType() throws WfException { String[] list = {"running", "not_running"}; return Arrays.asList(list); @@ -313,7 +314,7 @@ public abstract class WfExecutionObjectI /** * @see org.ofbiz.workflow.WfExecutionObject#whyNotRunningType() */ - public List whyNotRunningType() throws WfException { + public List<String> whyNotRunningType() throws WfException { String[] list = {"not_started", "suspended"}; return Arrays.asList(list); @@ -346,7 +347,7 @@ public abstract class WfExecutionObjectI /** * @see org.ofbiz.workflow.WfExecutionObject#setProcessContext(java.util.Map) */ - public void setProcessContext(Map newValue) throws WfException, InvalidData, UpdateNotAllowed { + public void setProcessContext(Map<String, Object> newValue) throws WfException, InvalidData, UpdateNotAllowed { setSerializedData(newValue); } @@ -377,14 +378,14 @@ public abstract class WfExecutionObjectI /** * @see org.ofbiz.workflow.WfExecutionObject#processContext() */ - public Map processContext() throws WfException { + public Map<String, Object> processContext() throws WfException { return getContext(); } /** * @see org.ofbiz.workflow.WfExecutionObject#workflowStateType() */ - public List workflowStateType() throws WfException { + public List<String> workflowStateType() throws WfException { String[] list = {"open", "closed"}; return Arrays.asList(list); } @@ -437,7 +438,7 @@ public abstract class WfExecutionObjectI /** * @see org.ofbiz.workflow.WfExecutionObject#getSequenceHistory(int) */ - public List getSequenceHistory(int maxNumber) throws WfException, + public List<?> getSequenceHistory(int maxNumber) throws WfException, HistoryNotAvailable { return history; } @@ -445,8 +446,7 @@ public abstract class WfExecutionObjectI /** * @see org.ofbiz.workflow.WfExecutionObject#getIteratorHistory(java.lang.String, java.util.Map) */ - public Iterator getIteratorHistory(String query, - Map namesInQuery) throws WfException, HistoryNotAvailable { + public Iterator<?> getIteratorHistory(String query, Map<String, Object> namesInQuery) throws WfException, HistoryNotAvailable { return history.iterator(); } @@ -470,7 +470,7 @@ public abstract class WfExecutionObjectI /** * @see org.ofbiz.workflow.WfExecutionObject#howClosedType() */ - public List howClosedType() throws WfException { + public List<String> howClosedType() throws WfException { String[] list = {"completed", "terminated", "aborted"}; return Arrays.asList(list); @@ -518,7 +518,7 @@ public abstract class WfExecutionObjectI public GenericValue getDefinitionObject() throws WfException { String entityName = activityId != null ? "WorkflowActivity" : "WorkflowProcess"; GenericValue value = null; - Map fields = UtilMisc.toMap("packageId", packageId, "packageVersion", packageVersion, "processId", processId, + Map<String, Object> fields = UtilMisc.toMap("packageId", (Object) packageId, "packageVersion", packageVersion, "processId", processId, "processVersion", processVersion); if (activityId != null) @@ -555,7 +555,7 @@ public abstract class WfExecutionObjectI * @param value The value to serialize and set * @throws WfException */ - protected void setSerializedData(Map value) throws WfException, InvalidData { + protected void setSerializedData(Map<String, Object> value) throws WfException, InvalidData { GenericValue runtimeData = null; GenericValue dataObject = getRuntimeObject(); @@ -596,10 +596,10 @@ public abstract class WfExecutionObjectI return GenericDispatcher.getLocalDispatcher(dispatcherName, getDelegator()); } - private Map getContext() throws WfException { + private Map<String, Object> getContext() throws WfException { GenericValue dataObject = getRuntimeObject(); String contextXML = null; - Map context = null; + Map<String, Object> context = null; if (dataObject.get("runtimeDataId") == null) return context; @@ -613,7 +613,7 @@ public abstract class WfExecutionObjectI // De-serialize the context if (contextXML != null) { try { - context = (Map) XmlSerializer.deserialize(contextXML, getDelegator()); + context = UtilGenerics.checkMap(XmlSerializer.deserialize(contextXML, getDelegator())); } catch (SerializeException e) { throw new WfException(e.getMessage(), e); } catch (IOException e) { @@ -642,7 +642,7 @@ public abstract class WfExecutionObjectI * @return The result of the evaluation (True/False) * @throws WfException */ - protected boolean evalConditionClass(String className, String expression, Map context, Map attrs) throws WfException { + protected boolean evalConditionClass(String className, String expression, Map<String, Object> context, Map<String, String> attrs) throws WfException { // attempt to load and instance of the class Object conditionObject = null; try { @@ -692,7 +692,7 @@ public abstract class WfExecutionObjectI * @return The result of the evaluation (True/False) * @throws WfException */ - protected boolean evalBshCondition(String expression, Map context) throws WfException { + protected boolean evalBshCondition(String expression, Map<String, Object> context) throws WfException { if (UtilValidate.isEmpty(expression)) { Debug.logVerbose("Null or empty expression, returning true.", module); return true; Modified: ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfProcessImpl.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfProcessImpl.java?rev=932317&r1=932316&r2=932317&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfProcessImpl.java (original) +++ ofbiz/trunk/specialpurpose/workflow/src/org/ofbiz/workflow/impl/WfProcessImpl.java Fri Apr 9 09:40:02 2010 @@ -19,7 +19,6 @@ package org.ofbiz.workflow.impl; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -89,7 +88,7 @@ public class WfProcessImpl extends WfExe private void init() throws WfException { // since we are a process we don't have a context yet // get the context to use with parsing descriptions from the manager - Map context = manager.getInitialContext(); + Map<String, Object> context = manager.getInitialContext(); this.parseDescriptions(context); } @@ -105,9 +104,9 @@ public class WfProcessImpl extends WfExe /** * @see org.ofbiz.workflow.WfProcess#getSequenceStep(int) */ - public List getSequenceStep(int maxNumber) throws WfException { + public List<WfActivity> getSequenceStep(int maxNumber) throws WfException { if (maxNumber > 0) - return new ArrayList(activeSteps().subList(0, maxNumber - 1)); + return new ArrayList<WfActivity>(activeSteps().subList(0, maxNumber - 1)); return activeSteps(); } @@ -119,9 +118,7 @@ public class WfProcessImpl extends WfExe super.abort(); // cancel the active activities - Iterator activities = this.activeSteps().iterator(); - while (activities.hasNext()) { - WfActivity activity = (WfActivity) activities.next(); + for (WfActivity activity : this.activeSteps()) { activity.abort(); } } @@ -151,7 +148,7 @@ public class WfProcessImpl extends WfExe try { if (activityId != null) { GenericValue processDef = getDefinitionObject(); - Map fields = UtilMisc.toMap("packageId", processDef.getString("packageId"), "packageVersion", + Map<String, Object> fields = UtilMisc.toMap("packageId", (Object) processDef.getString("packageId"), "packageVersion", processDef.getString("packageVersion"), "processId", processDef.getString("processId"), "processVersion", processDef.getString("processVersion"), "activityId", activityId); start = getDelegator().findByPrimaryKey("WorkflowActivity", fields); @@ -202,7 +199,7 @@ public class WfProcessImpl extends WfExe /** * @see org.ofbiz.workflow.WfProcess#getIteratorStep() */ - public Iterator getIteratorStep() throws WfException { + public Iterator<WfActivity> getIteratorStep() throws WfException { return activeSteps().iterator(); } @@ -216,13 +213,10 @@ public class WfProcessImpl extends WfExe /** * @see org.ofbiz.workflow.WfProcess#getActivitiesInState(java.lang.String) */ - public Iterator getActivitiesInState(String state) throws WfException, InvalidState { - ArrayList res = new ArrayList(); - Iterator i = getIteratorStep(); - - while (i.hasNext()) { - WfActivity a = (WfActivity) i.next(); - + public Iterator<WfActivity> getActivitiesInState(String state) throws WfException, InvalidState { + List<WfActivity> res = new ArrayList<WfActivity>(); + + for (WfActivity a : activeSteps()) { if (a.state().equals(state)) res.add(a); } @@ -232,18 +226,15 @@ public class WfProcessImpl extends WfExe /** * @see org.ofbiz.workflow.WfProcess#result() */ - public Map result() throws WfException, ResultNotAvailable { - Map resultSig = manager().resultSignature(); - Map results = new HashMap(); - Map context = processContext(); + public Map<String, Object> result() throws WfException, ResultNotAvailable { + Map<String, Object> resultSig = manager().resultSignature(); + Map<String, Object> results = new HashMap<String, Object>(); + Map<String, Object> context = processContext(); if (resultSig != null) { - Set resultKeys = resultSig.keySet(); - Iterator i = resultKeys.iterator(); - - while (i.hasNext()) { - Object key = i.next(); - + Set<String> resultKeys = resultSig.keySet(); + + for (String key : resultKeys) { if (context.containsKey(key)) results.put(key, context.get(key)); } @@ -261,8 +252,8 @@ public class WfProcessImpl extends WfExe /** * @see org.ofbiz.workflow.WfProcess#receiveResults(org.ofbiz.workflow.WfActivity, java.util.Map) */ - public synchronized void receiveResults(WfActivity activity, Map results) throws WfException, InvalidData { - Map context = processContext(); + public synchronized void receiveResults(WfActivity activity, Map<String, Object> results) throws WfException, InvalidData { + Map<String, Object> context = processContext(); context.putAll(results); setSerializedData(context); } @@ -287,14 +278,10 @@ public class WfProcessImpl extends WfExe // Queues the next activities for processing private void queueNext(WfActivity fromActivity) throws WfException { - List nextTrans = getTransFrom(fromActivity); + List<GenericValue> nextTrans = getTransFrom(fromActivity); if (nextTrans.size() > 0) { - Iterator i = nextTrans.iterator(); - - while (i.hasNext()) { - GenericValue trans = (GenericValue) i.next(); - + for (GenericValue trans : nextTrans) { // Get the activity definition GenericValue toActivity = null; @@ -330,8 +317,8 @@ public class WfProcessImpl extends WfExe GenericValue transition) throws WfException { // get all TO transitions to this activity GenericValue dataObject = getRuntimeObject(); - Collection toTrans = null; - + + List<GenericValue> toTrans = null; try { toTrans = toActivity.getRelated("ToWorkflowTransition"); } catch (GenericEntityException e) { @@ -339,10 +326,9 @@ public class WfProcessImpl extends WfExe } // get a list of followed transition to this activity - Collection followed = null; - + List<GenericValue> followed = null; try { - Map fields = new HashMap(); + Map<String, Object> fields = new HashMap<String, Object>(); fields.put("processWorkEffortId", dataObject.getString("workEffortId")); fields.put("toActivityId", toActivity.getString("activityId")); followed = getDelegator().findByAnd("WorkEffortTransBox", fields); @@ -358,7 +344,7 @@ public class WfProcessImpl extends WfExe Debug.logVerbose("[WfProcess.joinTransition] : All transitions have followed.", module); startActivity(toActivity); try { - Map fields = new HashMap(); + Map<String, Object> fields = new HashMap<String, Object>(); fields.put("processWorkEffortId", dataObject.getString("workEffortId")); fields.put("toActivityId", toActivity.getString("activityId")); getDelegator().removeByAnd("WorkEffortTransBox", fields); @@ -368,7 +354,7 @@ public class WfProcessImpl extends WfExe } else { Debug.logVerbose("[WfProcess.joinTransition] : Waiting for transitions to finish.", module); try { - Map fields = new HashMap(); + Map<String, Object> fields = new HashMap<String, Object>(); fields.put("processWorkEffortId", dataObject.getString("workEffortId")); fields.put("toActivityId", toActivity.getString("activityId")); fields.put("transitionId", transition.getString("transitionId")); @@ -418,13 +404,13 @@ public class WfProcessImpl extends WfExe } // Determine the next activity or activities - private List getTransFrom(WfActivity fromActivity) throws WfException { - List transList = new ArrayList(); + private List<GenericValue> getTransFrom(WfActivity fromActivity) throws WfException { + List<GenericValue> transList = new ArrayList<GenericValue>(); + // get the from transitions - Collection fromCol = null; - + List<GenericValue> fromTransitions = null; try { - fromCol = fromActivity.getDefinitionObject().getRelated("FromWorkflowTransition"); + fromTransitions = fromActivity.getDefinitionObject().getRelated("FromWorkflowTransition"); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } @@ -442,10 +428,7 @@ public class WfProcessImpl extends WfExe GenericValue otherwise = null; // iterate through the possible transitions - Iterator fromIt = fromCol.iterator(); - while (fromIt.hasNext()) { - GenericValue transition = (GenericValue) fromIt.next(); - + for (GenericValue transition : fromTransitions) { // if this transition is OTHERWISE store it for later and continue on if (transition.get("conditionTypeEnumId") != null && transition.getString("conditionTypeEnumId").equals("WTC_OTHERWISE")) { // there should be only one of these, if there is more then one we will use the last one defined @@ -457,7 +440,7 @@ public class WfProcessImpl extends WfExe String conditionBody = transition.getString("conditionExpr"); // get the extended attributes for the transition - Map extendedAttr = StringUtil.strToMap(transition.getString("extendedAttributes")); + Map<String, String> extendedAttr = StringUtil.strToMap(transition.getString("extendedAttributes")); // check for a conditionClassName attribute if exists use it if (extendedAttr != null && extendedAttr.get("conditionClassName") != null) { @@ -487,18 +470,6 @@ public class WfProcessImpl extends WfExe return transList; } - // Gets a specific activity by its key - private WfActivity getActivity(String key) throws WfException { - Iterator i = getIteratorStep(); - - while (i.hasNext()) { - WfActivity a = (WfActivity) i.next(); - if (a.key().equals(key)) - return a; - } - throw new WfException("Activity not an active member of this process"); - } - // Complete this workflow private void finishProcess() throws WfException { changeState("closed.completed"); @@ -515,25 +486,23 @@ public class WfProcessImpl extends WfExe } // Get the active process activities - private List activeSteps() throws WfException { - List steps = new ArrayList(); - Collection c = null; + private List<WfActivity> activeSteps() throws WfException { + List<WfActivity> steps = new ArrayList<WfActivity>(); + List<GenericValue> workEffortList = null; try { - c = getDelegator().findByAnd("WorkEffort", UtilMisc.toMap("workEffortParentId", runtimeKey())); + workEffortList = getDelegator().findByAnd("WorkEffort", UtilMisc.toMap("workEffortParentId", runtimeKey())); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } - if (c == null) + if (workEffortList == null) { return steps; - Iterator i = c.iterator(); - - while (i.hasNext()) { - GenericValue v = (GenericValue) i.next(); - - if (v.get("currentStatusId") != null && - WfUtil.getOMGStatus(v.getString("currentStatusId")).startsWith("open.")) - steps.add(WfFactory.getWfActivity(getDelegator(), v.getString("workEffortId"))); + } + + for (GenericValue workEffort : workEffortList) { + if (workEffort.get("currentStatusId") != null && + WfUtil.getOMGStatus(workEffort.getString("currentStatusId")).startsWith("open.")) + steps.add(WfFactory.getWfActivity(getDelegator(), workEffort.getString("workEffortId"))); } return steps; } |
Free forum by Nabble | Edit this page |