java.lang.ObjectFactory that creates Schema objects. Entry-point to the validation API.javax.xml.validation.SchemaFactory
SchemaFactory is a schema compiler. It reads external representations of schemas and prepares them for validation.
The SchemaFactory class is not thread-safe. In other words, it is the application's responsibility to ensure that at most one thread is using a SchemaFactory object at any given moment. Implementations are encouraged to mark methods as synchronized to protect themselves from broken clients.
SchemaFactory is not re-entrant. While one of the
newSchema
methods is being invoked, applications
may not attempt to recursively invoke the newSchema
method,
even from the same thread.
This spec uses a namespace URI to designate a schema language. The following table shows the values defined by this specification.
To be compliant with the spec, the implementation is only required to support W3C XML Schema 1.0. However, if it chooses to support other schema languages listed here, it must conform to the relevant behaviors described in this spec.
Schema languages not listed here are expected to introduce their own URIs to represent themselves. The SchemaFactory class is capable of locating other implementations for other schema languages at run-time.
Note that because the XML DTD is strongly tied to the parsing process and has a significant effect on the parsing process, it is impossible to define the DTD validation as a process independent from parsing. For this reason, this specification does not define the semantics for the XML DTD. This doesn't prohibit implementors from implementing it in a way they see fit, but users are warned that any DTD validation implemented on this interface necessarily deviate from the XML DTD semantics as defined in the XML 1.0.
value | language |
---|---|
javax.xml.XMLConstants#W3C_XML_SCHEMA_NS_URI ("http://www.w3.org/2001/XMLSchema ") |
W3C XML Schema 1.0 |
javax.xml.XMLConstants#RELAXNG_NS_URI ("http://relaxng.org/ns/structure/1.0 ") |
RELAX NG 1.0 |
- href="mailto:Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi
$
- Revision: 884952 $, $Date: 2009-11-27 13:55:08 -0500 (Fri, 27 Nov 2009) $1.5
- Constructor: |
---|
Constructor for derived classes. The constructor does nothing. Derived classes must create SchemaFactory objects that have
|
Method from javax.xml.validation.SchemaFactory Summary: |
---|
getErrorHandler, getFeature, getProperty, getResourceResolver, isSchemaLanguageSupported, newInstance, newInstance, newSchema, newSchema, newSchema, newSchema, newSchema, setErrorHandler, setFeature, setProperty, setResourceResolver |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from javax.xml.validation.SchemaFactory Detail: |
---|
|
The feature name is any fully-qualified URI. It is possible for a SchemaFactory to recognize a feature name but temporarily be unable to return its value. Implementors are free (and encouraged) to invent their own features, using names built on their own URIs. |
The property name is any fully-qualified URI. It is possible for a SchemaFactory to recognize a property name but temporarily be unable to return its value. SchemaFactory s are not required to recognize any specific property names. Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs. |
|
Is specified schema supported by this |
Lookup an implementation of the To find a If everything fails, IllegalArgumentException will be thrown. Tip for Trouble-shooting: See java.util.Properties#load(java.io.InputStream) for exactly how a property file is parsed. In particular, colons ':' need to be escaped in a property file, so make sure schema language URIs are properly escaped in it. For example: http\://www.w3.org/2001/XMLSchema=org.acme.foo.XSSchemaFactory |
|
The exact semantics of the returned Schema object depends on the schema language that this SchemaFactory is created for. Also, implementations are allowed to use implementation-specific property/feature to alter the semantics of this method. W3C XML Schema 1.0For XML Schema, this method creates a Schema object that performs validation by using location hints specified in documents. The returned Schema object assumes that if documents refer to the same URL in the schema location hints, they will always resolve to the same schema document. This assumption allows implementations to reuse parsed results of schema documents so that multiple validations against the same schema will run faster. Note that the use of schema location hints introduces a vulnerability to denial-of-service attacks. RELAX NGRELAX NG does not support this operation. |
Parses the specified source as a schema and returns it as a schema. This is a convenience method for #newSchema(Source[] schemas) . |
Parses the specified This is a convenience method for #newSchema(Source schema) . |
Parses the specified This is a convenience method for #newSchema(Source schema) . |
The callee will read all the Source s and combine them into a single schema. The exact semantics of the combination depends on the schema language that this SchemaFactory object is created for. When an ErrorHandler is set, the callee will report all the errors found in sources to the handler. If the handler throws an exception, it will abort the schema compilation and the same exception will be thrown from this method. Also, after an error is reported to a handler, the callee is allowed to abort the further processing by throwing it. If an error handler is not set, the callee will throw the first error it finds in the sources. W3C XML Schema 1.0The resulting schema contains components from the specified sources. The same result would be achieved if all these sources were imported, using appropriate values for schemaLocation and namespace, into a single schema document with a different targetNamespace and no components of its own, if the import elements were given in the same order as the sources. Section 4.2.3 of the XML Schema recommendation describes the options processors have in this regard. While a processor should be consistent in its treatment of JAXP schema sources and XML Schema imports, the behaviour between JAXP-compliant parsers may vary; in particular, parsers may choose to ignore all but the first <import> for a given namespace, regardless of information provided in schemaLocation. If the parsed set of schemas includes error(s) as specified in the section 5.1 of the XML Schema spec, then the error must be reported to the ErrorHandler . RELAX NGFor RELAX NG, this method must throw UnsupportedOperationException if schemas.length!=1. |
newSchema method invocation.
Error handler can be used to customize the error handling process during schema parsing. When an ErrorHandler is set, errors found during the parsing of schemas will be first sent to the ErrorHandler . The error handler can abort the parsing of a schema immediately by throwing SAXException from the handler. Or for example it can print an error to the screen and try to continue the processing by returning normally from the ErrorHandler
If any Throwable (or instances of its derived classes)
is thrown from an ErrorHandler ,
the caller of the SchemaFactory is not allowed to throw SAXException without first reporting it to ErrorHandler . Applications can call this method even during a Schema is being parsed. When the ErrorHandler is null, the implementation will behave as if the following ErrorHandler is set: class DraconianErrorHandler implements ErrorHandler { public void fatalError( org.xml.sax.SAXParseException e ) throws SAXException { throw e; } public void error( org.xml.sax.SAXParseException e ) throws SAXException { throw e; } public void warning( org.xml.sax.SAXParseException e ) throws SAXException { // noop } } When a new SchemaFactory object is created, initially this field is set to null. This field will NOT be inherited to Schema s, Validator s, or ValidatorHandler s that are created from this SchemaFactory . |
Feature can be used to control the way a SchemaFactory parses schemas, although SchemaFactory s are not required to recognize any specific feature names. The feature name is any fully-qualified URI. It is possible for a SchemaFactory to expose a feature value but to be unable to change the current value. All implementations are required to support the javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING feature. When the feature is: |
The property name is any fully-qualified URI. It is possible for a SchemaFactory to recognize a property name but to be unable to change the current value. SchemaFactory s are not required to recognize setting any specific property names. |
SchemaFactory uses a LSResourceResolver when it needs to locate external resources while parsing schemas, although exactly what constitutes "locating external resources" is up to each schema language. For example, for W3C XML Schema, this includes files <include>d or <import>ed, and DTD referenced from schema files, etc. Applications can call this method even during a Schema is being parsed. When the LSResourceResolver is null, the implementation will behave as if the following LSResourceResolver is set: class DumbDOMResourceResolver implements LSResourceResolver { public org.w3c.dom.ls.LSInput resolveResource( String publicId, String systemId, String baseURI) { return null; // always return null } }
If a LSResourceResolver throws a RuntimeException
(or instances of its derived classes),
then the SchemaFactory will abort the parsing and
the caller of the When a new SchemaFactory object is created, initially this field is set to null. This field will NOT be inherited to Schema s, Validator s, or ValidatorHandler s that are created from this SchemaFactory . |