1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2002, 2003 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 2001, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.impl.dv.xs;
  58. import com.sun.org.apache.xerces.internal.impl.dv.SchemaDVFactory;
  59. import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;
  60. import com.sun.org.apache.xerces.internal.impl.dv.XSFacets;
  61. import com.sun.org.apache.xerces.internal.xs.XSConstants;
  62. import com.sun.org.apache.xerces.internal.xs.XSObjectList;
  63. import com.sun.org.apache.xerces.internal.util.SymbolHash;
  64. /**
  65. * the factory to create/return built-in schema DVs and create user-defined DVs
  66. *
  67. * @author Neeraj Bajaj, Sun Microsystems, inc.
  68. * @author Sandy Gao, IBM
  69. *
  70. * @version $Id: BaseDVFactory.java,v 1.5 2003/11/12 23:17:32 sandygao Exp $
  71. */
  72. public class BaseDVFactory extends SchemaDVFactory {
  73. static final String URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema";
  74. // there are 27 types. 53 is the closest prime number to 27*2=54.
  75. static SymbolHash fBaseTypes = new SymbolHash(53);
  76. static {
  77. createBuiltInTypes(fBaseTypes);
  78. }
  79. /**
  80. * Get a built-in simple type of the given name
  81. * REVISIT: its still not decided within the Schema WG how to define the
  82. * ur-types and if all simple types should be derived from a
  83. * complex type, so as of now we ignore the fact that anySimpleType
  84. * is derived from anyType, and pass 'null' as the base of
  85. * anySimpleType. It needs to be changed as per the decision taken.
  86. *
  87. * @param name the name of the datatype
  88. * @return the datatype validator of the given name
  89. */
  90. public XSSimpleType getBuiltInType(String name) {
  91. return (XSSimpleType)fBaseTypes.get(name);
  92. }
  93. /**
  94. * get all built-in simple types, which are stored in a hashtable keyed by
  95. * the name
  96. *
  97. * @return a hashtable which contains all built-in simple types
  98. */
  99. public SymbolHash getBuiltInTypes() {
  100. return (SymbolHash)fBaseTypes.makeClone();
  101. }
  102. /**
  103. * Create a new simple type which is derived by restriction from another
  104. * simple type.
  105. *
  106. * @param name name of the new type, could be null
  107. * @param targetNamespace target namespace of the new type, could be null
  108. * @param finalSet value of "final"
  109. * @param base base type of the new type
  110. * @param annotations set of annotations
  111. * @return the newly created simple type
  112. */
  113. public XSSimpleType createTypeRestriction(String name, String targetNamespace,
  114. short finalSet, XSSimpleType base, XSObjectList annotations) {
  115. return new XSSimpleTypeDecl((XSSimpleTypeDecl)base, name, targetNamespace, finalSet, false, annotations);
  116. }
  117. /**
  118. * Create a new simple type which is derived by list from another simple
  119. * type.
  120. *
  121. * @param name name of the new type, could be null
  122. * @param targetNamespace target namespace of the new type, could be null
  123. * @param finalSet value of "final"
  124. * @param itemType item type of the list type
  125. * @param annotations set of annotations
  126. * @return the newly created simple type
  127. */
  128. public XSSimpleType createTypeList(String name, String targetNamespace,
  129. short finalSet, XSSimpleType itemType,
  130. XSObjectList annotations) {
  131. return new XSSimpleTypeDecl(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType, false, annotations);
  132. }
  133. /**
  134. * Create a new simple type which is derived by union from a list of other
  135. * simple types.
  136. *
  137. * @param name name of the new type, could be null
  138. * @param targetNamespace target namespace of the new type, could be null
  139. * @param finalSet value of "final"
  140. * @param base member types of the union type
  141. * @param annotations set of annotations
  142. * @return the newly created simple type
  143. */
  144. public XSSimpleType createTypeUnion(String name, String targetNamespace,
  145. short finalSet, XSSimpleType[] memberTypes,
  146. XSObjectList annotations) {
  147. int typeNum = memberTypes.length;
  148. XSSimpleTypeDecl[] mtypes = new XSSimpleTypeDecl[typeNum];
  149. System.arraycopy(memberTypes, 0, mtypes, 0, typeNum);
  150. return new XSSimpleTypeDecl(name, targetNamespace, finalSet, mtypes, annotations);
  151. }
  152. // create all built-in types
  153. static void createBuiltInTypes(SymbolHash types) {
  154. // base schema simple type names
  155. final String ANYSIMPLETYPE = "anySimpleType";
  156. final String ANYURI = "anyURI";
  157. final String BASE64BINARY = "base64Binary";
  158. final String BOOLEAN = "boolean";
  159. final String BYTE = "byte";
  160. final String DATE = "date";
  161. final String DATETIME = "dateTime";
  162. final String DAY = "gDay";
  163. final String DECIMAL = "decimal";
  164. final String INT = "int";
  165. final String INTEGER = "integer";
  166. final String LONG = "long";
  167. final String NEGATIVEINTEGER = "negativeInteger";
  168. final String MONTH = "gMonth";
  169. final String MONTHDAY = "gMonthDay";
  170. final String NONNEGATIVEINTEGER= "nonNegativeInteger";
  171. final String NONPOSITIVEINTEGER= "nonPositiveInteger";
  172. final String POSITIVEINTEGER = "positiveInteger";
  173. final String SHORT = "short";
  174. final String STRING = "string";
  175. final String TIME = "time";
  176. final String UNSIGNEDBYTE = "unsignedByte";
  177. final String UNSIGNEDINT = "unsignedInt";
  178. final String UNSIGNEDLONG = "unsignedLong";
  179. final String UNSIGNEDSHORT = "unsignedShort";
  180. final String YEAR = "gYear";
  181. final String YEARMONTH = "gYearMonth";
  182. final XSFacets facets = new XSFacets();
  183. XSSimpleTypeDecl anySimpleType = XSSimpleTypeDecl.fAnySimpleType;
  184. types.put(ANYSIMPLETYPE, anySimpleType);
  185. XSSimpleTypeDecl stringDV = new XSSimpleTypeDecl(anySimpleType, STRING, XSSimpleTypeDecl.DV_STRING, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.STRING_DT);
  186. types.put(STRING, stringDV);
  187. types.put(BOOLEAN, new XSSimpleTypeDecl(anySimpleType, BOOLEAN, XSSimpleTypeDecl.DV_BOOLEAN, XSSimpleType.ORDERED_FALSE, false, true, false, true, XSConstants.BOOLEAN_DT));
  188. XSSimpleTypeDecl decimalDV = new XSSimpleTypeDecl(anySimpleType, DECIMAL, XSSimpleTypeDecl.DV_DECIMAL, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.DECIMAL_DT);
  189. types.put(DECIMAL, decimalDV);
  190. types.put(ANYURI, new XSSimpleTypeDecl(anySimpleType, ANYURI, XSSimpleTypeDecl.DV_ANYURI, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ANYURI_DT));
  191. types.put(BASE64BINARY, new XSSimpleTypeDecl(anySimpleType, BASE64BINARY, XSSimpleTypeDecl.DV_BASE64BINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.BASE64BINARY_DT));
  192. types.put(DATETIME, new XSSimpleTypeDecl(anySimpleType, DATETIME, XSSimpleTypeDecl.DV_DATETIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATETIME_DT));
  193. types.put(TIME, new XSSimpleTypeDecl(anySimpleType, TIME, XSSimpleTypeDecl.DV_TIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.TIME_DT));
  194. types.put(DATE, new XSSimpleTypeDecl(anySimpleType, DATE, XSSimpleTypeDecl.DV_DATE, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATE_DT));
  195. types.put(YEARMONTH, new XSSimpleTypeDecl(anySimpleType, YEARMONTH, XSSimpleTypeDecl.DV_GYEARMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEARMONTH_DT));
  196. types.put(YEAR, new XSSimpleTypeDecl(anySimpleType, YEAR, XSSimpleTypeDecl.DV_GYEAR, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEAR_DT));
  197. types.put(MONTHDAY, new XSSimpleTypeDecl(anySimpleType, MONTHDAY, XSSimpleTypeDecl.DV_GMONTHDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTHDAY_DT));
  198. types.put(DAY, new XSSimpleTypeDecl(anySimpleType, DAY, XSSimpleTypeDecl.DV_GDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GDAY_DT));
  199. types.put(MONTH, new XSSimpleTypeDecl(anySimpleType, MONTH, XSSimpleTypeDecl.DV_GMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTH_DT));
  200. XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER, XSSimpleTypeDecl.DV_INTEGER, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.INTEGER_DT);
  201. types.put(INTEGER, integerDV);
  202. facets.maxInclusive = "0";
  203. XSSimpleTypeDecl nonPositiveDV = new XSSimpleTypeDecl(integerDV, NONPOSITIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONPOSITIVEINTEGER_DT);
  204. nonPositiveDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
  205. types.put(NONPOSITIVEINTEGER, nonPositiveDV);
  206. facets.maxInclusive = "-1";
  207. XSSimpleTypeDecl negativeDV = new XSSimpleTypeDecl(integerDV, NEGATIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NEGATIVEINTEGER_DT);
  208. negativeDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
  209. types.put(NEGATIVEINTEGER, negativeDV);
  210. facets.maxInclusive = "9223372036854775807";
  211. facets.minInclusive = "-9223372036854775808";
  212. XSSimpleTypeDecl longDV = new XSSimpleTypeDecl(integerDV, LONG, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LONG_DT);
  213. longDV.applyFacets1(facets , (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
  214. types.put(LONG, longDV);
  215. facets.maxInclusive = "2147483647";
  216. facets.minInclusive = "-2147483648";
  217. XSSimpleTypeDecl intDV = new XSSimpleTypeDecl(longDV, INT, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.INT_DT);
  218. intDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
  219. types.put(INT, intDV);
  220. facets.maxInclusive = "32767";
  221. facets.minInclusive = "-32768";
  222. XSSimpleTypeDecl shortDV = new XSSimpleTypeDecl(intDV, SHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.SHORT_DT);
  223. shortDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
  224. types.put(SHORT, shortDV);
  225. facets.maxInclusive = "127";
  226. facets.minInclusive = "-128";
  227. XSSimpleTypeDecl byteDV = new XSSimpleTypeDecl(shortDV, BYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.BYTE_DT);
  228. byteDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
  229. types.put(BYTE, byteDV);
  230. facets.minInclusive = "0" ;
  231. XSSimpleTypeDecl nonNegativeDV = new XSSimpleTypeDecl(integerDV, NONNEGATIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONNEGATIVEINTEGER_DT);
  232. nonNegativeDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
  233. types.put(NONNEGATIVEINTEGER, nonNegativeDV);
  234. facets.maxInclusive = "18446744073709551615" ;
  235. XSSimpleTypeDecl unsignedLongDV = new XSSimpleTypeDecl(nonNegativeDV, UNSIGNEDLONG , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDLONG_DT);
  236. unsignedLongDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
  237. types.put(UNSIGNEDLONG, unsignedLongDV);
  238. facets.maxInclusive = "4294967295" ;
  239. XSSimpleTypeDecl unsignedIntDV = new XSSimpleTypeDecl(unsignedLongDV, UNSIGNEDINT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDINT_DT);
  240. unsignedIntDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
  241. types.put(UNSIGNEDINT, unsignedIntDV);
  242. facets.maxInclusive = "65535" ;
  243. XSSimpleTypeDecl unsignedShortDV = new XSSimpleTypeDecl(unsignedIntDV, UNSIGNEDSHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDSHORT_DT);
  244. unsignedShortDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
  245. types.put(UNSIGNEDSHORT, unsignedShortDV);
  246. facets.maxInclusive = "255" ;
  247. XSSimpleTypeDecl unsignedByteDV = new XSSimpleTypeDecl(unsignedShortDV, UNSIGNEDBYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDBYTE_DT);
  248. unsignedByteDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
  249. types.put(UNSIGNEDBYTE, unsignedByteDV);
  250. facets.minInclusive = "1" ;
  251. XSSimpleTypeDecl positiveIntegerDV = new XSSimpleTypeDecl(nonNegativeDV, POSITIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.POSITIVEINTEGER_DT);
  252. positiveIntegerDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
  253. types.put(POSITIVEINTEGER, positiveIntegerDV);
  254. }//createBuiltInTypes(SymbolHash)
  255. }//BaseDVFactory