Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/aendvari/griffin/validation/validator/ValidateMethod.java


1   /*
2    * ValidateMethod.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.aendvari.griffin.validation.validator;
11  
12  import java.util.*;
13  
14  import com.aendvari.common.util.Debug;
15  import com.aendvari.common.model.*;
16  
17  import com.aendvari.griffin.validation.*;
18  import com.aendvari.griffin.validation.dataset.*;
19  import com.aendvari.griffin.validation.validator.*;
20  
21  
22  /**
23   * <p>Defines a {@link ValidateMethod}.</p>
24   *
25   * <p>This class is used to define the method that is to be called upon validates found in validation.</p>
26   *
27   * @author  Scott Milne
28   *
29   */
30  
31  public class ValidateMethod extends HandlerMethod
32  {
33    /**
34     * Executes this part of a <code>Dataset</code> validation.
35     *
36     * @param    validator          The {@link Validator} instance for this method.
37     * @param    property          A {@link Property} instance for the value to test.
38     * @param    handlers          A HashMap of {@link ValidationHandler} instances.
39     * @param    validateObjectHandler    A {@link ValidationHandler} as object handler instance.
40     * @param    validateClassHandler    A {@link ValidationHandler} as class handler instance.
41     *
42     */
43  
44    public boolean executeValidation(
45      Handler handler,
46      Property property,
47      ValidationHandler validateObjectHandler,
48      ValidationHandler validateClassHandler
49      )
50        throws Exception
51    {
52      boolean methodExecuted = false;
53      boolean methodSuccessful = false;
54  
55      // if there was a valid object handler, try looking there first
56      if (validateObjectHandler != null)
57      {
58        // if the method we want is there, execute it
59        if (validateObjectHandler.isMethodAvailable(name))
60        {
61          // execute each of the validators
62          methodSuccessful = validateObjectHandler.executeMethod( name, parameters, handler, property );
63          methodExecuted = true;
64        }
65      }
66  
67      // if the object handler was not there, or the method wanted was not found
68      // then check to make sure we have a valid class handler, then check there
69      if ( !methodExecuted && validateClassHandler != null)
70      {
71        // if the method we want is there, execute it
72        if (validateClassHandler.isMethodAvailable(name))
73        {
74          // execute each of the validators
75          methodSuccessful = validateClassHandler.executeMethod( name, parameters, handler, property );
76          methodExecuted = true;
77        }
78      }
79  
80      // return the success value
81      return methodSuccessful;
82    }
83  
84    /**
85     * Convert this object into a String representation.
86     *
87     */
88  
89    public String toString()
90    {
91      String data = "ValidateMethod [";
92      data += "name=" + name + ",";
93      data += "parameters=" + parameters + ",";
94      data += "]";
95      return data;
96    }
97  }
98