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.XSSimpleType;
  59. import com.sun.org.apache.xerces.internal.impl.dv.XSFacets;
  60. import com.sun.org.apache.xerces.internal.util.SymbolHash;
  61. import com.sun.org.apache.xerces.internal.xs.XSConstants;
  62. /**
  63. * the factory to create/return built-in schema DVs and create user-defined DVs
  64. *
  65. * @author Neeraj Bajaj, Sun Microsystems, inc.
  66. * @author Sandy Gao, IBM
  67. *
  68. * @version $Id: FullDVFactory.java,v 1.5 2003/11/12 23:17:32 sandygao Exp $
  69. */
  70. public class FullDVFactory extends BaseDVFactory {
  71. static final String URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema";
  72. // there are 45 types. 89 is the closest prime number to 45*2=90.
  73. static SymbolHash fFullTypes = new SymbolHash(89);
  74. static {
  75. createBuiltInTypes(fFullTypes);
  76. }
  77. /**
  78. * Get a built-in simple type of the given name
  79. * REVISIT: its still not decided within the Schema WG how to define the
  80. * ur-types and if all simple types should be derived from a
  81. * complex type, so as of now we ignore the fact that anySimpleType
  82. * is derived from anyType, and pass 'null' as the base of
  83. * anySimpleType. It needs to be changed as per the decision taken.
  84. *
  85. * @param name the name of the datatype
  86. * @return the datatype validator of the given name
  87. */
  88. public XSSimpleType getBuiltInType(String name) {
  89. return (XSSimpleType)fFullTypes.get(name);
  90. }
  91. /**
  92. * get all built-in simple types, which are stored in a hashtable keyed by
  93. * the name
  94. *
  95. * @return a hashtable which contains all built-in simple types
  96. */
  97. public SymbolHash getBuiltInTypes() {
  98. return (SymbolHash)fFullTypes.makeClone();
  99. }
  100. // create all built-in types
  101. static void createBuiltInTypes(SymbolHash types) {
  102. // create base types first
  103. BaseDVFactory.createBuiltInTypes(types);
  104. // full schema simple type names
  105. final String DOUBLE = "double";
  106. final String DURATION = "duration";
  107. final String ENTITY = "ENTITY";
  108. final String ENTITIES = "ENTITIES";
  109. final String FLOAT = "float";
  110. final String HEXBINARY = "hexBinary";
  111. final String ID = "ID";
  112. final String IDREF = "IDREF";
  113. final String IDREFS = "IDREFS";
  114. final String NAME = "Name";
  115. final String NCNAME = "NCName";
  116. final String NMTOKEN = "NMTOKEN";
  117. final String NMTOKENS = "NMTOKENS";
  118. final String LANGUAGE = "language";
  119. final String NORMALIZEDSTRING = "normalizedString";
  120. final String NOTATION = "NOTATION";
  121. final String QNAME = "QName";
  122. final String STRING = "string";
  123. final String TOKEN = "token";
  124. final XSFacets facets = new XSFacets();
  125. XSSimpleTypeDecl anySimpleType = XSSimpleTypeDecl.fAnySimpleType;
  126. XSSimpleTypeDecl stringDV = (XSSimpleTypeDecl)types.get(STRING);
  127. types.put(FLOAT, new XSSimpleTypeDecl(anySimpleType, FLOAT, XSSimpleTypeDecl.DV_FLOAT, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.FLOAT_DT));
  128. types.put(DOUBLE, new XSSimpleTypeDecl(anySimpleType, DOUBLE, XSSimpleTypeDecl.DV_DOUBLE, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.DOUBLE_DT));
  129. types.put(DURATION, new XSSimpleTypeDecl(anySimpleType, DURATION, XSSimpleTypeDecl.DV_DURATION, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DURATION_DT));
  130. types.put(HEXBINARY, new XSSimpleTypeDecl(anySimpleType, HEXBINARY, XSSimpleTypeDecl.DV_HEXBINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.HEXBINARY_DT));
  131. types.put(QNAME, new XSSimpleTypeDecl(anySimpleType, QNAME, XSSimpleTypeDecl.DV_QNAME, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.QNAME_DT));
  132. types.put(NOTATION, new XSSimpleTypeDecl(anySimpleType, NOTATION, XSSimpleTypeDecl.DV_NOTATION, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.NOTATION_DT));
  133. facets.whiteSpace = XSSimpleType.WS_REPLACE;
  134. XSSimpleTypeDecl normalizedDV = new XSSimpleTypeDecl(stringDV, NORMALIZEDSTRING , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NORMALIZEDSTRING_DT);
  135. normalizedDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 );
  136. types.put(NORMALIZEDSTRING, normalizedDV);
  137. facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
  138. XSSimpleTypeDecl tokenDV = new XSSimpleTypeDecl(normalizedDV, TOKEN , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.TOKEN_DT);
  139. tokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 );
  140. types.put(TOKEN, tokenDV);
  141. facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
  142. facets.pattern = "([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*";
  143. XSSimpleTypeDecl languageDV = new XSSimpleTypeDecl(tokenDV, LANGUAGE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LANGUAGE_DT);
  144. languageDV.applyFacets1(facets, (short)(XSSimpleType.FACET_WHITESPACE | XSSimpleType.FACET_PATTERN) ,(short)0);
  145. types.put(LANGUAGE, languageDV);
  146. facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
  147. XSSimpleTypeDecl nameDV = new XSSimpleTypeDecl(tokenDV, NAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NAME_DT);
  148. nameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NAME);
  149. types.put(NAME, nameDV);
  150. facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
  151. XSSimpleTypeDecl ncnameDV = new XSSimpleTypeDecl(nameDV, NCNAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NCNAME_DT) ;
  152. ncnameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NCNAME);
  153. types.put(NCNAME, ncnameDV);
  154. types.put(ID, new XSSimpleTypeDecl(ncnameDV, ID, XSSimpleTypeDecl.DV_ID, XSSimpleType.ORDERED_FALSE, false, false, false , true, XSConstants.ID_DT));
  155. XSSimpleTypeDecl idrefDV = new XSSimpleTypeDecl(ncnameDV, IDREF , XSSimpleTypeDecl.DV_IDREF, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.IDREF_DT);
  156. types.put(IDREF, idrefDV);
  157. facets.minLength = 1;
  158. XSSimpleTypeDecl tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, idrefDV, true, null);
  159. XSSimpleTypeDecl idrefsDV = new XSSimpleTypeDecl(tempDV, IDREFS, URI_SCHEMAFORSCHEMA, (short)0, false, null);
  160. idrefsDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
  161. types.put(IDREFS, idrefsDV);
  162. XSSimpleTypeDecl entityDV = new XSSimpleTypeDecl(ncnameDV, ENTITY , XSSimpleTypeDecl.DV_ENTITY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ENTITY_DT);
  163. types.put(ENTITY, entityDV);
  164. facets.minLength = 1;
  165. tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, entityDV, true, null);
  166. XSSimpleTypeDecl entitiesDV = new XSSimpleTypeDecl(tempDV, ENTITIES, URI_SCHEMAFORSCHEMA, (short)0, false, null);
  167. entitiesDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
  168. types.put(ENTITIES, entitiesDV);
  169. facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
  170. XSSimpleTypeDecl nmtokenDV = new XSSimpleTypeDecl(tokenDV, NMTOKEN, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NMTOKEN_DT);
  171. nmtokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NMTOKEN);
  172. types.put(NMTOKEN, nmtokenDV);
  173. facets.minLength = 1;
  174. tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, nmtokenDV, true, null);
  175. XSSimpleTypeDecl nmtokensDV = new XSSimpleTypeDecl(tempDV, NMTOKENS, URI_SCHEMAFORSCHEMA, (short)0, false, null);
  176. nmtokensDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
  177. types.put(NMTOKENS, nmtokensDV);
  178. }//createBuiltInTypes(SymbolHash)
  179. }//XFormsDVFactory