Source code: com/aendvari/griffin/validation/validator/ErrorMethod.java
1 /*
2 * ErrorMethod.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 ErrorMethod}.</p>
24 *
25 * <p>This class is used to define the method that is to be called upon errors found in validation.</p>
26 *
27 * @author Scott Milne
28 *
29 */
30
31 public class ErrorMethod extends HandlerMethod
32 {
33 /**
34 * Executes this classes' part of a Dataset validation.
35 *
36 * @param errorHandler The {@link ErrorHandler} instance for this method.
37 * @param property A {@link Property} instance for the value to test.
38 * @param handlers A <code>HashMap</code> of {@link ValidationHandler} instances.
39 * @param defaultObjectHandler A {@link ValidationHandler} for object error handler.
40 * @param defaultClassHandler A {@link ValidationHandler} for class error handler.
41 *
42 */
43
44 public boolean executeValidation(
45 Handler handler,
46 Property property,
47 ValidationHandler errorObjectHandler,
48 ValidationHandler errorClassHandler )
49 throws Exception
50 {
51 boolean methodExecuted = false;
52
53 // if there was a valid object handler, try looking there first
54 if (errorObjectHandler != null)
55 {
56 // if the method we want is there, execute it
57 if (errorObjectHandler.isMethodAvailable(name))
58 {
59 // execute each of the validators
60 errorObjectHandler.executeMethod( name, parameters, handler, property );
61 methodExecuted = true;
62 }
63 }
64
65 // if the object handler was not there, or the method wanted was not found
66 // then check to make sure we have a valid class handler, then check there
67 if ( !methodExecuted && errorClassHandler != null)
68 {
69 // if the method we want is there, execute it
70 if (errorClassHandler.isMethodAvailable(name))
71 {
72 // execute each of the validators
73 errorClassHandler.executeMethod( name, parameters, handler, property );
74 methodExecuted = true;
75 }
76 }
77
78 return methodExecuted;
79 }
80
81 /**
82 * Convert this object into a String representation.
83 *
84 */
85
86 public String toString()
87 {
88 String data = "ErrorMethod [";
89 data += "name=" + name + ",";
90 data += "parameters=" + parameters + ",";
91 data += "]";
92 return data;
93 }
94 }
95