001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.impl.dv;
019:
020: import org.apache.xerces.util.SymbolHash;
021: import org.apache.xerces.xs.XSObjectList;
022:
023: /**
024: * Defines a factory API that enables applications to <p>
025: * 1. to get the instance of specified SchemaDVFactory implementation <p>
026: * 2. to create/return built-in schema simple types <p>
027: * 3. to create user defined simple types. <p>
028: *
029: * Implementations of this abstract class can be used to get built-in simple
030: * types and create user-defined simle types. <p>
031: *
032: * The implementation should store the built-in datatypes in static data, so
033: * that they can be shared by multiple parser instance, and multiple threads.
034: *
035: * @xerces.internal
036: *
037: * @author Sandy Gao, IBM
038: *
039: * @version $Id: SchemaDVFactory.java 558582 2007-07-23 02:05:04Z mrglavas $
040: */
041: public abstract class SchemaDVFactory {
042:
043: private static final String DEFAULT_FACTORY_CLASS = "org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl";
044:
045: /**
046: * Get a default instance of SchemaDVFactory implementation.
047: *
048: * @return an instance of SchemaDVFactory implementation
049: * @exception DVFactoryException cannot create an instance of the specified
050: * class name or the default class name
051: */
052: public static final SchemaDVFactory getInstance()
053: throws DVFactoryException {
054: return getInstance(DEFAULT_FACTORY_CLASS);
055: } //getInstance(): SchemaDVFactory
056:
057: /**
058: * Get an instance of SchemaDVFactory implementation.
059: *
060: * @param factoryClass name of the schema factory implementation to instantiate.
061: * @return an instance of SchemaDVFactory implementation
062: * @exception DVFactoryException cannot create an instance of the specified
063: * class name or the default class name
064: */
065: public static final SchemaDVFactory getInstance(String factoryClass)
066: throws DVFactoryException {
067: try {
068: // if the class name is not specified, use the default one
069: return (SchemaDVFactory) (ObjectFactory
070: .newInstance(factoryClass, ObjectFactory
071: .findClassLoader(), true));
072: } catch (ClassCastException e4) {
073: throw new DVFactoryException("Schema factory class "
074: + factoryClass
075: + " does not extend from SchemaDVFactory.");
076: }
077: }
078:
079: // can't create a new object of this class
080: protected SchemaDVFactory() {
081: }
082:
083: /**
084: * Get a built-in simple type of the given name
085: * REVISIT: its still not decided within the Schema WG how to define the
086: * ur-types and if all simple types should be derived from a
087: * complex type, so as of now we ignore the fact that anySimpleType
088: * is derived from anyType, and pass 'null' as the base of
089: * anySimpleType. It needs to be changed as per the decision taken.
090: *
091: * @param name the name of the datatype
092: * @return the datatype validator of the given name
093: */
094: public abstract XSSimpleType getBuiltInType(String name);
095:
096: /**
097: * get all built-in simple types, which are stored in a SymbolHash keyed by
098: * the name
099: *
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,
116: String targetNamespace, 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,
131: String targetNamespace, short finalSet,
132: XSSimpleType itemType, 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,
146: String targetNamespace, short finalSet,
147: XSSimpleType[] memberTypes, XSObjectList annotations);
148:
149: }
|