View Javadoc
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;
22  
23  import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition;
24  
25  /**
26   * This interface <code>XSSimpleType</code> represents the simple type
27   * definition of schema component and defines methods to query the information
28   * contained.
29   * Any simple type (atomic, list or union) will implement this interface.
30   * It inherits from <code>XSTypeDecl</code>.
31   *
32   * @xerces.internal
33   *
34   * @author Sandy Gao, IBM
35   *
36   */
37  public interface XSSimpleType extends XSSimpleTypeDefinition {
38  
39      /**
40       * constants defined for the values of 'whitespace' facet.
41       * see <a href='http://www.w3.org/TR/xmlschema-2/#dt-whiteSpace'> XML Schema
42       * Part 2: Datatypes </a>
43       */
44      /** preserve the white spaces */
45      public static final short WS_PRESERVE = 0;
46      /** replace the white spaces */
47      public static final short WS_REPLACE  = 1;
48      /** collapse the white spaces */
49      public static final short WS_COLLAPSE = 2;
50  
51      /**
52       * Constant defined for the primitive built-in simple tpyes.
53       * see <a href='http://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes'>
54       * XML Schema Part 2: Datatypes </a>
55       */
56      /** "string" type */
57      public static final short PRIMITIVE_STRING        = 1;
58      /** "boolean" type */
59      public static final short PRIMITIVE_BOOLEAN       = 2;
60      /** "decimal" type */
61      public static final short PRIMITIVE_DECIMAL       = 3;
62      /** "float" type */
63      public static final short PRIMITIVE_FLOAT         = 4;
64      /** "double" type */
65      public static final short PRIMITIVE_DOUBLE        = 5;
66      /** "duration" type */
67      public static final short PRIMITIVE_DURATION      = 6;
68      /** "dataTime" type */
69      public static final short PRIMITIVE_DATETIME      = 7;
70      /** "time" type */
71      public static final short PRIMITIVE_TIME          = 8;
72      /** "date" type */
73      public static final short PRIMITIVE_DATE          = 9;
74      /** "gYearMonth" type */
75      public static final short PRIMITIVE_GYEARMONTH    = 10;
76      /** "gYear" type */
77      public static final short PRIMITIVE_GYEAR         = 11;
78      /** "gMonthDay" type */
79      public static final short PRIMITIVE_GMONTHDAY     = 12;
80      /** "gDay" type */
81      public static final short PRIMITIVE_GDAY          = 13;
82      /** "gMonth" type */
83      public static final short PRIMITIVE_GMONTH        = 14;
84      /** "hexBinary" type */
85      public static final short PRIMITIVE_HEXBINARY     = 15;
86      /** "base64Binary" type */
87      public static final short PRIMITIVE_BASE64BINARY  = 16;
88      /** "anyURI" type */
89      public static final short PRIMITIVE_ANYURI        = 17;
90      /** "QName" type */
91      public static final short PRIMITIVE_QNAME         = 18;
92      /** "precisionDecimal" type */
93      public static final short PRIMITIVE_PRECISIONDECIMAL = 19;
94      /** "NOTATION" type */
95      public static final short PRIMITIVE_NOTATION      = 20;
96  
97      /**
98       * return an ID representing the built-in primitive base type.
99       * REVISIT: This method is (currently) for internal use only.
100      *          the constants returned from this method are not finalized yet.
101      *          the names and values might change in the further.
102      *
103      * @return   an ID representing the built-in primitive base type
104      */
105     public short getPrimitiveKind();
106 
107     /**
108      * validate a given string against this simple type.
109      *
110      * @param content       the string value that needs to be validated
111      * @param context       the validation context
112      * @param validatedInfo used to store validation result
113      *
114      * @return              the actual value (QName, Boolean) of the string value
115      */
116     public Object validate(String content, ValidationContext context, ValidatedInfo validatedInfo)
117         throws InvalidDatatypeValueException;
118 
119     /**
120      * validate a given string value, represented by content.toString().
121      * note that if content is a StringBuffer, for performance reasons,
122      * it's possible that the content of the string buffer is modified.
123      *
124      * @param content       the string value that needs to be validated
125      * @param context       the validation context
126      * @param validatedInfo used to store validation result
127      *
128      * @return              the actual value (QName, Boolean) of the string value
129      */
130     public Object validate(Object content, ValidationContext context, ValidatedInfo validatedInfo)
131         throws InvalidDatatypeValueException;
132 
133     /**
134      * Validate an actual value against this simple type.
135      *
136      * @param context       the validation context
137      * @param validatedInfo used to provide the actual value and member types
138      * @exception InvalidDatatypeValueException  exception for invalid values.
139      */
140     public void validate(ValidationContext context, ValidatedInfo validatedInfo)
141         throws InvalidDatatypeValueException;
142 
143     /**
144      * If this type is created from restriction, then some facets can be applied
145      * to the simple type. <code>XSFacets</code> is used to pass the value of
146      * different facets.
147      *
148      * @param facets        the value of all the facets
149      * @param presentFacet  bit combination value of the costraining facet
150      *                      constants which are present.
151      * @param fixedFacet    bit combination value of the costraining facet
152      *                      constants which are fixed.
153      * @param context       the validation context
154      * @exception InvalidDatatypeFacetException  exception for invalid facet values.
155      */
156     public void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, ValidationContext context)
157         throws InvalidDatatypeFacetException;
158 
159     /**
160      * Check whether two actual values are equal.
161      *
162      * @param value1  the first value
163      * @param value2  the second value
164      * @return        true if the two value are equal
165      */
166     public boolean isEqual(Object value1, Object value2);
167 
168     /**
169      * Check the order of the two actual values. (May not be supported by all
170      * simple types.
171      * REVISIT: Andy believes that a compare() method is necessary.
172      *          I don't see the necessity for schema (the only place where we
173      *          need to compare two values is to check min/maxIn/Exclusive
174      *          facets, but we only need a private method for this case.)
175      *          But Andy thinks XPATH potentially needs this compare() method.
176      *
177      * @param value1  the first value
178      * @prarm value2  the second value
179      * @return        > 0 if value1 > value2
180      *                = 0 if value1 == value2
181      *                < = if value1 < value2
182      */
183     //public short compare(Object value1, Object value2);
184 
185     /**
186      * Check whether this type is or is derived from ID.
187      * REVISIT: this method makes ID special, which is not a good design.
188      *          but since ID is not a primitive, there doesn't seem to be a
189      *          clean way of doing it except to define special method like this.
190      *
191      * @return  whether this simple type is or is derived from ID.
192      */
193     public boolean isIDType();
194 
195     /**
196      * Return the whitespace corresponding to this datatype.
197      *
198      * @return valid values are WS_PRESERVE, WS_REPLACE, WS_COLLAPSE.
199      * @exception DatatypeException
200      *                   union datatypes don't have whitespace facet associated with them
201      */
202     public short getWhitespace() throws DatatypeException;
203 }