Title: [waffle-scm] [422] trunk/waffle-distribution/src/site/content: Made validator suffix configurable.

Diff

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/DefaultValidator.java (421 => 422)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/DefaultValidator.java	2007-11-24 18:19:20 UTC (rev 421)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/DefaultValidator.java	2007-11-25 01:01:12 UTC (rev 422)
@@ -29,16 +29,21 @@
  * @author Mauro Talevi
  */
 public class DefaultValidator implements Validator {
-    protected static final String VALIDATOR_SUFFIX = "Validator";
     private final ValidationMonitor validationMonitor;
-
+    private final ValidatorConfiguration validatorConfiguration;
+    
     public DefaultValidator(ValidationMonitor validationMonitor){
+        this(new DefaultValidatorConfiguration(), validationMonitor);        
+    }
+    
+    public DefaultValidator(ValidatorConfiguration validatorConfiguration, ValidationMonitor validationMonitor){
+        this.validatorConfiguration = validatorConfiguration;
         this.validationMonitor = validationMonitor;        
     }
 
     public void validate(ControllerDefinition controllerDefinition, ErrorsContext errorsContext) {
         ContextContainer container = RequestLevelContainer.get();
-        Object controllerValidator = container.getComponentInstance(controllerDefinition.getName() + VALIDATOR_SUFFIX);
+        Object controllerValidator = container.getComponentInstance(controllerDefinition.getName() + validatorConfiguration.getSuffix());
 
         if (controllerValidator == null) {
             validationMonitor.controllerValidatorNotFound();

Added: trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/DefaultValidatorConfiguration.java (0 => 422)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/DefaultValidatorConfiguration.java	                        (rev 0)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/DefaultValidatorConfiguration.java	2007-11-25 01:01:12 UTC (rev 422)
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (C) 2005,2006 Michael Ward                                      *
+ * All rights reserved.                                                      *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by: Mauro Talevi                                            *
+ *****************************************************************************/
+package org.codehaus.waffle.validation;
+
+public class DefaultValidatorConfiguration implements ValidatorConfiguration {
+    private static final String DEFAULT_SUFFIX = "Validator";
+    
+    private String suffix;
+    
+    public DefaultValidatorConfiguration(){
+        this(DEFAULT_SUFFIX);
+    }
+    
+    public DefaultValidatorConfiguration(String suffix) {
+        this.suffix = suffix;
+    }
+
+    public String getSuffix() {
+        return suffix;
+    }
+
+}

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/Validator.java (421 => 422)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/Validator.java	2007-11-24 18:19:20 UTC (rev 421)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/Validator.java	2007-11-25 01:01:12 UTC (rev 422)
@@ -15,4 +15,5 @@
 public interface Validator {
 
     void validate(ControllerDefinition controllerDefinition, ErrorsContext errorsContext);
+
 }

Added: trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/ValidatorConfiguration.java (0 => 422)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/ValidatorConfiguration.java	                        (rev 0)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/ValidatorConfiguration.java	2007-11-25 01:01:12 UTC (rev 422)
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * Copyright (C) 2005,2006 Michael Ward                                      *
+ * All rights reserved.                                                      *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by: Mauro Talevi                                            *
+ *****************************************************************************/
+package org.codehaus.waffle.validation;
+
+/**
+ * Holds validator configuration
+ * 
+ * @author Mauro Talevi
+ */
+public interface ValidatorConfiguration {
+
+    /**
+     * Returns the suffix of the validator class name
+     * 
+     * @return The suffix
+     */
+    String getSuffix();
+
+}

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/validation/DefaultValidatorTest.java (421 => 422)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/validation/DefaultValidatorTest.java	2007-11-24 18:19:20 UTC (rev 421)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/validation/DefaultValidatorTest.java	2007-11-25 01:01:12 UTC (rev 422)
@@ -36,13 +36,26 @@
 
     @Test
     public void canValidate() throws Exception {
+        String suffix = "Validator";
+        Validator validator = new DefaultValidator(new SilentMonitor());
+        assertValidator(validator, suffix);
+    }
+    
+    @Test
+    public void canValidateWithCustumSuffix() throws Exception {
+        String suffix = "Check";
+        Validator validator = new DefaultValidator(new DefaultValidatorConfiguration(suffix), new SilentMonitor());
+        assertValidator(validator, suffix);
+    }
+
+    private void assertValidator(Validator validator, final String suffix) throws NoSuchMethodException {
         final FakeControllerValidator fakeControllerValidator = new FakeControllerValidator();
 
         // Mock ContextContainer
         final ContextContainer contextContainer = mockery.mock(ContextContainer.class);
         mockery.checking(new Expectations() {
             {
-                one(contextContainer).getComponentInstance("theControllerValidator");
+                one(contextContainer).getComponentInstance("theController"+suffix);
                 will(returnValue(fakeControllerValidator));
             }
         });
@@ -57,7 +70,6 @@
         ControllerDefinition controllerDefinition = new ControllerDefinition("theController", fakeController, methodDefinition);
 
         ErrorsContext errorsContext = new DefaultErrorsContext();
-        Validator validator = new DefaultValidator(new SilentMonitor());
         validator.validate(controllerDefinition, errorsContext);
 
         assertSame(errorsContext, fakeControllerValidator.errorsContext);

Modified: trunk/waffle-distribution/src/site/content/validation.html (421 => 422)

--- trunk/waffle-distribution/src/site/content/validation.html	2007-11-24 18:19:20 UTC (rev 421)
+++ trunk/waffle-distribution/src/site/content/validation.html	2007-11-25 01:01:12 UTC (rev 422)
@@ -60,7 +60,8 @@
 
     <p>
       You can register any POJO you would like as a Validator. The only requirement is that it should be registered with
-      the suffix <i>Validator</i>.  In other words the POJO registered under the name <i>"fooValidator"</i> would be the
+      the suffix <i>Validator</i> (or a different suffix that can be configured via the <b>ValidatorConfiguration</b>).  
+      In other words the POJO registered under the name <i>"fooValidator"</i> would be the
       Validator for the controller registered under the name <i>"foo"</i>.  The Validator class will need to provide a
       seperate method for each ActionMethod requiring sepearte validation. These validate methods will need to be named
       identical to the ActionMethods they are providing validation for. The signature of the validate method is


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to