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