KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > acting > ValidatorActionHelper


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.acting;
17
18
19 /**
20  * Helper class to pass the result of a validation back along with
21  * the validated object itself.
22  *
23  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
24  * @version CVS $Id: ValidatorActionHelper.java 30932 2004-07-29 17:35:38Z vgritsenko $
25  */

26 public class ValidatorActionHelper
27 {
28     protected ValidatorActionResult result = ValidatorActionResult.OK;
29     protected Object JavaDoc object = null;
30
31     /**
32      * Create a ValidatorActionHelper object that contains just the
33      * object. Defaults to <code>OK</code> as validation result.
34      *
35      * @param validatedObject object that has been validated
36      */

37     public ValidatorActionHelper ( Object JavaDoc validatedObject ) {
38         this.object = validatedObject;
39         this.result = ValidatorActionResult.OK;
40     }
41
42     /**
43      * Create a ValidatorActionHelper object that contains just the
44      * object. Defaults to <code>OK</code> as validation result.
45      *
46      * @param validatedObject object that has been validated
47      * @param validationResult result of the validation
48      */

49     public ValidatorActionHelper ( Object JavaDoc validatedObject, ValidatorActionResult validationResult ) {
50         this.object = validatedObject;
51         this.result = validationResult;
52     }
53
54     /**
55      * Tests if the validation result is <code>OK</code>
56      *
57      */

58     public boolean isOK() {
59         return (result.equals(ValidatorActionResult.OK));
60     }
61
62     /**
63      * Tests if the validation result is <code>NOTPRESENT</code>,
64      * e.g. when the value is null and is allowed to be null.
65      *
66      */

67     public boolean isNotPresent() {
68         return (result.equals(ValidatorActionResult.NOTPRESENT));
69     }
70
71     /**
72      * Tests if the validation result is <code>ISNULL</code>,
73      * e.g. when the value is null but is not supposed to be null.
74      *
75      */

76     public boolean isNull() {
77         return (result.equals(ValidatorActionResult.ISNULL));
78     }
79
80     /**
81      * Tests if the validation result is <code>TOOLARGE</code>,
82      * e.g. in case of a double or long the value is too large or in
83      * case of a string it is too long.
84      *
85      */

86     public boolean isTooLarge() {
87         return (result.equals(ValidatorActionResult.TOOLARGE));
88     }
89
90     /**
91      * Tests if the validation result is <code>TOOSMALL</code>,
92      * e.g. in case of a double or long the value is too small or in
93      * case of a string it is too short.
94      *
95      */

96     public boolean isTooSmall() {
97         return (result.equals(ValidatorActionResult.TOOSMALL));
98     }
99
100     /**
101      * Tests if the validation result is <code>NOMATCH</code>, can
102      * only occur when
103      *
104      */

105     public boolean doesNotMatch() {
106         return (result.equals(ValidatorActionResult.NOMATCH));
107     }
108
109     /**
110      * Returns the tested object.
111      *
112      */

113     public Object JavaDoc getObject() {
114         return object;
115     }
116
117     /**
118      * Returns the result.
119      *
120      */

121     public ValidatorActionResult getResult() {
122         return result;
123     }
124 }
125
Popular Tags