KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > forms > validators > ValidTypeValidator


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: ValidTypeValidator.java,v 1.15 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.forms.validators;
21
22 import java.util.*;
23
24 import org.enhydra.barracuda.core.forms.*;
25 import org.enhydra.barracuda.plankton.*;
26
27 /**
28  * This validator ensures that the original value constitues a
29  * valid type
30  */

31 public class ValidTypeValidator extends DefaultFormValidator {
32
33     /**
34      * Public constructor.
35      */

36     public ValidTypeValidator() {
37         super();
38     }
39
40     /**
41      * Public constructor.
42      *
43      * @param ierrorMessage the message associated with this error
44      */

45     public ValidTypeValidator(String JavaDoc ierrorMessage) {
46         super(ierrorMessage);
47     }
48
49     /**
50      * Public constructor.
51      *
52      * @param errorMessage the message associated with this error
53      * @param deferExceptions true if want generated exceptions to be deferred
54      */

55 // public ValidTypeValidator(String ierrorMessage, boolean ideferExceptions) {
56
// super(ierrorMessage, ideferExceptions);
57
// }
58

59     /**
60      * Validate a FormElement to make sure that the non-null orig values are valid
61      * for the specified element type
62      *
63      * @param val the value to compare the element value to
64      * @param element the form element that contains the val
65      * to validate elements by comparing them with other elements)
66      * @param deferExceptions do we want to deferValidation exceptions
67      * and attempt to validate all elements so that we can process
68      * all the exceptions at once
69      * @throws ValidationException if the element is not valid
70      */

71     public void validateFormElement(Object JavaDoc val, FormElement element, boolean deferExceptions) throws ValidationException {
72         //ilc-02-20-2000 begin changes
73
//make sure we validate val
74
// Object origVal = element.getOrigVal();
75
//ilc-02-20-2000 end changes
76
FormType ft = element.getType();
77         if (localLogger.isInfoEnabled()) localLogger.info("validating orig val="+val+" is of type:"+ft);
78 //System.out.println("validating orig val="+origVal+" is of type:"+ft);
79

80         //ilc-02-20-2000 begin changes
81
//Do not make judgement calls on null and empty strings
82
// if (origVal==null) return; //this validator makes no judgement calls if the value is null
83
//this validator makes no judgement calls if the value is null
84
// if (val==null || val.toString().trim().length()<1) return;
85
if (isNull(val, element))
86           return;
87         //ilc-02-20-2000 end changes
88

89         if (element.getParseException()!=null) {
90             throw this.generateException(element, deferExceptions, "Invalid value '"+val+"' for form type "+ft);
91         }
92     }
93
94 }
95
Popular Tags