You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2008/08/15 17:29:30 UTC

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

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();
     



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

Posted by Adam Heath <do...@brainfood.com>.
Jacopo Cappellato wrote:
> On Aug 15, 2008, at 5:42 PM, Adam Heath wrote:
> 
>> Jacopo Cappellato wrote:
>>
>>> please remember the License header and the svn properties (still 
>>> missing from the last new file you added to the repository).
>>
>> You're right, I forgot to add it to *this* new file; but I already did 
>> it for the last one.
>>
> 
> Yeah, I noticed the fix for the license... I was just speaking about the 
> svn properities for the old file.
> 
> The best thing to do is to load the svn config file in your user home, 
> so that the standard svn properties will be automatically added to all 
> the new files you commit; you can find a link to our official config 
> file (and the simple instructions to use it) here:

Ew.  That's bad.  I hate that svn and svk don't have per-checkout config 
settings.

So, I wrote a program to automate it.

==
mkdir $HOME/bin
PATH=$HOME/bin:$PATH
cp $attachments/svk $HOME/bin/svk
cp $attachments/.svn-props.txt $ofbiz_checkout_root/.svn-props.txt
==

This should also work for svn(by copying the script and naming it svn 
instead), but I haven't tested that.  I haven't tested it on anything 
other than debian linux.  The only odd thing is does it call 
/bin/readlink, but most systems should already have that.

If others like this script, then we could check in that .svn-props.txt, 
and the binary.  For now, I'll keep them local.

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

Posted by Jacopo Cappellato <ja...@gmail.com>.
On Aug 15, 2008, at 5:42 PM, Adam Heath wrote:

> Jacopo Cappellato wrote:
>
>> please remember the License header and the svn properties (still  
>> missing from the last new file you added to the repository).
>
> You're right, I forgot to add it to *this* new file; but I already  
> did it for the last one.
>

Yeah, I noticed the fix for the license... I was just speaking about  
the svn properities for the old file.

The best thing to do is to load the svn config file in your user home,  
so that the standard svn properties will be automatically added to all  
the new files you commit; you can find a link to our official config  
file (and the simple instructions to use it) here:

  http://docs.ofbiz.org/display/OFBADMIN/OFBiz+Source+Repository+and+Access

(see the paragraph "Developer Access").

There is also a mention to this here:

http://docs.ofbiz.org/display/OFBADMIN/OFBiz+Contributors+Best+Practices

> What svn properties need to be set?  Or, point me at the  
> documentation that says what should be done.

For files like these (that are similar to Java source files) we need  
the following properties:

svn:mime-type=text/plain
svn:eol-style=native
svn:keywords="Date Rev Author URL Id"
You can manually set them to two files in your local repository using  
the "svn propset" command and then committing the file.
For example:

svn propset svn:mime-type text/plain path/to/file/filename
svn propset ....
svn commit path/to/file/filename

Hope it helps,
Jacopo

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

Posted by Adam Heath <do...@brainfood.com>.
Jacopo Cappellato wrote:

> please remember the License header and the svn properties (still missing 
> from the last new file you added to the repository).

You're right, I forgot to add it to *this* new file; but I already did 
it for the last one.

What svn properties need to be set?  Or, point me at the documentation 
that says what should be done.

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

Posted by Jacopo Cappellato <ja...@gmail.com>.
Adam,

please remember the License header and the svn properties (still  
missing from the last new file you added to the repository).

Thanks,

Jacopo

On Aug 15, 2008, at 5:29 PM, doogie@apache.org wrote:

> 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
> +
>