286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2001, 2002,2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.impl.dv.xs;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.ValidationContext;
286N/A
286N/A/**
286N/A * All primitive types plus ID/IDREF/ENTITY/INTEGER are derived from this abstract
286N/A * class. It provides extra information XSSimpleTypeDecl requires from each
286N/A * type: allowed facets, converting String to actual value, check equality,
286N/A * comparison, etc.
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A * @author Neeraj Bajaj, Sun Microsystems, inc.
286N/A * @author Sandy Gao, IBM
286N/A *
286N/A */
286N/Apublic abstract class TypeValidator {
286N/A
286N/A // which facets are allowed for this type
286N/A public abstract short getAllowedFacets();
286N/A
286N/A // convert a string to an actual value. for example,
286N/A // for number types (decimal, double, float, and types derived from them),
286N/A // get the BigDecimal, Double, Flout object.
286N/A // for some types (string and derived), they just return the string itself
286N/A public abstract Object getActualValue(String content, ValidationContext context)
286N/A throws InvalidDatatypeValueException;
286N/A
286N/A // for ID/IDREF/ENTITY types, do some extra checking after the value is
286N/A // checked to be valid with respect to both lexical representation and
286N/A // facets
286N/A public void checkExtraRules(Object value, ValidationContext context) throws InvalidDatatypeValueException {
286N/A }
286N/A
286N/A // the following methods might not be supported by every DV.
286N/A // but XSSimpleTypeDecl should know which type supports which methods,
286N/A // and it's an *internal* error if a method is called on a DV that
286N/A // doesn't support it.
286N/A
286N/A //order constants
286N/A public static final short LESS_THAN = -1;
286N/A public static final short EQUAL = 0;
286N/A public static final short GREATER_THAN = 1;
286N/A public static final short INDETERMINATE = 2;
286N/A
286N/A // where there is distinction between identity and equality, this method
286N/A // will be overwritten
286N/A // checks whether the two values are identical; for ex, this distinguishes
286N/A // -0.0 from 0.0
286N/A public boolean isIdentical (Object value1, Object value2) {
286N/A return value1.equals(value2);
286N/A }
286N/A
286N/A // check the order relation between the two values
286N/A // the parameters are in compiled form (from getActualValue)
286N/A public int compare(Object value1, Object value2) {
286N/A return -1;
286N/A }
286N/A
286N/A // get the length of the value
286N/A // the parameters are in compiled form (from getActualValue)
286N/A public int getDataLength(Object value) {
286N/A return (value instanceof String) ? ((String)value).length() : -1;
286N/A }
286N/A
286N/A // get the number of digits of the value
286N/A // the parameters are in compiled form (from getActualValue)
286N/A public int getTotalDigits(Object value) {
286N/A return -1;
286N/A }
286N/A
286N/A // get the number of fraction digits of the value
286N/A // the parameters are in compiled form (from getActualValue)
286N/A public int getFractionDigits(Object value) {
286N/A return -1;
286N/A }
286N/A
286N/A // check whether the character is in the range 0x30 ~ 0x39
286N/A public static final boolean isDigit(char ch) {
286N/A return ch >= '0' && ch <= '9';
286N/A }
286N/A
286N/A // if the character is in the range 0x30 ~ 0x39, return its int value (0~9),
286N/A // otherwise, return -1
286N/A public static final int getDigit(char ch) {
286N/A return isDigit(ch) ? ch - '0' : -1;
286N/A }
286N/A
286N/A} // interface TypeValidator