Revision: 1355
          http://svn.sourceforge.net/spring-rich-c/?rev=1355&view=rev
Author:   jhoskens
Date:     2006-08-31 00:41:53 -0700 (Thu, 31 Aug 2006)

Log Message:
-----------
Small refactoring: And/Or/XOr handled by one function taking CompoungConstraint
removed appendValue code: not used

Modified Paths:
--------------
    
trunk/spring-richclient/support/src/main/java/org/springframework/rules/reporting/DefaultMessageTranslator.java

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/rules/reporting/DefaultMessageTranslator.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/rules/reporting/DefaultMessageTranslator.java
     2006-08-30 20:22:39 UTC (rev 1354)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/rules/reporting/DefaultMessageTranslator.java
     2006-08-31 07:41:53 UTC (rev 1355)
@@ -28,10 +28,9 @@
 import org.springframework.core.ReflectiveVisitorHelper;
 import org.springframework.core.closure.Constraint;
 import org.springframework.core.style.StylerUtils;
-import org.springframework.rules.constraint.And;
 import org.springframework.rules.constraint.ClosureResultConstraint;
+import org.springframework.rules.constraint.CompoundConstraint;
 import org.springframework.rules.constraint.Not;
-import org.springframework.rules.constraint.Or;
 import org.springframework.rules.constraint.ParameterizedBinaryConstraint;
 import org.springframework.rules.constraint.Range;
 import org.springframework.rules.constraint.StringLengthConstraint;
@@ -54,8 +53,6 @@
 
        private ReflectiveVisitorHelper visitorSupport = new 
ReflectiveVisitorHelper();
 
-       private boolean appendValue = false;
-
        private List args = new ArrayList();
 
        private MessageSource messages;
@@ -128,12 +125,6 @@
                if (objectName != null) {
                        buf.append(resolveObjectName(objectName));
                        buf.append(' ');
-                       if (appendValue) {
-                               if (rejectedValue != null) {
-                                       buf.append("'" + rejectedValue + "'");
-                                       buf.append(' ');
-                               }
-                       }
                }
                for (int i = 0; i < args.length - 1; i++) {
                        MessageSourceResolvable arg = args[i];
@@ -189,28 +180,25 @@
                visitorSupport.invokeVisit(this, 
valueConstraint.getConstraint());
        }
 
-       void visit(And and) {
-               Iterator it = and.iterator();
+    /**
+     * Visit function for compound constraints like And/Or/XOr.
+     * 
+     * <p>syntax: <code>CONSTRAINT MESSAGE{code} CONSTRAINT</code></p>
+     * 
+     * @param compoundConstraint
+     */
+       void visit(CompoundConstraint compoundConstraint) {
+               Iterator it = compoundConstraint.iterator();
+        String compoundMessage = getMessageCode(compoundConstraint);
                while (it.hasNext()) {
                        Constraint p = (Constraint) it.next();
                        visitorSupport.invokeVisit(this, p);
                        if (it.hasNext()) {
-                               add("and", null, "add");
+                               add(compoundMessage, null, compoundMessage);
                        }
                }
        }
 
-       void visit(Or or) {
-               Iterator it = or.iterator();
-               while (it.hasNext()) {
-                       Constraint p = (Constraint) it.next();
-                       visitorSupport.invokeVisit(this, p);
-                       if (it.hasNext()) {
-                               add("or", null, "or");
-                       }
-               }
-       }
-
        void visit(Not not) {
                add("not", null, "not");
                visitorSupport.invokeVisit(this, not.getConstraint());
@@ -258,7 +246,15 @@
                }
        }
 
-       private String getMessageCode(Object o) {
+    /**
+     * Determines the messageCode (key in messageSource) to look up.
+     * If <code>TypeResolvable</code> is implemented, user can give a custom 
code,
+     * otherwise the short className is used.
+     * 
+     * @param o
+     * @return
+     */
+       protected String getMessageCode(Object o) {
                if (o instanceof TypeResolvable) {
                        String type = ((TypeResolvable) o).getType();
                        if (type != null) {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to