jaxp/src/share/classes/javax/xml/validation/SchemaFactory.java
author dav
Thu, 27 Mar 2008 12:31:18 +0300
changeset 428 79b6854acb4a
parent 6 7f561c08de6b
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 * have any questions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
package javax.xml.validation;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import java.io.File;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import java.net.URL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import javax.xml.transform.Source;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import javax.xml.transform.stream.StreamSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import org.w3c.dom.ls.LSResourceResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import org.xml.sax.ErrorHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import org.xml.sax.SAXNotRecognizedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import org.xml.sax.SAXNotSupportedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * Factory that creates {@link Schema} objects. Entry-point to
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * the validation API.
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * {@link SchemaFactory} is a schema compiler. It reads external
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * representations of schemas and prepares them for validation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * The {@link SchemaFactory} class is not thread-safe. In other words,
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * it is the application's responsibility to ensure that at most
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * one thread is using a {@link SchemaFactory} object at any
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * given moment. Implementations are encouraged to mark methods
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * as <code>synchronized</code> to protect themselves from broken clients.
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * {@link SchemaFactory} is not re-entrant. While one of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * <code>newSchema</code> methods is being invoked, applications
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * may not attempt to recursively invoke the <code>newSchema</code> method,
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * even from the same thread.
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 * <h2><a name="schemaLanguage"></a>Schema Language</h2>
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 * This spec uses a namespace URI to designate a schema language.
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
 * The following table shows the values defined by this specification.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
 * To be compliant with the spec, the implementation
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
 * is only required to support W3C XML Schema 1.0. However,
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 * if it chooses to support other schema languages listed here,
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 * it must conform to the relevant behaviors described in this spec.
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
 * Schema languages not listed here are expected to
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
 * introduce their own URIs to represent themselves.
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
 * The {@link SchemaFactory} class is capable of locating other
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
 * implementations for other schema languages at run-time.
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
 * Note that because the XML DTD is strongly tied to the parsing process
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
 * and has a significant effect on the parsing process, it is impossible
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
 * to define the DTD validation as a process independent from parsing.
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
 * For this reason, this specification does not define the semantics for
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
 * the XML DTD. This doesn't prohibit implentors from implementing it
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
 * in a way they see fit, but <em>users are warned that any DTD
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
 * validation implemented on this interface necessarily deviate from
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
 * the XML DTD semantics as defined in the XML 1.0</em>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
 * <table border="1" cellpadding="2">
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
 *   <thead>
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
 *     <tr>
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
 *       <th>value</th>
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
 *       <th>language</th>
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
 *     </tr>
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
 *   </thead>
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
 *   <tbody>
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
 *     <tr>
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
 *       <td>{@link javax.xml.XMLConstants#W3C_XML_SCHEMA_NS_URI} ("<code>http://www.w3.org/2001/XMLSchema</code>")</td>
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
 *       <td><a href="http://www.w3.org/TR/xmlschema-1">W3C XML Schema 1.0</a></td>
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
 *     </tr>
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
 *     <tr>
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
 *       <td>{@link javax.xml.XMLConstants#RELAXNG_NS_URI} ("<code>http://relaxng.org/ns/structure/1.0</code>")</td>
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
 *       <td><a href="http://www.relaxng.org/">RELAX NG 1.0</a></td>
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
 *     </tr>
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
 *   </tbody>
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
 * </table>
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
 * @author  <a href="mailto:Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
 * @author  <a href="mailto:Neeraj.Bajaj@sun.com">Neeraj Bajaj</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
 * @since 1.5
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
public abstract class SchemaFactory {
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
     private static SecuritySupport ss = new SecuritySupport();
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
     * <p>Constructor for derived classes.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
     * <p>The constructor does nothing.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
     * <p>Derived classes must create {@link SchemaFactory} objects that have
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
     * <code>null</code> {@link ErrorHandler} and
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
     * <code>null</code> {@link LSResourceResolver}.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    protected SchemaFactory() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     * <p>Lookup an implementation of the <code>SchemaFactory</code> that supports the specified
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     * schema language and return it.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
     * <p>To find a <code>SchemaFactory</code> object for a given schema language,
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
     * this method looks the following places in the following order
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
     * where "the class loader" refers to the context class loader:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
     * <ol>
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
     *  <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
     *     If the system property
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
     *     <code>"javax.xml.validation.SchemaFactory:<i>schemaLanguage</i>"</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     *     is present (where <i>schemaLanguage</i> is the parameter
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
     *     to this method), then its value is read
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
     *     as a class name. The method will try to
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
     *     create a new instance of this class by using the class loader,
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
     *     and returns it if it is successfully created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
     *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
     *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
     *     <code>$java.home/lib/jaxp.properties</code> is read and
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
     *     the value associated with the key being the system property above
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     *     is looked for. If present, the value is processed just like above.
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
     *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
     *     <p>The class loader is asked for service provider provider-configuration files matching
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     *     <code>javax.xml.validation.SchemaFactory</code> in the resource directory META-INF/services.
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     *     See the JAR File Specification for file format and parsing rules.
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
     *     Each potential service provider is required to implement the method:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
     *     <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
     *        {@link #isSchemaLanguageSupported(String schemaLanguage)}
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
     *     </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
     *     The first service provider found in class loader order that supports the specified schema language is returned.
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
     *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
     *     Platform default <code>SchemaFactory</code> is located
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
     *     in a implementation specific way. There must be a platform default
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
     *     <code>SchemaFactory</code> for W3C XML Schema.
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
     *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     * </ol>
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     * <p>If everything fails, {@link IllegalArgumentException} will be thrown.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     * <p><strong>Tip for Trouble-shooting:</strong></p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
     * <p>See {@link java.util.Properties#load(java.io.InputStream)} for
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
     * exactly how a property file is parsed. In particular, colons ':'
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
     * need to be escaped in a property file, so make sure schema language
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
     * URIs are properly escaped in it. For example:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
     * http\://www.w3.org/2001/XMLSchema=org.acme.foo.XSSchemaFactory
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
     * @param schemaLanguage
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
     *      Specifies the schema language which the returned
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
     *      SchemaFactory will understand. See
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
     *      <a href="#schemaLanguage">the list of available
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
     *      schema languages</a> for the possible values.
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
     * @return New instance of a <code>SchemaFactory</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
     * @throws IllegalArgumentException
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
     *      If no implementation of the schema language is available.
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
     * @throws NullPointerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
     *      If the <code>schemaLanguage</code> parameter is null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
     * @see #newInstance(String schemaLanguage, String factoryClassName, ClassLoader classLoader)
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    public static final SchemaFactory newInstance(String schemaLanguage) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
        ClassLoader cl;
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
        cl = ss.getContextClassLoader();
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
        if (cl == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
            //cl = ClassLoader.getSystemClassLoader();
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
            //use the current class loader
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
            cl = SchemaFactory.class.getClassLoader();
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
        SchemaFactory f = new SchemaFactoryFinder(cl).newFactory(schemaLanguage);
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
        if (f == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
            throw new IllegalArgumentException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
                    "No SchemaFactory"
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
                    + " that implements the schema language specified by: " + schemaLanguage
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
                    + " could be loaded");
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
        return f;
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
     * <p>Obtain a new instance of a <code>SchemaFactory</code> from class name. <code>SchemaFactory</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
     * is returned if specified factory class name supports the specified schema language.
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
     * This function is useful when there are multiple providers in the classpath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
     * It gives more control to the application as it can specify which provider
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
     * should be loaded.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
     * <h2>Tip for Trouble-shooting</h2>
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
     * <p>Setting the <code>jaxp.debug</code> system property will cause
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
     * this method to print a lot of debug messages
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
     * to <code>System.err</code> about what it is doing and where it is looking at.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
     * <p> If you have problems try:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
     * java -Djaxp.debug=1 YourProgram ....
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
     * @param schemaLanguage Specifies the schema language which the returned
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
     *                          <code>SchemaFactory</code> will understand. See
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
     *                          <a href="#schemaLanguage">the list of available
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
     *                          schema languages</a> for the possible values.
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
     * @param factoryClassName fully qualified factory class name that provides implementation of <code>javax.xml.validation.SchemaFactory</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
     * @param classLoader <code>ClassLoader</code> used to load the factory class. If <code>null</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
     *                     current <code>Thread</code>'s context classLoader is used to load the factory class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
     * @return New instance of a <code>SchemaFactory</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
     * @throws IllegalArgumentException
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
     *                   if <code>factoryClassName</code> is <code>null</code>, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
     *                   the factory class cannot be loaded, instantiated or doesn't
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
     *                   support the schema language specified in <code>schemLanguage</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
     *                   parameter.
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
     * @throws NullPointerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
     *      If the <code>schemaLanguage</code> parameter is null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
     * @see #newInstance(String schemaLanguage)
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
     * @since 1.6
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    public static SchemaFactory newInstance(String schemaLanguage, String factoryClassName, ClassLoader classLoader){
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
        ClassLoader cl = classLoader;
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
        if (cl == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
            cl = ss.getContextClassLoader();
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
        SchemaFactory f = new SchemaFactoryFinder(cl).createInstance(factoryClassName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        if (f == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
            throw new IllegalArgumentException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
                    "Factory " + factoryClassName
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
                    + " could not be loaded to implement the schema language specified by: " + schemaLanguage);
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
        //if this factory supports the given schemalanguage return this factory else thrown exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        if(f.isSchemaLanguageSupported(schemaLanguage)){
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
            return f;
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
        }else{
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
            throw new IllegalArgumentException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
                    "Factory " + f.getClass().getName()
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
                    + " does not implement the schema language specified by: " + schemaLanguage);
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
         * <p>Is specified schema supported by this <code>SchemaFactory</code>?</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
         * @param schemaLanguage Specifies the schema language which the returned <code>SchemaFactory</code> will understand.
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
     *    <code>schemaLanguage</code> must specify a <a href="#schemaLanguage">valid</a> schema language.
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
         * @return <code>true</code> if <code>SchemaFactory</code> supports <code>schemaLanguage</code>, else <code>false</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
         * @throws NullPointerException If <code>schemaLanguage</code> is <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
         * @throws IllegalArgumentException If <code>schemaLanguage.length() == 0</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
         *   or <code>schemaLanguage</code> does not specify a <a href="#schemaLanguage">valid</a> schema language.
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
        public abstract boolean isSchemaLanguageSupported(String schemaLanguage);
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
     * Look up the value of a feature flag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
     * <p>The feature name is any fully-qualified URI.  It is
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
     * possible for a {@link SchemaFactory} to recognize a feature name but
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
     * temporarily be unable to return its value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
     * <p>Implementors are free (and encouraged) to invent their own features,
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
     * using names built on their own URIs.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
     * @param name The feature name, which is a non-null fully-qualified URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
     * @return The current value of the feature (true or false).
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
     * @throws SAXNotRecognizedException If the feature
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
     *   value can't be assigned or retrieved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
     * @throws SAXNotSupportedException When the
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
     *   {@link SchemaFactory} recognizes the feature name but
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
     *   cannot determine its value at this time.
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
     * @throws NullPointerException If <code>name</code> is <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
     * @see #setFeature(String, boolean)
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
    public boolean getFeature(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
        throws SAXNotRecognizedException, SAXNotSupportedException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
        if (name == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
                throw new NullPointerException("the name parameter is null");
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
        throw new SAXNotRecognizedException(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
     * <p>Set a feature for this <code>SchemaFactory</code>,
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
     * {@link Schema}s created by this factory, and by extension,
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
     * {@link Validator}s and {@link ValidatorHandler}s created by
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
     * those {@link Schema}s.
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
     * </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
     * <p>Implementors and developers should pay particular attention
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
     * to how the special {@link Schema} object returned by {@link
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
     * #newSchema()} is processed. In some cases, for example, when the
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
     * <code>SchemaFactory</code> and the class actually loading the
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
     * schema come from different implementations, it may not be possible
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
     * for <code>SchemaFactory</code> features to be inherited automatically.
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
     * Developers should
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
     * make sure that features, such as secure processing, are explicitly
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
     * set in both places.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
     * <p>The feature name is any fully-qualified URI. It is
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
     * possible for a {@link SchemaFactory} to expose a feature value but
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
     * to be unable to change the current value.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
     * <p>All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature.
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
     * When the feature is:</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
     * <ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
     *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
     *     <code>true</code>: the implementation will limit XML processing to conform to implementation limits.
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
     *     Examples include enity expansion limits and XML Schema constructs that would consume large amounts of resources.
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
     *     If XML processing is limited for security reasons, it will be reported via a call to the registered
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
     *    {@link ErrorHandler#fatalError(SAXParseException exception)}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
     *     See {@link #setErrorHandler(ErrorHandler errorHandler)}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
     *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
     *   <li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
     *     <code>false</code>: the implementation will processing XML according to the XML specifications without
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
     *     regard to possible implementation limits.
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
     *   </li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
     * </ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
     * @param name The feature name, which is a non-null fully-qualified URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
     * @param value The requested value of the feature (true or false).
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
     * @throws SAXNotRecognizedException If the feature
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
     *   value can't be assigned or retrieved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
     * @throws SAXNotSupportedException When the
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
     *   {@link SchemaFactory} recognizes the feature name but
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
     *   cannot set the requested value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
     * @throws NullPointerException If <code>name</code> is <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
     * @see #getFeature(String)
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
    public void setFeature(String name, boolean value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        throws SAXNotRecognizedException, SAXNotSupportedException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
        if (name == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
                throw new NullPointerException("the name parameter is null");
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
        throw new SAXNotRecognizedException(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
     * Set the value of a property.
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
     * <p>The property name is any fully-qualified URI.  It is
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
     * possible for a {@link SchemaFactory} to recognize a property name but
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
     * to be unable to change the current value.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
     * <p>{@link SchemaFactory}s are not required to recognize setting
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
     * any specific property names.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
     * @param name The property name, which is a non-null fully-qualified URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
     * @param object The requested value for the property.
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
     * @throws SAXNotRecognizedException If the property
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
     *   value can't be assigned or retrieved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
     * @throws SAXNotSupportedException When the
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
     *   {@link SchemaFactory} recognizes the property name but
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
     *   cannot set the requested value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
     * @throws NullPointerException If <code>name</code> is <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
    public void setProperty(String name, Object object)
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
        throws SAXNotRecognizedException, SAXNotSupportedException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
        if (name == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
                throw new NullPointerException("the name parameter is null");
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
        throw new SAXNotRecognizedException(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
     * Look up the value of a property.
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
     * <p>The property name is any fully-qualified URI.  It is
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
     * possible for a {@link SchemaFactory} to recognize a property name but
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
     * temporarily be unable to return its value.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
     * <p>{@link SchemaFactory}s are not required to recognize any specific
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
     * property names.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
     * <p>Implementors are free (and encouraged) to invent their own properties,
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
     * using names built on their own URIs.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
     * @param name The property name, which is a non-null fully-qualified URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
     * @return The current value of the property.
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
     * @throws SAXNotRecognizedException If the property
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
     *   value can't be assigned or retrieved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
     * @throws SAXNotSupportedException When the
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
     *   XMLReader recognizes the property name but
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
     *   cannot determine its value at this time.
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
     * @throws NullPointerException If <code>name</code> is <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
     * @see #setProperty(String, Object)
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
    public Object getProperty(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
        throws SAXNotRecognizedException, SAXNotSupportedException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
        if (name == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
                throw new NullPointerException("the name parameter is null");
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
        throw new SAXNotRecognizedException(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
     * Sets the {@link ErrorHandler} to receive errors encountered
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
     * during the <code>newSchema</code> method invocation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
     * Error handler can be used to customize the error handling process
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
     * during schema parsing. When an {@link ErrorHandler} is set,
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
     * errors found during the parsing of schemas will be first sent
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
     * to the {@link ErrorHandler}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
     * The error handler can abort the parsing of a schema immediately
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
     * by throwing {@link SAXException} from the handler. Or for example
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
     * it can print an error to the screen and try to continue the
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
     * processing by returning normally from the {@link ErrorHandler}
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
     * If any {@link Throwable} (or instances of its derived classes)
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
     * is thrown from an {@link ErrorHandler},
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
     * the caller of the <code>newSchema</code> method will be thrown
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
     * the same {@link Throwable} object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
     * {@link SchemaFactory} is not allowed to
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
     * throw {@link SAXException} without first reporting it to
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
     * {@link ErrorHandler}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
     * Applications can call this method even during a {@link Schema}
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
     * is being parsed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
     * When the {@link ErrorHandler} is null, the implementation will
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
     * behave as if the following {@link ErrorHandler} is set:
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
     * class DraconianErrorHandler implements {@link ErrorHandler} {
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
     *     public void fatalError( {@link org.xml.sax.SAXParseException} e ) throws {@link SAXException} {
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
     *         throw e;
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
     *     }
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
     *     public void error( {@link org.xml.sax.SAXParseException} e ) throws {@link SAXException} {
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
     *         throw e;
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
     *     }
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
     *     public void warning( {@link org.xml.sax.SAXParseException} e ) throws {@link SAXException} {
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
     *         // noop
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
     *     }
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
     * }
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
     * When a new {@link SchemaFactory} object is created, initially
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
     * this field is set to null. This field will <em>NOT</em> be
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
     * inherited to {@link Schema}s, {@link Validator}s, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
     * {@link ValidatorHandler}s that are created from this {@link SchemaFactory}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
     * @param errorHandler A new error handler to be set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
     *   This parameter can be <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
    public abstract void setErrorHandler(ErrorHandler errorHandler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
     * Gets the current {@link ErrorHandler} set to this {@link SchemaFactory}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
     * @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
     *      This method returns the object that was last set through
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
     *      the {@link #setErrorHandler(ErrorHandler)} method, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
     *      if that method has never been called since this {@link SchemaFactory}
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
     *      has created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
     * @see #setErrorHandler(ErrorHandler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
    public abstract ErrorHandler getErrorHandler();
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
     * Sets the {@link LSResourceResolver} to customize
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
     * resource resolution when parsing schemas.
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
     * {@link SchemaFactory} uses a {@link LSResourceResolver}
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
     * when it needs to locate external resources while parsing schemas,
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
     * although exactly what constitutes "locating external resources" is
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
     * up to each schema language. For example, for W3C XML Schema,
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
     * this includes files <code>&lt;include></code>d or <code>&lt;import></code>ed,
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
     * and DTD referenced from schema files, etc.
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
     * Applications can call this method even during a {@link Schema}
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
     * is being parsed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
     * When the {@link LSResourceResolver} is null, the implementation will
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
     * behave as if the following {@link LSResourceResolver} is set:
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
     * class DumbDOMResourceResolver implements {@link LSResourceResolver} {
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
     *     public {@link org.w3c.dom.ls.LSInput} resolveResource(
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
     *         String publicId, String systemId, String baseURI) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
     *         return null; // always return null
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
     *     }
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
     * }
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
     * If a {@link LSResourceResolver} throws a {@link RuntimeException}
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
     *  (or instances of its derived classes),
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
     * then the {@link SchemaFactory} will abort the parsing and
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
     * the caller of the <code>newSchema</code> method will receive
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
     * the same {@link RuntimeException}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
     * When a new {@link SchemaFactory} object is created, initially
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
     * this field is set to null.  This field will <em>NOT</em> be
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
     * inherited to {@link Schema}s, {@link Validator}s, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
     * {@link ValidatorHandler}s that are created from this {@link SchemaFactory}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
     * @param   resourceResolver
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
     *      A new resource resolver to be set. This parameter can be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
    public abstract void setResourceResolver(LSResourceResolver resourceResolver);
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
     * Gets the current {@link LSResourceResolver} set to this {@link SchemaFactory}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
     * @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
     *      This method returns the object that was last set through
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
     *      the {@link #setResourceResolver(LSResourceResolver)} method, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
     *      if that method has never been called since this {@link SchemaFactory}
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
     *      has created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
     * @see #setErrorHandler(ErrorHandler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
    public abstract LSResourceResolver getResourceResolver();
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
     * <p>Parses the specified source as a schema and returns it as a schema.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
     * <p>This is a convenience method for {@link #newSchema(Source[] schemas)}.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
     * @param schema Source that represents a schema.
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
     * @return New <code>Schema</code> from parsing <code>schema</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
     * @throws SAXException If a SAX error occurs during parsing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
     * @throws NullPointerException if <code>schema</code> is null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
    public Schema newSchema(Source schema) throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
        return newSchema(new Source[]{schema});
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
     * <p>Parses the specified <code>File</code> as a schema and returns it as a <code>Schema</code>.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
     * <p>This is a convenience method for {@link #newSchema(Source schema)}.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
     * @param schema File that represents a schema.
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
     * @return New <code>Schema</code> from parsing <code>schema</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
     * @throws SAXException If a SAX error occurs during parsing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
     * @throws NullPointerException if <code>schema</code> is null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
    public Schema newSchema(File schema) throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
        return newSchema(new StreamSource(schema));
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
     * <p>Parses the specified <code>URL</code> as a schema and returns it as a <code>Schema</code>.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
     * <p>This is a convenience method for {@link #newSchema(Source schema)}.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
     * @param schema <code>URL</code> that represents a schema.
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
     * @return New <code>Schema</code> from parsing <code>schema</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
     * @throws SAXException If a SAX error occurs during parsing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
     * @throws NullPointerException if <code>schema</code> is null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
    public Schema newSchema(URL schema) throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
        return newSchema(new StreamSource(schema.toExternalForm()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
     * Parses the specified source(s) as a schema and returns it as a schema.
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
     * The callee will read all the {@link Source}s and combine them into a
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
     * single schema. The exact semantics of the combination depends on the schema
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
     * language that this {@link SchemaFactory} object is created for.
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
     * When an {@link ErrorHandler} is set, the callee will report all the errors
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
     * found in sources to the handler. If the handler throws an exception, it will
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
     * abort the schema compilation and the same exception will be thrown from
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
     * this method. Also, after an error is reported to a handler, the callee is allowed
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
     * to abort the further processing by throwing it. If an error handler is not set,
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
     * the callee will throw the first error it finds in the sources.
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
     * <h2>W3C XML Schema 1.0</h2>
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
     * The resulting schema contains components from the specified sources.
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
     * The same result would be achieved if all these sources were
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
     * imported, using appropriate values for schemaLocation and namespace,
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
     * into a single schema document with a different targetNamespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
     * and no components of its own, if the import elements were given
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
     * in the same order as the sources.  Section 4.2.3 of the XML Schema
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
     * recommendation describes the options processors have in this
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
     * regard.  While a processor should be consistent in its treatment of
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
     * JAXP schema sources and XML Schema imports, the behaviour between
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
     * JAXP-compliant parsers may vary; in particular, parsers may choose
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
     * to ignore all but the first &lt;import> for a given namespace,
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
     * regardless of information provided in schemaLocation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
     * If the parsed set of schemas includes error(s) as
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
     * specified in the section 5.1 of the XML Schema spec, then
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
     * the error must be reported to the {@link ErrorHandler}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
     * <h2>RELAX NG</h2>
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
     * <p>For RELAX NG, this method must throw {@link UnsupportedOperationException}
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
     * if <code>schemas.length!=1</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
     * @param schemas
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
     *      inputs to be parsed. {@link SchemaFactory} is required
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
     *      to recognize {@link javax.xml.transform.sax.SAXSource},
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
     *      {@link StreamSource},
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
     *      {@link javax.xml.transform.stax.StAXSource},
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
     *      and {@link javax.xml.transform.dom.DOMSource}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
     *      Input schemas must be XML documents or
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
     *      XML elements and must not be null. For backwards compatibility,
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
     *      the results of passing anything other than
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
     *      a document or element are implementation-dependent.
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
     *      Implementations must either recognize and process the input
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
     *      or thrown an IllegalArgumentException.
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
     * @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
     *      Always return a non-null valid {@link Schema} object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
     *      Note that when an error has been reported, there is no
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
     *      guarantee that the returned {@link Schema} object is
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
     *      meaningful.
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
     * @throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
     *      If an error is found during processing the specified inputs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
     *      When an {@link ErrorHandler} is set, errors are reported to
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
     *      there first. See {@link #setErrorHandler(ErrorHandler)}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
     * @throws NullPointerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
     *      If the <code>schemas</code> parameter itself is null or
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
     *      any item in the array is null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
     * @throws IllegalArgumentException
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
     *      If any item in the array is not recognized by this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
     * @throws UnsupportedOperationException
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
     *      If the schema language doesn't support this operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
    public abstract Schema newSchema(Source[] schemas) throws SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
     * Creates a special {@link Schema} object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
     * <p>The exact semantics of the returned {@link Schema} object
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
     * depend on the schema language for which this {@link SchemaFactory}
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
     * is created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
     * <p>Also, implementations are allowed to use implementation-specific
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
     * property/feature to alter the semantics of this method.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
     * <p>Implementors and developers should pay particular attention
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
     * to how the features set on this {@link SchemaFactory} are
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
     * processed by this special {@link Schema}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
     * In some cases, for example, when the
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
     * {@link SchemaFactory} and the class actually loading the
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
     * schema come from different implementations, it may not be possible
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
     * for {@link SchemaFactory} features to be inherited automatically.
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
     * Developers should
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
     * make sure that features, such as secure processing, are explicitly
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
     * set in both places.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
     * <h2>W3C XML Schema 1.0</h2>
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
     * For XML Schema, this method creates a {@link Schema} object that
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
     * performs validation by using location hints specified in documents.
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
     * The returned {@link Schema} object assumes that if documents
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
     * refer to the same URL in the schema location hints,
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
     * they will always resolve to the same schema document. This
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
     * asusmption allows implementations to reuse parsed results of
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
     * schema documents so that multiple validations against the same
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
     * schema will run faster.
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
     * Note that the use of schema location hints introduces a
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
     * vulnerability to denial-of-service attacks.
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
     * <h2>RELAX NG</h2>
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
     * RELAX NG does not support this operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
     * @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
     *      Always return non-null valid {@link Schema} object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
     * @throws UnsupportedOperationException
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
     *      If this operation is not supported by the callee.
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
     * @throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
     *      If this operation is supported but failed for some reason.
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
    public abstract Schema newSchema() throws SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
}