KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > dv > xs > TypeValidator


1 /*
2  * Copyright 2001, 2002,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
17 package org.apache.xerces.impl.dv.xs;
18
19 import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
20 import org.apache.xerces.impl.dv.ValidationContext;
21
22 /**
23  * All primitive types plus ID/IDREF/ENTITY/INTEGER are derived from this abstract
24  * class. It provides extra information XSSimpleTypeDecl requires from each
25  * type: allowed facets, converting String to actual value, check equality,
26  * comparison, etc.
27  *
28  * @xerces.internal
29  *
30  * @author Neeraj Bajaj, Sun Microsystems, inc.
31  * @author Sandy Gao, IBM
32  *
33  * @version $Id: TypeValidator.java,v 1.8 2004/10/06 14:56:46 mrglavas Exp $
34  */

35 public abstract class TypeValidator {
36
37     // which facets are allowed for this type
38
public abstract short getAllowedFacets();
39
40     // convert a string to an actual value. for example,
41
// for number types (decimal, double, float, and types derived from them),
42
// get the BigDecimal, Double, Flout object.
43
// for some types (string and derived), they just return the string itself
44
public abstract Object JavaDoc getActualValue(String JavaDoc content, ValidationContext context)
45         throws InvalidDatatypeValueException;
46
47     // for ID/IDREF/ENTITY types, do some extra checking after the value is
48
// checked to be valid with respect to both lexical representation and
49
// facets
50
public void checkExtraRules(Object JavaDoc value, ValidationContext context) throws InvalidDatatypeValueException {
51     }
52
53     // the following methods might not be supported by every DV.
54
// but XSSimpleTypeDecl should know which type supports which methods,
55
// and it's an *internal* error if a method is called on a DV that
56
// doesn't support it.
57

58     //order constants
59
public static final short LESS_THAN = -1;
60     public static final short EQUAL = 0;
61     public static final short GREATER_THAN = 1;
62     public static final short INDETERMINATE = 2;
63     
64     // where there is distinction between identity and equality, this method
65
// will be overwritten
66
// checks whether the two values are identical; for ex, this distinguishes
67
// -0.0 from 0.0
68
public boolean isIdentical (Object JavaDoc value1, Object JavaDoc value2) {
69         return value1.equals(value2);
70     }
71
72     // check the order relation between the two values
73
// the parameters are in compiled form (from getActualValue)
74
public int compare(Object JavaDoc value1, Object JavaDoc value2) {
75         return -1;
76     }
77
78     // get the length of the value
79
// the parameters are in compiled form (from getActualValue)
80
public int getDataLength(Object JavaDoc value) {
81         return (value instanceof String JavaDoc) ? ((String JavaDoc)value).length() : -1;
82     }
83
84     // get the number of digits of the value
85
// the parameters are in compiled form (from getActualValue)
86
public int getTotalDigits(Object JavaDoc value) {
87         return -1;
88     }
89
90     // get the number of fraction digits of the value
91
// the parameters are in compiled form (from getActualValue)
92
public int getFractionDigits(Object JavaDoc value) {
93         return -1;
94     }
95
96     // check whether the character is in the range 0x30 ~ 0x39
97
public static final boolean isDigit(char ch) {
98         return ch >= '0' && ch <= '9';
99     }
100     
101     // if the character is in the range 0x30 ~ 0x39, return its int value (0~9),
102
// otherwise, return -1
103
public static final int getDigit(char ch) {
104         return isDigit(ch) ? ch - '0' : -1;
105     }
106     
107 } // interface TypeValidator
108
Popular Tags