svn commit: r686251 - in /ofbiz/trunk/framework/minilang/src: META-INF/services/ org/ofbiz/minilang/method/conditional/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r686251 - in /ofbiz/trunk/framework/minilang/src: META-INF/services/ org/ofbiz/minilang/method/conditional/

doogie-3
Author: doogie
Date: Fri Aug 15 08:29:29 2008
New Revision: 686251

URL: http://svn.apache.org/viewvc?rev=686251&view=rev
Log:
More use of ServiceRegistry.

Added:
    ofbiz/trunk/framework/minilang/src/META-INF/services/org.ofbiz.minilang.method.conditional.ConditionalFactory
Modified:
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CombinedCondition.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareCondition.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareFieldCondition.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ConditionalFactory.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/EmptyCondition.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/HasPermissionCondition.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java

Added: ofbiz/trunk/framework/minilang/src/META-INF/services/org.ofbiz.minilang.method.conditional.ConditionalFactory
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/META-INF/services/org.ofbiz.minilang.method.conditional.ConditionalFactory?rev=686251&view=auto
==============================================================================
--- ofbiz/trunk/framework/minilang/src/META-INF/services/org.ofbiz.minilang.method.conditional.ConditionalFactory (added)
+++ ofbiz/trunk/framework/minilang/src/META-INF/services/org.ofbiz.minilang.method.conditional.ConditionalFactory Fri Aug 15 08:29:29 2008
@@ -0,0 +1,11 @@
+org.ofbiz.minilang.method.conditional.CombinedCondition$OrConditionFactory
+org.ofbiz.minilang.method.conditional.CombinedCondition$XorConditionFactory
+org.ofbiz.minilang.method.conditional.CombinedCondition$AndConditionFactory
+org.ofbiz.minilang.method.conditional.CombinedCondition$NotConditionFactory
+org.ofbiz.minilang.method.conditional.CompareCondition$CompareConditionFactory
+org.ofbiz.minilang.method.conditional.CompareFieldCondition$CompareFieldConditionFactory
+org.ofbiz.minilang.method.conditional.EmptyCondition$EmptyConditionFactory
+org.ofbiz.minilang.method.conditional.HasPermissionCondition$HasPermissionConditionFactory
+org.ofbiz.minilang.method.conditional.RegexpCondition$RegexpConditionFactory
+org.ofbiz.minilang.method.conditional.ValidateMethodCondition$ValidateMethodConditionFactory
+

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CombinedCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CombinedCondition.java?rev=686251&r1=686250&r2=686251&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CombinedCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CombinedCondition.java Fri Aug 15 08:29:29 2008
@@ -29,6 +29,45 @@
  * Implements generic combining conditions such as or, and, etc.
  */
 public class CombinedCondition implements Conditional {
+    public static final class OrConditionFactory extends ConditionalFactory<CombinedCondition> {
+        public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) {
+            return new CombinedCondition(element, OR, simpleMethod);
+        }
+
+        public String getName() {
+            return "or";
+        }
+    }
+
+    public static final class XorConditionFactory extends ConditionalFactory<CombinedCondition> {
+        public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) {
+            return new CombinedCondition(element, XOR, simpleMethod);
+        }
+
+        public String getName() {
+            return "xor";
+        }
+    }
+
+    public static final class AndConditionFactory extends ConditionalFactory<CombinedCondition> {
+        public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) {
+            return new CombinedCondition(element, AND, simpleMethod);
+        }
+
+        public String getName() {
+            return "and";
+        }
+    }
+
+    public static final class NotConditionFactory extends ConditionalFactory<CombinedCondition> {
+        public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) {
+            return new CombinedCondition(element, NOT, simpleMethod);
+        }
+
+        public String getName() {
+            return "not";
+        }
+    }
     
     public static final int OR = 1;
     public static final int XOR = 2;

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareCondition.java?rev=686251&r1=686250&r2=686251&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareCondition.java Fri Aug 15 08:29:29 2008
@@ -31,6 +31,16 @@
  * Implements compare to a constant condition.
  */
 public class CompareCondition implements Conditional {
+    public static final class CompareConditionFactory extends ConditionalFactory<CompareCondition> {
+        public CompareCondition createCondition(Element element, SimpleMethod simpleMethod) {
+            return new CompareCondition(element, simpleMethod);
+        }
+
+        public String getName() {
+            return "if-compare";
+        }
+    }
+
     
     public static final String module = CompareCondition.class.getName();
     

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareFieldCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareFieldCondition.java?rev=686251&r1=686250&r2=686251&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareFieldCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareFieldCondition.java Fri Aug 15 08:29:29 2008
@@ -30,6 +30,16 @@
  * Implements compare to a field condition.
  */
 public class CompareFieldCondition implements Conditional {
+    public static final class CompareFieldConditionFactory extends ConditionalFactory<CompareFieldCondition> {
+        public CompareFieldCondition createCondition(Element element, SimpleMethod simpleMethod) {
+            return new CompareFieldCondition(element, simpleMethod);
+        }
+
+        public String getName() {
+            return "if-compare-field";
+        }
+    }
+
     
     public static final String module = CompareFieldCondition.class.getName();
     

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ConditionalFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ConditionalFactory.java?rev=686251&r1=686250&r2=686251&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ConditionalFactory.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ConditionalFactory.java Fri Aug 15 08:29:29 2008
@@ -18,6 +18,13 @@
  *******************************************************************************/
 package org.ofbiz.minilang.method.conditional;
 
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.imageio.spi.ServiceRegistry;
+
 import org.w3c.dom.*;
 import org.ofbiz.base.util.*;
 import org.ofbiz.minilang.*;
@@ -25,36 +32,32 @@
 /**
  * Creates Conditional objects according to the element that is passed.
  */
-public class ConditionalFactory {
+public abstract class ConditionalFactory<C extends Conditional> {
+    private static final Map<String, ConditionalFactory> conditionalFactories;
+    static {
+        Map<String, ConditionalFactory> factories = new HashMap<String, ConditionalFactory>();
+        Iterator<ConditionalFactory> it = ServiceRegistry.lookupProviders(ConditionalFactory.class, ConditionalFactory.class.getClassLoader());
+        while (it.hasNext()) {
+            ConditionalFactory factory = it.next();
+            factories.put(factory.getName(), factory);
+        }
+        conditionalFactories = Collections.unmodifiableMap(factories);
+    }
     
     public static final String module = ConditionalFactory.class.getName();
     
     public static Conditional makeConditional(Element element, SimpleMethod simpleMethod) {
         String tagName = element.getTagName();
         
-        if ("or".equals(tagName)) {
-            return new CombinedCondition(element, CombinedCondition.OR, simpleMethod);
-        } else if ("xor".equals(tagName)) {
-            return new CombinedCondition(element, CombinedCondition.XOR, simpleMethod);
-        } else if ("and".equals(tagName)) {
-            return new CombinedCondition(element, CombinedCondition.AND, simpleMethod);
-        } else if ("not".equals(tagName)) {
-            return new CombinedCondition(element, CombinedCondition.NOT, simpleMethod);
-        } else if ("if-validate-method".equals(tagName)) {
-            return new ValidateMethodCondition(element);
-        } else if ("if-compare".equals(tagName)) {
-            return new CompareCondition(element, simpleMethod);
-        } else if ("if-compare-field".equals(tagName)) {
-            return new CompareFieldCondition(element, simpleMethod);
-        } else if ("if-empty".equals(tagName)) {
-            return new EmptyCondition(element, simpleMethod);
-        } else if ("if-regexp".equals(tagName)) {
-            return new RegexpCondition(element, simpleMethod);
-        } else if ("if-has-permission".equals(tagName)) {
-            return new HasPermissionCondition(element, simpleMethod);
+        ConditionalFactory factory = conditionalFactories.get(tagName);
+        if (factory != null) {
+            return factory.createCondition(element, simpleMethod);
         } else {
             Debug.logWarning("Found an unknown if condition: " + tagName, module);
             return null;
         }
     }
+
+    public abstract C createCondition(Element element, SimpleMethod simpleMethod);
+    public abstract String getName();
 }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/EmptyCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/EmptyCondition.java?rev=686251&r1=686250&r2=686251&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/EmptyCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/EmptyCondition.java Fri Aug 15 08:29:29 2008
@@ -28,6 +28,16 @@
  * Implements compare to a constant condition.
  */
 public class EmptyCondition implements Conditional {
+    public static final class EmptyConditionFactory extends ConditionalFactory<EmptyCondition> {
+        public EmptyCondition createCondition(Element element, SimpleMethod simpleMethod) {
+            return new EmptyCondition(element, simpleMethod);
+        }
+
+        public String getName() {
+            return "if-empty";
+        }
+    }
+
     
     public static final String module = EmptyCondition.class.getName();
     

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/HasPermissionCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/HasPermissionCondition.java?rev=686251&r1=686250&r2=686251&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/HasPermissionCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/HasPermissionCondition.java Fri Aug 15 08:29:29 2008
@@ -29,6 +29,16 @@
  * Implements compare to a constant condition.
  */
 public class HasPermissionCondition implements Conditional {
+    public static final class HasPermissionConditionFactory extends ConditionalFactory<HasPermissionCondition> {
+        public HasPermissionCondition createCondition(Element element, SimpleMethod simpleMethod) {
+            return new HasPermissionCondition(element, simpleMethod);
+        }
+
+        public String getName() {
+            return "if-has-permission";
+        }
+    }
+
     
     SimpleMethod simpleMethod;
     

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java?rev=686251&r1=686250&r2=686251&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java Fri Aug 15 08:29:29 2008
@@ -43,6 +43,16 @@
  * Implements compare to a constant condition.
  */
 public class RegexpCondition implements Conditional {
+    public static final class RegexpConditionFactory extends ConditionalFactory<RegexpCondition> {
+        public RegexpCondition createCondition(Element element, SimpleMethod simpleMethod) {
+            return new RegexpCondition(element, simpleMethod);
+        }
+
+        public String getName() {
+            return "if-regexp";
+        }
+    }
+
     
     public static final String module = RegexpCondition.class.getName();
     

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java?rev=686251&r1=686250&r2=686251&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java Fri Aug 15 08:29:29 2008
@@ -22,12 +22,23 @@
 import java.lang.reflect.*;
 import org.w3c.dom.*;
 import org.ofbiz.base.util.*;
+import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.minilang.method.*;
 
 /**
  * Implements validate method condition.
  */
 public class ValidateMethodCondition implements Conditional {
+    public static final class ValidateMethodConditionFactory extends ConditionalFactory<ValidateMethodCondition> {
+        public ValidateMethodCondition createCondition(Element element, SimpleMethod simpleMethod) {
+            return new ValidateMethodCondition(element);
+        }
+
+        public String getName() {
+            return "if-validate-method";
+        }
+    }
+
     
     public static final String module = ValidateMethodCondition.class.getName();