Methods Summary |
---|
public abstract org.xml.sax.ErrorHandler | getErrorHandler()Gets the current {@link ErrorHandler} set to this {@link SchemaFactory}.
|
public boolean | getFeature(java.lang.String name)Look up the value of a feature flag.
The feature name is any fully-qualified URI. It is
possible for a {@link 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.
if (name == null) {
throw new NullPointerException("the name parameter is null");
}
throw new SAXNotRecognizedException(name);
|
public java.lang.Object | getProperty(java.lang.String name)Look up the value of a property.
The property name is any fully-qualified URI. It is
possible for a {@link SchemaFactory} to recognize a property name but
temporarily be unable to return its value.
{@link 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.
if (name == null) {
throw new NullPointerException("the name parameter is null");
}
throw new SAXNotRecognizedException(name);
|
public abstract org.w3c.dom.ls.LSResourceResolver | getResourceResolver()Gets the current {@link LSResourceResolver} set to this {@link SchemaFactory}.
|
public abstract boolean | isSchemaLanguageSupported(java.lang.String schemaLanguage)Is specified schema supported by this SchemaFactory ?
|
public static final javax.xml.validation.SchemaFactory | newInstance(java.lang.String schemaLanguage)Lookup an implementation of the SchemaFactory that supports the specified
schema language and return it.
To find a SchemaFactory object for a given schema language,
this method looks the following places in the following order
where "the class loader" refers to the context class loader:
-
If the system property
"javax.xml.validation.SchemaFactory:schemaLanguage"
is present (where schemaLanguage is the parameter
to this method), then its value is read
as a class name. The method will try to
create a new instance of this class by using the class loader,
and returns it if it is successfully created.
-
$java.home/lib/jaxp.properties is read and
the value associated with the key being the system property above
is looked for. If present, the value is processed just like above.
-
The class loader is asked for service provider provider-configuration files matching
javax.xml.validation.SchemaFactory in the resource directory META-INF/services.
See the JAR File Specification for file format and parsing rules.
Each potential service provider is required to implement the method:
{@link #isSchemaLanguageSupported(String schemaLanguage)}
The first service provider found in class loader order that supports the specified schema language is returned.
-
Platform default
SchemaFactory is located
in a implementation specific way. There must be a platform default
SchemaFactory for W3C XML Schema.
If everything fails, {@link IllegalArgumentException} will be thrown.
Tip for Trouble-shooting:
See {@link 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
ClassLoader cl;
cl = ss.getContextClassLoader();
if (cl == null) {
//cl = ClassLoader.getSystemClassLoader();
//use the current class loader
cl = SchemaFactory.class.getClassLoader();
}
SchemaFactory f = new SchemaFactoryFinder(cl).newFactory(schemaLanguage);
if (f == null) {
throw new IllegalArgumentException(schemaLanguage);
}
return f;
|
public javax.xml.validation.Schema | newSchema(javax.xml.transform.Source schema)Parses the specified source as a schema and returns it as a schema.
This is a convenience method for {@link #newSchema(Source[] schemas)}.
return newSchema(new Source[]{schema});
|
public javax.xml.validation.Schema | newSchema(java.io.File schema)Parses the specified File as a schema and returns it as a Schema .
This is a convenience method for {@link #newSchema(Source schema)}.
return newSchema(new StreamSource(schema));
|
public javax.xml.validation.Schema | newSchema(java.net.URL schema)Parses the specified URL as a schema and returns it as a Schema .
This is a convenience method for {@link #newSchema(Source schema)}.
return newSchema(new StreamSource(schema.toExternalForm()));
|
public abstract javax.xml.validation.Schema | newSchema(javax.xml.transform.Source[] schemas)Parses the specified source(s) as a schema and returns it as a schema.
The callee will read all the {@link Source}s and combine them into a
single schema. The exact semantics of the combination depends on the schema
language that this {@link SchemaFactory} object is created for.
When an {@link 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.0
The 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 {@link ErrorHandler}.
RELAX NG
For RELAX NG, this method must throw {@link UnsupportedOperationException}
if schemas.length!=1.
|
public abstract javax.xml.validation.Schema | newSchema()Creates a special {@link Schema} object.
The exact semantics of the returned {@link Schema} object depends
on the schema language that this {@link 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.0
For XML Schema, this method creates a {@link Schema} object that
performs validation by using location hints specified in documents.
The returned {@link 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
asusmption 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 NG
RELAX NG does not support this operation.
|
public abstract void | setErrorHandler(org.xml.sax.ErrorHandler errorHandler)Sets the {@link ErrorHandler} to receive errors encountered
during the newSchema method invocation.
Error handler can be used to customize the error handling process
during schema parsing. When an {@link ErrorHandler} is set,
errors found during the parsing of schemas will be first sent
to the {@link ErrorHandler}.
The error handler can abort the parsing of a schema immediately
by throwing {@link 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 {@link ErrorHandler}
If any {@link Throwable} (or instances of its derived classes)
is thrown from an {@link ErrorHandler},
the caller of the newSchema method will be thrown
the same {@link Throwable} object.
{@link SchemaFactory} is not allowed to
throw {@link SAXException} without first reporting it to
{@link ErrorHandler}.
Applications can call this method even during a {@link Schema}
is being parsed.
When the {@link ErrorHandler} is null, the implementation will
behave as if the following {@link ErrorHandler} is set:
class DraconianErrorHandler implements {@link ErrorHandler} {
public void fatalError( {@link org.xml.sax.SAXParseException} e ) throws {@link SAXException} {
throw e;
}
public void error( {@link org.xml.sax.SAXParseException} e ) throws {@link SAXException} {
throw e;
}
public void warning( {@link org.xml.sax.SAXParseException} e ) throws {@link SAXException} {
// noop
}
}
When a new {@link SchemaFactory} object is created, initially
this field is set to null. This field will NOT be
inherited to {@link Schema}s, {@link Validator}s, or
{@link ValidatorHandler}s that are created from this {@link SchemaFactory}.
|
public void | setFeature(java.lang.String name, boolean value)Set the value of a feature flag.
Feature can be used to control the way a {@link SchemaFactory}
parses schemas, although {@link SchemaFactory}s are not required
to recognize any specific feature names.
The feature name is any fully-qualified URI. It is
possible for a {@link SchemaFactory} to expose a feature value but
to be unable to change the current value.
All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature.
When the feature is:
-
true : the implementation will limit XML processing to conform to implementation limits.
Examples include enity expansion limits and XML Schema constructs that would consume large amounts of resources.
If XML processing is limited for security reasons, it will be reported via a call to the registered
{@link ErrorHandler#fatalError(SAXParseException exception)}.
See {@link #setErrorHandler(ErrorHandler errorHandler)}.
-
false : the implementation will processing XML according to the XML specifications without
regard to possible implementation limits.
if (name == null) {
throw new NullPointerException("the name parameter is null");
}
throw new SAXNotRecognizedException(name);
|
public void | setProperty(java.lang.String name, java.lang.Object object)Set the value of a property.
The property name is any fully-qualified URI. It is
possible for a {@link SchemaFactory} to recognize a property name but
to be unable to change the current value.
{@link SchemaFactory}s are not required to recognize setting
any specific property names.
if (name == null) {
throw new NullPointerException("the name parameter is null");
}
throw new SAXNotRecognizedException(name);
|
public abstract void | setResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolver)Sets the {@link LSResourceResolver} to customize
resource resolution when parsing schemas.
{@link SchemaFactory} uses a {@link 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 {@link Schema}
is being parsed.
When the {@link LSResourceResolver} is null, the implementation will
behave as if the following {@link LSResourceResolver} is set:
class DumbDOMResourceResolver implements {@link LSResourceResolver} {
public {@link org.w3c.dom.ls.LSInput} resolveResource(
String publicId, String systemId, String baseURI) {
return null; // always return null
}
}
If a {@link LSResourceResolver} throws a {@link RuntimeException}
(or instances of its derived classes),
then the {@link SchemaFactory} will abort the parsing and
the caller of the newSchema method will receive
the same {@link RuntimeException}.
When a new {@link SchemaFactory} object is created, initially
this field is set to null. This field will NOT be
inherited to {@link Schema}s, {@link Validator}s, or
{@link ValidatorHandler}s that are created from this {@link SchemaFactory}.
|