View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2001-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.util.SymbolHash;
24  import com.sun.org.apache.xerces.internal.xs.XSObjectList;
25  import com.sun.org.apache.xerces.internal.utils.ObjectFactory;
26  
27  /**
28   * Defines a factory API that enables applications to <p>
29   * 1. to get the instance of specified SchemaDVFactory implementation <p>
30   * 2. to create/return built-in schema simple types <p>
31   * 3. to create user defined simple types. <p>
32   *
33   * Implementations of this abstract class can be used to get built-in simple
34   * types and create user-defined simle types. <p>
35   *
36   * The implementation should store the built-in datatypes in static data, so
37   * that they can be shared by multiple parser instance, and multiple threads.
38   *
39   * @xerces.internal
40   *
41   * @author Sandy Gao, IBM
42   *
43   * @version $Id: SchemaDVFactory.java,v 1.6 2010-11-01 04:39:43 joehw Exp $
44   */
45  public abstract class SchemaDVFactory {
46  
47      private static final String DEFAULT_FACTORY_CLASS = "com.sun.org.apache.xerces.internal.impl.dv.xs.SchemaDVFactoryImpl";
48  
49      /**
50       * Get a default instance of SchemaDVFactory implementation.
51       *
52       * @return  an instance of SchemaDVFactory implementation
53       * @exception DVFactoryException  cannot create an instance of the specified
54       *                                class name or the default class name
55       */
56      public static synchronized final SchemaDVFactory getInstance() throws DVFactoryException {
57          return getInstance(DEFAULT_FACTORY_CLASS);
58      } //getInstance():  SchemaDVFactory
59  
60  
61      /**
62       * Get an instance of SchemaDVFactory implementation.
63       *
64       * @param factoryClass   name of the schema factory implementation to instantiate.
65       * @return  an instance of SchemaDVFactory implementation
66       * @exception DVFactoryException  cannot create an instance of the specified
67       *                                class name or the default class name
68       */
69      public static synchronized final SchemaDVFactory getInstance(String factoryClass) throws DVFactoryException {
70  
71          try {
72              // if the class name is not specified, use the default one
73              return (SchemaDVFactory)(ObjectFactory.newInstance(factoryClass, true));
74          } catch (ClassCastException e4) {
75              throw new DVFactoryException("Schema factory class " + factoryClass + " does not extend from SchemaDVFactory.");
76          }
77  
78      }
79  
80      // can't create a new object of this class
81      protected SchemaDVFactory(){}
82  
83      /**
84       * Get a built-in simple type of the given name
85       * REVISIT: its still not decided within the Schema WG how to define the
86       *          ur-types and if all simple types should be derived from a
87       *          complex type, so as of now we ignore the fact that anySimpleType
88       *          is derived from anyType, and pass 'null' as the base of
89       *          anySimpleType. It needs to be changed as per the decision taken.
90       *
91       * @param name  the name of the datatype
92       * @return      the datatype validator of the given name
93       */
94      public abstract XSSimpleType getBuiltInType(String name);
95  
96      /**
97       * get all built-in simple types, which are stored in a SymbolHash keyed by
98       * the name
99       *
100      * @return      a SymbolHash which contains all built-in simple types
101      */
102     public abstract SymbolHash getBuiltInTypes();
103 
104     /**
105      * Create a new simple type which is derived by restriction from another
106      * simple type.
107      *
108      * @param name              name of the new type, could be null
109      * @param targetNamespace   target namespace of the new type, could be null
110      * @param finalSet          value of "final"
111      * @param base              base type of the new type
112      * @param annotations       set of annotations
113      * @return                  the newly created simple type
114      */
115     public abstract XSSimpleType createTypeRestriction(String name, String targetNamespace,
116                                                        short finalSet, XSSimpleType base,
117                                                        XSObjectList annotations);
118 
119     /**
120      * Create a new simple type which is derived by list from another simple
121      * type.
122      *
123      * @param name              name of the new type, could be null
124      * @param targetNamespace   target namespace of the new type, could be null
125      * @param finalSet          value of "final"
126      * @param itemType          item type of the list type
127      * @param annotations       set of annotations
128      * @return                  the newly created simple type
129      */
130     public abstract XSSimpleType createTypeList(String name, String targetNamespace,
131                                                 short finalSet, XSSimpleType itemType,
132                                                 XSObjectList annotations);
133 
134     /**
135      * Create a new simple type which is derived by union from a list of other
136      * simple types.
137      *
138      * @param name              name of the new type, could be null
139      * @param targetNamespace   target namespace of the new type, could be null
140      * @param finalSet          value of "final"
141      * @param memberTypes       member types of the union type
142      * @param annotations       set of annotations
143      * @return                  the newly created simple type
144      */
145     public abstract XSSimpleType createTypeUnion(String name, String targetNamespace,
146                                                  short finalSet, XSSimpleType[] memberTypes,
147                                                  XSObjectList annotations);
148 
149 }