1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2001, 2002,2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.impl.dv.xs; 22 23 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; 24 import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext; 25 26 /** 27 * All primitive types plus ID/IDREF/ENTITY/INTEGER are derived from this abstract 28 * class. It provides extra information XSSimpleTypeDecl requires from each 29 * type: allowed facets, converting String to actual value, check equality, 30 * comparison, etc. 31 * 32 * @xerces.internal 33 * 34 * @author Neeraj Bajaj, Sun Microsystems, inc. 35 * @author Sandy Gao, IBM 36 * 37 */ 38 public abstract class TypeValidator { 39 40 // which facets are allowed for this type getAllowedFacets()41 public abstract short getAllowedFacets(); 42 43 // convert a string to an actual value. for example, 44 // for number types (decimal, double, float, and types derived from them), 45 // get the BigDecimal, Double, Flout object. 46 // for some types (string and derived), they just return the string itself getActualValue(String content, ValidationContext context)47 public abstract Object getActualValue(String content, ValidationContext context) 48 throws InvalidDatatypeValueException; 49 50 // for ID/IDREF/ENTITY types, do some extra checking after the value is 51 // checked to be valid with respect to both lexical representation and 52 // facets checkExtraRules(Object value, ValidationContext context)53 public void checkExtraRules(Object value, ValidationContext context) throws InvalidDatatypeValueException { 54 } 55 56 // the following methods might not be supported by every DV. 57 // but XSSimpleTypeDecl should know which type supports which methods, 58 // and it's an *internal* error if a method is called on a DV that 59 // doesn't support it. 60 61 //order constants 62 public static final short LESS_THAN = -1; 63 public static final short EQUAL = 0; 64 public static final short GREATER_THAN = 1; 65 public static final short INDETERMINATE = 2; 66 67 // where there is distinction between identity and equality, this method 68 // will be overwritten 69 // checks whether the two values are identical; for ex, this distinguishes 70 // -0.0 from 0.0 isIdentical(Object value1, Object value2)71 public boolean isIdentical (Object value1, Object value2) { 72 return value1.equals(value2); 73 } 74 75 // check the order relation between the two values 76 // the parameters are in compiled form (from getActualValue) compare(Object value1, Object value2)77 public int compare(Object value1, Object value2) { 78 return -1; 79 } 80 81 // get the length of the value 82 // the parameters are in compiled form (from getActualValue) getDataLength(Object value)83 public int getDataLength(Object value) { 84 return (value instanceof String) ? ((String)value).length() : -1; 85 } 86 87 // get the number of digits of the value 88 // the parameters are in compiled form (from getActualValue) getTotalDigits(Object value)89 public int getTotalDigits(Object value) { 90 return -1; 91 } 92 93 // get the number of fraction digits of the value 94 // the parameters are in compiled form (from getActualValue) getFractionDigits(Object value)95 public int getFractionDigits(Object value) { 96 return -1; 97 } 98 99 // check whether the character is in the range 0x30 ~ 0x39 isDigit(char ch)100 public static final boolean isDigit(char ch) { 101 return ch >= '0' && ch <= '9'; 102 } 103 104 // if the character is in the range 0x30 ~ 0x39, return its int value (0~9), 105 // otherwise, return -1 getDigit(char ch)106 public static final int getDigit(char ch) { 107 return isDigit(ch) ? ch - '0' : -1; 108 } 109 110 } // interface TypeValidator 111