|
Author: adrianc
Date: Mon Feb 18 00:10:25 2013 New Revision: 1447108 URL: http://svn.apache.org/r1447108 Log: Small enhancements to EntityEcaRule.java: parse <eca> element only once, improve thread safety, add some accessor methods. Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java?rev=1447108&r1=1447107&r2=1447108&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java Mon Feb 18 00:10:25 2013 @@ -18,12 +18,12 @@ *******************************************************************************/ package org.ofbiz.entityext.eca; -import java.util.HashSet; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; -import javolution.util.FastList; import javolution.util.FastMap; import org.ofbiz.base.util.Debug; @@ -34,54 +34,47 @@ import org.ofbiz.service.DispatchContext import org.w3c.dom.Element; /** - * EntityEcaRule + * Entity event-condition-action rule. */ @SuppressWarnings("serial") public final class EntityEcaRule implements java.io.Serializable { public static final String module = EntityEcaRule.class.getName(); - private static final Set<String> nameSet = new HashSet<String>(2); - static { - nameSet.add("set"); - nameSet.add("action"); - } - - protected final String entityName; - protected final String operationName; - protected final String eventName; - protected final boolean runOnError; - protected final List<EntityEcaCondition> conditions = FastList.newInstance(); - protected final List<Object> actionsAndSets = FastList.newInstance(); - protected boolean enabled = true; + private final String entityName; + private final String operationName; + private final String eventName; + private final boolean runOnError; + private final List<EntityEcaCondition> conditions; + private final List<Object> actionsAndSets; + private boolean enabled = true; public EntityEcaRule(Element eca) { this.entityName = eca.getAttribute("entity"); this.operationName = eca.getAttribute("operation"); this.eventName = eca.getAttribute("event"); this.runOnError = "true".equals(eca.getAttribute("run-on-error")); - - for (Element element: UtilXml.childElementList(eca, "condition")) { - conditions.add(new EntityEcaCondition(element, true)); - } - - for (Element element: UtilXml.childElementList(eca, "condition-field")) { - conditions.add(new EntityEcaCondition(element, false)); - } - - if (Debug.verboseOn()) { - Debug.logVerbose("Conditions: " + conditions, module); - } - - for (Element actionOrSetElement: UtilXml.childElementList(eca, nameSet)) { - if ("action".equals(actionOrSetElement.getNodeName())) { - this.actionsAndSets.add(new EntityEcaAction(actionOrSetElement)); + ArrayList<EntityEcaCondition> conditions = new ArrayList<EntityEcaCondition>(); + ArrayList<Object> actionsAndSets = new ArrayList<Object>(); + for (Element element: UtilXml.childElementList(eca)) { + if ("condition".equals(element.getNodeName())) { + conditions.add(new EntityEcaCondition(element, true)); + } else if ("condition-field".equals(element.getNodeName())) { + conditions.add(new EntityEcaCondition(element, false)); + } else if ("action".equals(element.getNodeName())) { + actionsAndSets.add(new EntityEcaAction(element)); + } else if ("set".equals(element.getNodeName())) { + actionsAndSets.add(new EntityEcaSetField(element)); } else { - this.actionsAndSets.add(new EntityEcaSetField(actionOrSetElement)); + Debug.logWarning("Invalid eca child element " + element.getNodeName(), module); } } - + conditions.trimToSize(); + this.conditions = Collections.unmodifiableList(conditions); + actionsAndSets.trimToSize(); + this.actionsAndSets = Collections.unmodifiableList(actionsAndSets); if (Debug.verboseOn()) { + Debug.logVerbose("Conditions: " + conditions, module); Debug.logVerbose("actions and sets (intermixed): " + actionsAndSets, module); } } @@ -102,6 +95,14 @@ public final class EntityEcaRule impleme return this.runOnError; } + public List<Object> getActionsAndSets() { + return this.actionsAndSets; + } + + public List<EntityEcaCondition> getConditions() { + return this.conditions; + } + public void eval(String currentOperation, DispatchContext dctx, GenericEntity value, boolean isError, Set<String> actionsRun) throws GenericEntityException { if (!enabled) { Debug.logInfo("Entity ECA [" + this.entityName + "] on [" + this.eventName + "] is disabled; not running.", module); @@ -148,6 +149,10 @@ public final class EntityEcaRule impleme } } + /** + * @deprecated Not thread-safe, no replacement. + * @param enabled + */ public void setEnabled(boolean enabled) { this.enabled = enabled; } |
| Free forum by Nabble | Edit this page |
