001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.acting;
018:
019: /**
020: * Helper class to pass the result of a validation back along with
021: * the validated object itself.
022: *
023: * @author <a href="mailto:haul@apache.org">Christian Haul</a>
024: * @version CVS $Id: ValidatorActionHelper.java 433543 2006-08-22 06:22:54Z crossley $
025: */
026: public class ValidatorActionHelper {
027: protected ValidatorActionResult result = ValidatorActionResult.OK;
028: protected Object object = null;
029:
030: /**
031: * Create a ValidatorActionHelper object that contains just the
032: * object. Defaults to <code>OK</code> as validation result.
033: *
034: * @param validatedObject object that has been validated
035: */
036: public ValidatorActionHelper(Object validatedObject) {
037: this .object = validatedObject;
038: this .result = ValidatorActionResult.OK;
039: }
040:
041: /**
042: * Create a ValidatorActionHelper object that contains just the
043: * object. Defaults to <code>OK</code> as validation result.
044: *
045: * @param validatedObject object that has been validated
046: * @param validationResult result of the validation
047: */
048: public ValidatorActionHelper(Object validatedObject,
049: ValidatorActionResult validationResult) {
050: this .object = validatedObject;
051: this .result = validationResult;
052: }
053:
054: /**
055: * Tests if the validation result is <code>OK</code>
056: *
057: */
058: public boolean isOK() {
059: return (result.equals(ValidatorActionResult.OK));
060: }
061:
062: /**
063: * Tests if the validation result is <code>NOTPRESENT</code>,
064: * e.g. when the value is null and is allowed to be null.
065: *
066: */
067: public boolean isNotPresent() {
068: return (result.equals(ValidatorActionResult.NOTPRESENT));
069: }
070:
071: /**
072: * Tests if the validation result is <code>ISNULL</code>,
073: * e.g. when the value is null but is not supposed to be null.
074: *
075: */
076: public boolean isNull() {
077: return (result.equals(ValidatorActionResult.ISNULL));
078: }
079:
080: /**
081: * Tests if the validation result is <code>TOOLARGE</code>,
082: * e.g. in case of a double or long the value is too large or in
083: * case of a string it is too long.
084: *
085: */
086: public boolean isTooLarge() {
087: return (result.equals(ValidatorActionResult.TOOLARGE));
088: }
089:
090: /**
091: * Tests if the validation result is <code>TOOSMALL</code>,
092: * e.g. in case of a double or long the value is too small or in
093: * case of a string it is too short.
094: *
095: */
096: public boolean isTooSmall() {
097: return (result.equals(ValidatorActionResult.TOOSMALL));
098: }
099:
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 getObject() {
114: return object;
115: }
116:
117: /**
118: * Returns the result.
119: *
120: */
121: public ValidatorActionResult getResult() {
122: return result;
123: }
124: }
|