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