01: /*
02: * Copyright 2006 Dan Shellman
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.iscreen.validators;
17:
18: import org.iscreen.BaseValidator;
19: import org.iscreen.FailureMessage;
20: import org.iscreen.SimpleBean;
21: import org.iscreen.ValidatorContext;
22:
23: /**
24: * The NullValidator checks a single value and ensures that it's not null.
25: *
26: * @author Shellman, Dan
27: */
28: public class NullValidator extends BaseValidator {
29: /**
30: * Default constructor.
31: */
32: public NullValidator() {
33: } //end NullValidator()
34:
35: public void validate(ValidatorContext context, Object beanToValidate) {
36: if (((SimpleBean) beanToValidate).getValue() == null) {
37: context.reportFailure(getDefaultFailure());
38: }
39: } //end validate()
40:
41: /**
42: * Retrieves the default failure message. If only one failure
43: * is used by the sub-class, then this property can be used to
44: * get the failure message for reporting a failure.
45: *
46: * @return Returns the default failure message.
47: */
48: public FailureMessage getDefaultFailure() {
49: return defaultFailure;
50: } //end getDefaultFailure()
51:
52: /**
53: * Sets the failure message. This is called based upon what's
54: * configured for this validator. Ensure that this is properly
55: * configured: otherwise, the call to getDefaultFailure() will
56: * return null.
57: *
58: * @param failure The default failure message to use.
59: */
60: public void setDefaultFailure(FailureMessage failure) {
61: defaultFailure = failure;
62: } //end setDefaultFailure()
63: } //end NullValidator
|