Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/javax/xml/validation/SchemaFactory.java
32285 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.validation;2627import java.io.File;28import java.net.URL;29import javax.xml.transform.Source;30import javax.xml.transform.stream.StreamSource;31import org.w3c.dom.ls.LSResourceResolver;32import org.xml.sax.ErrorHandler;33import org.xml.sax.SAXException;34import org.xml.sax.SAXNotRecognizedException;35import org.xml.sax.SAXNotSupportedException;36import org.xml.sax.SAXParseException;3738/**39* Factory that creates {@link Schema} objects. Entry-point to40* the validation API.41*42* <p>43* {@link SchemaFactory} is a schema compiler. It reads external44* representations of schemas and prepares them for validation.45*46* <p>47* The {@link SchemaFactory} class is not thread-safe. In other words,48* it is the application's responsibility to ensure that at most49* one thread is using a {@link SchemaFactory} object at any50* given moment. Implementations are encouraged to mark methods51* as <code>synchronized</code> to protect themselves from broken clients.52*53* <p>54* {@link SchemaFactory} is not re-entrant. While one of the55* <code>newSchema</code> methods is being invoked, applications56* may not attempt to recursively invoke the <code>newSchema</code> method,57* even from the same thread.58*59* <h2><a name="schemaLanguage"></a>Schema Language</h2>60* <p>61* This spec uses a namespace URI to designate a schema language.62* The following table shows the values defined by this specification.63* <p>64* To be compliant with the spec, the implementation65* is only required to support W3C XML Schema 1.0. However,66* if it chooses to support other schema languages listed here,67* it must conform to the relevant behaviors described in this spec.68*69* <p>70* Schema languages not listed here are expected to71* introduce their own URIs to represent themselves.72* The {@link SchemaFactory} class is capable of locating other73* implementations for other schema languages at run-time.74*75* <p>76* Note that because the XML DTD is strongly tied to the parsing process77* and has a significant effect on the parsing process, it is impossible78* to define the DTD validation as a process independent from parsing.79* For this reason, this specification does not define the semantics for80* the XML DTD. This doesn't prohibit implementors from implementing it81* in a way they see fit, but <em>users are warned that any DTD82* validation implemented on this interface necessarily deviate from83* the XML DTD semantics as defined in the XML 1.0</em>.84*85* <table border="1" cellpadding="2">86* <thead>87* <tr>88* <th>value</th>89* <th>language</th>90* </tr>91* </thead>92* <tbody>93* <tr>94* <td>{@link javax.xml.XMLConstants#W3C_XML_SCHEMA_NS_URI} ("<code>http://www.w3.org/2001/XMLSchema</code>")</td>95* <td><a href="http://www.w3.org/TR/xmlschema-1">W3C XML Schema 1.0</a></td>96* </tr>97* <tr>98* <td>{@link javax.xml.XMLConstants#RELAXNG_NS_URI} ("<code>http://relaxng.org/ns/structure/1.0</code>")</td>99* <td><a href="http://www.relaxng.org/">RELAX NG 1.0</a></td>100* </tr>101* </tbody>102* </table>103*104* @author <a href="mailto:[email protected]">Kohsuke Kawaguchi</a>105* @author <a href="mailto:[email protected]">Neeraj Bajaj</a>106*107* @since 1.5108*/109public abstract class SchemaFactory {110111private static SecuritySupport ss = new SecuritySupport();112113/**114* <p>Constructor for derived classes.</p>115*116* <p>The constructor does nothing.</p>117*118* <p>Derived classes must create {@link SchemaFactory} objects that have119* <code>null</code> {@link ErrorHandler} and120* <code>null</code> {@link LSResourceResolver}.</p>121*/122protected SchemaFactory() {123}124125/**126* <p>Lookup an implementation of the <code>SchemaFactory</code> that supports the specified127* schema language and return it.</p>128*129* <p>To find a <code>SchemaFactory</code> object for a given schema language,130* this method looks the following places in the following order131* where "the class loader" refers to the context class loader:</p>132* <ol>133* <li>134* If the system property135* <code>"javax.xml.validation.SchemaFactory:<i>schemaLanguage</i>"</code>136* is present (where <i>schemaLanguage</i> is the parameter137* to this method), then its value is read138* as a class name. The method will try to139* create a new instance of this class by using the class loader,140* and returns it if it is successfully created.141* </li>142* <li>143* <code>$java.home/lib/jaxp.properties</code> is read and144* the value associated with the key being the system property above145* is looked for. If present, the value is processed just like above.146* </li>147* <li>148* Use the service-provider loading facilities, defined by the149* {@link java.util.ServiceLoader} class, to attempt to locate and load an150* implementation of the service using the {@linkplain151* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}:152* the service-provider loading facility will use the {@linkplain153* java.lang.Thread#getContextClassLoader() current thread's context class loader}154* to attempt to load the service. If the context class155* loader is null, the {@linkplain156* ClassLoader#getSystemClassLoader() system class loader} will be used.157* <br>158* Each potential service provider is required to implement the method159* {@link #isSchemaLanguageSupported(String schemaLanguage)}.160* <br>161* The first service provider found that supports the specified schema162* language is returned.163* <br>164* In case of {@link java.util.ServiceConfigurationError} a165* {@link SchemaFactoryConfigurationError} will be thrown.166* </li>167* <li>168* Platform default <code>SchemaFactory</code> is located169* in a implementation specific way. There must be a platform default170* <code>SchemaFactory</code> for W3C XML Schema.171* </li>172* </ol>173*174* <p>If everything fails, {@link IllegalArgumentException} will be thrown.</p>175*176* <p><strong>Tip for Trouble-shooting:</strong></p>177* <p>See {@link java.util.Properties#load(java.io.InputStream)} for178* exactly how a property file is parsed. In particular, colons ':'179* need to be escaped in a property file, so make sure schema language180* URIs are properly escaped in it. For example:</p>181* <pre>182* http\://www.w3.org/2001/XMLSchema=org.acme.foo.XSSchemaFactory183* </pre>184*185* @param schemaLanguage186* Specifies the schema language which the returned187* SchemaFactory will understand. See188* <a href="#schemaLanguage">the list of available189* schema languages</a> for the possible values.190*191* @return New instance of a <code>SchemaFactory</code>192*193* @throws IllegalArgumentException194* If no implementation of the schema language is available.195* @throws NullPointerException196* If the <code>schemaLanguage</code> parameter is null.197* @throws SchemaFactoryConfigurationError198* If a configuration error is encountered.199*200* @see #newInstance(String schemaLanguage, String factoryClassName, ClassLoader classLoader)201*/202public static SchemaFactory newInstance(String schemaLanguage) {203ClassLoader cl;204cl = ss.getContextClassLoader();205206if (cl == null) {207//cl = ClassLoader.getSystemClassLoader();208//use the current class loader209cl = SchemaFactory.class.getClassLoader();210}211212SchemaFactory f = new SchemaFactoryFinder(cl).newFactory(schemaLanguage);213if (f == null) {214throw new IllegalArgumentException(215"No SchemaFactory"216+ " that implements the schema language specified by: " + schemaLanguage217+ " could be loaded");218}219return f;220}221222/**223* <p>Obtain a new instance of a <code>SchemaFactory</code> from class name. <code>SchemaFactory</code>224* is returned if specified factory class name supports the specified schema language.225* This function is useful when there are multiple providers in the classpath.226* It gives more control to the application as it can specify which provider227* should be loaded.</p>228*229* <h2>Tip for Trouble-shooting</h2>230* <p>Setting the <code>jaxp.debug</code> system property will cause231* this method to print a lot of debug messages232* to <code>System.err</code> about what it is doing and where it is looking at.</p>233*234* <p> If you have problems try:</p>235* <pre>236* java -Djaxp.debug=1 YourProgram ....237* </pre>238*239* @param schemaLanguage Specifies the schema language which the returned240* <code>SchemaFactory</code> will understand. See241* <a href="#schemaLanguage">the list of available242* schema languages</a> for the possible values.243*244* @param factoryClassName fully qualified factory class name that provides implementation of <code>javax.xml.validation.SchemaFactory</code>.245*246* @param classLoader <code>ClassLoader</code> used to load the factory class. If <code>null</code>247* current <code>Thread</code>'s context classLoader is used to load the factory class.248*249* @return New instance of a <code>SchemaFactory</code>250*251* @throws IllegalArgumentException252* if <code>factoryClassName</code> is <code>null</code>, or253* the factory class cannot be loaded, instantiated or doesn't254* support the schema language specified in <code>schemLanguage</code>255* parameter.256*257* @throws NullPointerException258* If the <code>schemaLanguage</code> parameter is null.259*260* @see #newInstance(String schemaLanguage)261*262* @since 1.6263*/264public static SchemaFactory newInstance(String schemaLanguage, String factoryClassName, ClassLoader classLoader){265ClassLoader cl = classLoader;266267if (cl == null) {268cl = ss.getContextClassLoader();269}270271SchemaFactory f = new SchemaFactoryFinder(cl).createInstance(factoryClassName);272if (f == null) {273throw new IllegalArgumentException(274"Factory " + factoryClassName275+ " could not be loaded to implement the schema language specified by: " + schemaLanguage);276}277//if this factory supports the given schemalanguage return this factory else thrown exception278if(f.isSchemaLanguageSupported(schemaLanguage)){279return f;280}else{281throw new IllegalArgumentException(282"Factory " + f.getClass().getName()283+ " does not implement the schema language specified by: " + schemaLanguage);284}285286}287288/**289* <p>Is specified schema supported by this <code>SchemaFactory</code>?</p>290*291* @param schemaLanguage Specifies the schema language which the returned <code>SchemaFactory</code> will understand.292* <code>schemaLanguage</code> must specify a <a href="#schemaLanguage">valid</a> schema language.293*294* @return <code>true</code> if <code>SchemaFactory</code> supports <code>schemaLanguage</code>, else <code>false</code>.295*296* @throws NullPointerException If <code>schemaLanguage</code> is <code>null</code>.297* @throws IllegalArgumentException If <code>schemaLanguage.length() == 0</code>298* or <code>schemaLanguage</code> does not specify a <a href="#schemaLanguage">valid</a> schema language.299*/300public abstract boolean isSchemaLanguageSupported(String schemaLanguage);301302/**303* Look up the value of a feature flag.304*305* <p>The feature name is any fully-qualified URI. It is306* possible for a {@link SchemaFactory} to recognize a feature name but307* temporarily be unable to return its value.308*309* <p>Implementors are free (and encouraged) to invent their own features,310* using names built on their own URIs.</p>311*312* @param name The feature name, which is a non-null fully-qualified URI.313*314* @return The current value of the feature (true or false).315*316* @throws SAXNotRecognizedException If the feature317* value can't be assigned or retrieved.318* @throws SAXNotSupportedException When the319* {@link SchemaFactory} recognizes the feature name but320* cannot determine its value at this time.321* @throws NullPointerException If <code>name</code> is <code>null</code>.322*323* @see #setFeature(String, boolean)324*/325public boolean getFeature(String name)326throws SAXNotRecognizedException, SAXNotSupportedException {327328if (name == null) {329throw new NullPointerException("the name parameter is null");330}331throw new SAXNotRecognizedException(name);332}333334/**335* <p>Set a feature for this <code>SchemaFactory</code>,336* {@link Schema}s created by this factory, and by extension,337* {@link Validator}s and {@link ValidatorHandler}s created by338* those {@link Schema}s.339* </p>340*341* <p>Implementors and developers should pay particular attention342* to how the special {@link Schema} object returned by {@link343* #newSchema()} is processed. In some cases, for example, when the344* <code>SchemaFactory</code> and the class actually loading the345* schema come from different implementations, it may not be possible346* for <code>SchemaFactory</code> features to be inherited automatically.347* Developers should348* make sure that features, such as secure processing, are explicitly349* set in both places.</p>350*351* <p>The feature name is any fully-qualified URI. It is352* possible for a {@link SchemaFactory} to expose a feature value but353* to be unable to change the current value.</p>354*355* <p>All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature.356* When the feature is:</p>357* <ul>358* <li>359* <code>true</code>: the implementation will limit XML processing to conform to implementation limits.360* Examples include enity expansion limits and XML Schema constructs that would consume large amounts of resources.361* If XML processing is limited for security reasons, it will be reported via a call to the registered362* {@link ErrorHandler#fatalError(SAXParseException exception)}.363* See {@link #setErrorHandler(ErrorHandler errorHandler)}.364* </li>365* <li>366* <code>false</code>: the implementation will processing XML according to the XML specifications without367* regard to possible implementation limits.368* </li>369* </ul>370*371* @param name The feature name, which is a non-null fully-qualified URI.372* @param value The requested value of the feature (true or false).373*374* @throws SAXNotRecognizedException If the feature375* value can't be assigned or retrieved.376* @throws SAXNotSupportedException When the377* {@link SchemaFactory} recognizes the feature name but378* cannot set the requested value.379* @throws NullPointerException If <code>name</code> is <code>null</code>.380*381* @see #getFeature(String)382*/383public void setFeature(String name, boolean value)384throws SAXNotRecognizedException, SAXNotSupportedException {385386if (name == null) {387throw new NullPointerException("the name parameter is null");388}389throw new SAXNotRecognizedException(name);390}391392/**393* Set the value of a property.394*395* <p>The property name is any fully-qualified URI. It is396* possible for a {@link SchemaFactory} to recognize a property name but397* to be unable to change the current value.</p>398*399* <p>400* All implementations that implement JAXP 1.5 or newer are required to401* support the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} and402* {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_SCHEMA} properties.403* </p>404* <ul>405* <li>406* <p>Access to external DTDs in Schema files is restricted to the protocols407* specified by the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property.408* If access is denied during the creation of new Schema due to the restriction409* of this property, {@link org.xml.sax.SAXException} will be thrown by the410* {@link #newSchema(Source)} or {@link #newSchema(File)}411* or {@link #newSchema(URL)} or or {@link #newSchema(Source[])} method.</p>412*413* <p>Access to external DTDs in xml source files is restricted to the protocols414* specified by the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property.415* If access is denied during validation due to the restriction416* of this property, {@link org.xml.sax.SAXException} will be thrown by the417* {@link javax.xml.validation.Validator#validate(Source)} or418* {@link javax.xml.validation.Validator#validate(Source, Result)} method.</p>419*420* <p>Access to external reference set by the schemaLocation attribute is421* restricted to the protocols specified by the422* {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_SCHEMA} property.423* If access is denied during validation due to the restriction of this property,424* {@link org.xml.sax.SAXException} will be thrown by the425* {@link javax.xml.validation.Validator#validate(Source)} or426* {@link javax.xml.validation.Validator#validate(Source, Result)} method.</p>427*428* <p>Access to external reference set by the Import429* and Include element is restricted to the protocols specified by the430* {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_SCHEMA} property.431* If access is denied during the creation of new Schema due to the restriction432* of this property, {@link org.xml.sax.SAXException} will be thrown by the433* {@link #newSchema(Source)} or {@link #newSchema(File)}434* or {@link #newSchema(URL)} or {@link #newSchema(Source[])} method.</p>435* </li>436* </ul>437*438* @param name The property name, which is a non-null fully-qualified URI.439* @param object The requested value for the property.440*441* @throws SAXNotRecognizedException If the property442* value can't be assigned or retrieved.443* @throws SAXNotSupportedException When the444* {@link SchemaFactory} recognizes the property name but445* cannot set the requested value.446* @throws NullPointerException If <code>name</code> is <code>null</code>.447*/448public void setProperty(String name, Object object)449throws SAXNotRecognizedException, SAXNotSupportedException {450451if (name == null) {452throw new NullPointerException("the name parameter is null");453}454throw new SAXNotRecognizedException(name);455}456457/**458* Look up the value of a property.459*460* <p>The property name is any fully-qualified URI. It is461* possible for a {@link SchemaFactory} to recognize a property name but462* temporarily be unable to return its value.</p>463*464* <p>{@link SchemaFactory}s are not required to recognize any specific465* property names.</p>466*467* <p>Implementors are free (and encouraged) to invent their own properties,468* using names built on their own URIs.</p>469*470* @param name The property name, which is a non-null fully-qualified URI.471*472* @return The current value of the property.473*474* @throws SAXNotRecognizedException If the property475* value can't be assigned or retrieved.476* @throws SAXNotSupportedException When the477* XMLReader recognizes the property name but478* cannot determine its value at this time.479* @throws NullPointerException If <code>name</code> is <code>null</code>.480*481* @see #setProperty(String, Object)482*/483public Object getProperty(String name)484throws SAXNotRecognizedException, SAXNotSupportedException {485486if (name == null) {487throw new NullPointerException("the name parameter is null");488}489throw new SAXNotRecognizedException(name);490}491492/**493* Sets the {@link ErrorHandler} to receive errors encountered494* during the <code>newSchema</code> method invocation.495*496* <p>497* Error handler can be used to customize the error handling process498* during schema parsing. When an {@link ErrorHandler} is set,499* errors found during the parsing of schemas will be first sent500* to the {@link ErrorHandler}.501*502* <p>503* The error handler can abort the parsing of a schema immediately504* by throwing {@link SAXException} from the handler. Or for example505* it can print an error to the screen and try to continue the506* processing by returning normally from the {@link ErrorHandler}507*508* <p>509* If any {@link Throwable} (or instances of its derived classes)510* is thrown from an {@link ErrorHandler},511* the caller of the <code>newSchema</code> method will be thrown512* the same {@link Throwable} object.513*514* <p>515* {@link SchemaFactory} is not allowed to516* throw {@link SAXException} without first reporting it to517* {@link ErrorHandler}.518*519* <p>520* Applications can call this method even during a {@link Schema}521* is being parsed.522*523* <p>524* When the {@link ErrorHandler} is null, the implementation will525* behave as if the following {@link ErrorHandler} is set:526* <pre>527* class DraconianErrorHandler implements {@link ErrorHandler} {528* public void fatalError( {@link org.xml.sax.SAXParseException} e ) throws {@link SAXException} {529* throw e;530* }531* public void error( {@link org.xml.sax.SAXParseException} e ) throws {@link SAXException} {532* throw e;533* }534* public void warning( {@link org.xml.sax.SAXParseException} e ) throws {@link SAXException} {535* // noop536* }537* }538* </pre>539*540* <p>541* When a new {@link SchemaFactory} object is created, initially542* this field is set to null. This field will <em>NOT</em> be543* inherited to {@link Schema}s, {@link Validator}s, or544* {@link ValidatorHandler}s that are created from this {@link SchemaFactory}.545*546* @param errorHandler A new error handler to be set.547* This parameter can be <code>null</code>.548*/549public abstract void setErrorHandler(ErrorHandler errorHandler);550551/**552* Gets the current {@link ErrorHandler} set to this {@link SchemaFactory}.553*554* @return555* This method returns the object that was last set through556* the {@link #setErrorHandler(ErrorHandler)} method, or null557* if that method has never been called since this {@link SchemaFactory}558* has created.559*560* @see #setErrorHandler(ErrorHandler)561*/562public abstract ErrorHandler getErrorHandler();563564/**565* Sets the {@link LSResourceResolver} to customize566* resource resolution when parsing schemas.567*568* <p>569* {@link SchemaFactory} uses a {@link LSResourceResolver}570* when it needs to locate external resources while parsing schemas,571* although exactly what constitutes "locating external resources" is572* up to each schema language. For example, for W3C XML Schema,573* this includes files <code><include></code>d or <code><import></code>ed,574* and DTD referenced from schema files, etc.575*576* <p>577* Applications can call this method even during a {@link Schema}578* is being parsed.579*580* <p>581* When the {@link LSResourceResolver} is null, the implementation will582* behave as if the following {@link LSResourceResolver} is set:583* <pre>584* class DumbDOMResourceResolver implements {@link LSResourceResolver} {585* public {@link org.w3c.dom.ls.LSInput} resolveResource(586* String publicId, String systemId, String baseURI) {587*588* return null; // always return null589* }590* }591* </pre>592*593* <p>594* If a {@link LSResourceResolver} throws a {@link RuntimeException}595* (or instances of its derived classes),596* then the {@link SchemaFactory} will abort the parsing and597* the caller of the <code>newSchema</code> method will receive598* the same {@link RuntimeException}.599*600* <p>601* When a new {@link SchemaFactory} object is created, initially602* this field is set to null. This field will <em>NOT</em> be603* inherited to {@link Schema}s, {@link Validator}s, or604* {@link ValidatorHandler}s that are created from this {@link SchemaFactory}.605*606* @param resourceResolver607* A new resource resolver to be set. This parameter can be null.608*/609public abstract void setResourceResolver(LSResourceResolver resourceResolver);610611/**612* Gets the current {@link LSResourceResolver} set to this {@link SchemaFactory}.613*614* @return615* This method returns the object that was last set through616* the {@link #setResourceResolver(LSResourceResolver)} method, or null617* if that method has never been called since this {@link SchemaFactory}618* has created.619*620* @see #setErrorHandler(ErrorHandler)621*/622public abstract LSResourceResolver getResourceResolver();623624/**625* <p>Parses the specified source as a schema and returns it as a schema.</p>626*627* <p>This is a convenience method for {@link #newSchema(Source[] schemas)}.</p>628*629* @param schema Source that represents a schema.630*631* @return New <code>Schema</code> from parsing <code>schema</code>.632*633* @throws SAXException If a SAX error occurs during parsing.634* @throws NullPointerException if <code>schema</code> is null.635*/636public Schema newSchema(Source schema) throws SAXException {637return newSchema(new Source[]{schema});638}639640/**641* <p>Parses the specified <code>File</code> as a schema and returns it as a <code>Schema</code>.</p>642*643* <p>This is a convenience method for {@link #newSchema(Source schema)}.</p>644*645* @param schema File that represents a schema.646*647* @return New <code>Schema</code> from parsing <code>schema</code>.648*649* @throws SAXException If a SAX error occurs during parsing.650* @throws NullPointerException if <code>schema</code> is null.651*/652public Schema newSchema(File schema) throws SAXException {653return newSchema(new StreamSource(schema));654}655656/**657* <p>Parses the specified <code>URL</code> as a schema and returns it as a <code>Schema</code>.</p>658*659* <p>This is a convenience method for {@link #newSchema(Source schema)}.</p>660*661* @param schema <code>URL</code> that represents a schema.662*663* @return New <code>Schema</code> from parsing <code>schema</code>.664*665* @throws SAXException If a SAX error occurs during parsing.666* @throws NullPointerException if <code>schema</code> is null.667*/668public Schema newSchema(URL schema) throws SAXException {669return newSchema(new StreamSource(schema.toExternalForm()));670}671672/**673* Parses the specified source(s) as a schema and returns it as a schema.674*675* <p>676* The callee will read all the {@link Source}s and combine them into a677* single schema. The exact semantics of the combination depends on the schema678* language that this {@link SchemaFactory} object is created for.679*680* <p>681* When an {@link ErrorHandler} is set, the callee will report all the errors682* found in sources to the handler. If the handler throws an exception, it will683* abort the schema compilation and the same exception will be thrown from684* this method. Also, after an error is reported to a handler, the callee is allowed685* to abort the further processing by throwing it. If an error handler is not set,686* the callee will throw the first error it finds in the sources.687*688* <h2>W3C XML Schema 1.0</h2>689* <p>690* The resulting schema contains components from the specified sources.691* The same result would be achieved if all these sources were692* imported, using appropriate values for schemaLocation and namespace,693* into a single schema document with a different targetNamespace694* and no components of its own, if the import elements were given695* in the same order as the sources. Section 4.2.3 of the XML Schema696* recommendation describes the options processors have in this697* regard. While a processor should be consistent in its treatment of698* JAXP schema sources and XML Schema imports, the behaviour between699* JAXP-compliant parsers may vary; in particular, parsers may choose700* to ignore all but the first <import> for a given namespace,701* regardless of information provided in schemaLocation.702*703* <p>704* If the parsed set of schemas includes error(s) as705* specified in the section 5.1 of the XML Schema spec, then706* the error must be reported to the {@link ErrorHandler}.707*708* <h2>RELAX NG</h2>709*710* <p>For RELAX NG, this method must throw {@link UnsupportedOperationException}711* if <code>schemas.length!=1</code>.712*713*714* @param schemas715* inputs to be parsed. {@link SchemaFactory} is required716* to recognize {@link javax.xml.transform.sax.SAXSource},717* {@link StreamSource},718* {@link javax.xml.transform.stax.StAXSource},719* and {@link javax.xml.transform.dom.DOMSource}.720* Input schemas must be XML documents or721* XML elements and must not be null. For backwards compatibility,722* the results of passing anything other than723* a document or element are implementation-dependent.724* Implementations must either recognize and process the input725* or thrown an IllegalArgumentException.726*727* @return728* Always return a non-null valid {@link Schema} object.729* Note that when an error has been reported, there is no730* guarantee that the returned {@link Schema} object is731* meaningful.732*733* @throws SAXException734* If an error is found during processing the specified inputs.735* When an {@link ErrorHandler} is set, errors are reported to736* there first. See {@link #setErrorHandler(ErrorHandler)}.737* @throws NullPointerException738* If the <code>schemas</code> parameter itself is null or739* any item in the array is null.740* @throws IllegalArgumentException741* If any item in the array is not recognized by this method.742* @throws UnsupportedOperationException743* If the schema language doesn't support this operation.744*/745public abstract Schema newSchema(Source[] schemas) throws SAXException;746747/**748* Creates a special {@link Schema} object.749*750* <p>The exact semantics of the returned {@link Schema} object751* depend on the schema language for which this {@link SchemaFactory}752* is created.753*754* <p>Also, implementations are allowed to use implementation-specific755* property/feature to alter the semantics of this method.</p>756*757* <p>Implementors and developers should pay particular attention758* to how the features set on this {@link SchemaFactory} are759* processed by this special {@link Schema}.760* In some cases, for example, when the761* {@link SchemaFactory} and the class actually loading the762* schema come from different implementations, it may not be possible763* for {@link SchemaFactory} features to be inherited automatically.764* Developers should765* make sure that features, such as secure processing, are explicitly766* set in both places.</p>767*768* <h2>W3C XML Schema 1.0</h2>769* <p>770* For XML Schema, this method creates a {@link Schema} object that771* performs validation by using location hints specified in documents.772*773* <p>774* The returned {@link Schema} object assumes that if documents775* refer to the same URL in the schema location hints,776* they will always resolve to the same schema document. This777* asusmption allows implementations to reuse parsed results of778* schema documents so that multiple validations against the same779* schema will run faster.780*781* <p>782* Note that the use of schema location hints introduces a783* vulnerability to denial-of-service attacks.784*785*786* <h2>RELAX NG</h2>787* <p>788* RELAX NG does not support this operation.789*790* @return791* Always return non-null valid {@link Schema} object.792*793* @throws UnsupportedOperationException794* If this operation is not supported by the callee.795* @throws SAXException796* If this operation is supported but failed for some reason.797*/798public abstract Schema newSchema() throws SAXException;799}800801802