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