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:
018: package org.apache.xerces.impl.dv.xs;
019:
020: import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
021: import org.apache.xerces.impl.dv.ValidationContext;
022:
023: /**
024: * All primitive types plus ID/IDREF/ENTITY/INTEGER are derived from this abstract
025: * class. It provides extra information XSSimpleTypeDecl requires from each
026: * type: allowed facets, converting String to actual value, check equality,
027: * comparison, etc.
028: *
029: * @xerces.internal
030: *
031: * @author Neeraj Bajaj, Sun Microsystems, inc.
032: * @author Sandy Gao, IBM
033: *
034: * @version $Id: TypeValidator.java 446745 2006-09-15 21:43:58Z mrglavas $
035: */
036: public abstract class TypeValidator {
037:
038: // which facets are allowed for this type
039: public abstract short getAllowedFacets();
040:
041: // convert a string to an actual value. for example,
042: // for number types (decimal, double, float, and types derived from them),
043: // get the BigDecimal, Double, Flout object.
044: // for some types (string and derived), they just return the string itself
045: public abstract Object getActualValue(String content,
046: ValidationContext context)
047: throws InvalidDatatypeValueException;
048:
049: // for ID/IDREF/ENTITY types, do some extra checking after the value is
050: // checked to be valid with respect to both lexical representation and
051: // facets
052: public void checkExtraRules(Object value, ValidationContext context)
053: throws InvalidDatatypeValueException {
054: }
055:
056: // the following methods might not be supported by every DV.
057: // but XSSimpleTypeDecl should know which type supports which methods,
058: // and it's an *internal* error if a method is called on a DV that
059: // doesn't support it.
060:
061: //order constants
062: public static final short LESS_THAN = -1;
063: public static final short EQUAL = 0;
064: public static final short GREATER_THAN = 1;
065: public static final short INDETERMINATE = 2;
066:
067: // where there is distinction between identity and equality, this method
068: // will be overwritten
069: // checks whether the two values are identical; for ex, this distinguishes
070: // -0.0 from 0.0
071: public boolean isIdentical(Object value1, Object value2) {
072: return value1.equals(value2);
073: }
074:
075: // check the order relation between the two values
076: // the parameters are in compiled form (from getActualValue)
077: public int compare(Object value1, Object value2) {
078: return -1;
079: }
080:
081: // get the length of the value
082: // the parameters are in compiled form (from getActualValue)
083: public int getDataLength(Object value) {
084: return (value instanceof String) ? ((String) value).length()
085: : -1;
086: }
087:
088: // get the number of digits of the value
089: // the parameters are in compiled form (from getActualValue)
090: public int getTotalDigits(Object value) {
091: return -1;
092: }
093:
094: // get the number of fraction digits of the value
095: // the parameters are in compiled form (from getActualValue)
096: public int getFractionDigits(Object value) {
097: return -1;
098: }
099:
100: // check whether the character is in the range 0x30 ~ 0x39
101: public static final boolean isDigit(char ch) {
102: return ch >= '0' && ch <= '9';
103: }
104:
105: // if the character is in the range 0x30 ~ 0x39, return its int value (0~9),
106: // otherwise, return -1
107: public static final int getDigit(char ch) {
108: return isDigit(ch) ? ch - '0' : -1;
109: }
110:
111: } // interface TypeValidator
|