KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > dv > dtd > ListDatatypeValidator


1 /*
2  * Copyright 1999-2002,2004,2005 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
17 package org.apache.xerces.impl.dv.dtd;
18
19 import org.apache.xerces.impl.dv.*;
20 import java.util.StringTokenizer JavaDoc;
21
22 /**
23  * For list types: ENTITIES, IDREFS, NMTOKENS.
24  *
25  * @xerces.internal
26  *
27  * @author Jeffrey Rodriguez, IBM
28  * @author Sandy Gao, IBM
29  *
30  * @version $Id: ListDatatypeValidator.java,v 1.8 2005/03/22 05:35:49 mrglavas Exp $
31  */

32 public class ListDatatypeValidator implements DatatypeValidator {
33
34     // the type of items in the list
35
DatatypeValidator fItemValidator;
36
37     // construct a list datatype validator
38
public ListDatatypeValidator(DatatypeValidator itemDV) {
39         fItemValidator = itemDV;
40     }
41
42     /**
43      * Checks that "content" string is valid.
44      * If invalid a Datatype validation exception is thrown.
45      *
46      * @param content the string value that needs to be validated
47      * @param context the validation context
48      * @throws InvalidDatatypeException if the content is
49      * invalid according to the rules for the validators
50      * @see InvalidDatatypeValueException
51      */

52     public void validate(String JavaDoc content, ValidationContext context) throws InvalidDatatypeValueException {
53
54         StringTokenizer JavaDoc parsedList = new StringTokenizer JavaDoc(content," ");
55         int numberOfTokens = parsedList.countTokens();
56         if (numberOfTokens == 0) {
57             throw new InvalidDatatypeValueException("EmptyList", null);
58         }
59         //Check each token in list against base type
60
while (parsedList.hasMoreTokens()) {
61             this.fItemValidator.validate(parsedList.nextToken(), context);
62         }
63     }
64
65 }
66
67
Popular Tags