@NotThreadSafe
public class SchemaBuilder
extends java.lang.Object
Schema from a set of inputs, allowing for
manipulation of the underlying factory.| Modifier and Type | Class and Description |
|---|---|
static class |
SchemaBuilder.SchemaLanguage
Language of the schema files.
|
| Modifier and Type | Field and Description |
|---|---|
private boolean |
alreadyBuilt
One time-init flag.
|
private org.xml.sax.ErrorHandler |
errorHandler
Custom error handler.
|
private java.util.Map<java.lang.String,java.lang.Boolean> |
features
Features to set on factory.
|
private org.slf4j.Logger |
log
Class logger.
|
private java.util.Map<java.lang.String,java.lang.Object> |
properties
Properties to set on factory.
|
private org.w3c.dom.ls.LSResourceResolver |
resourceResolver
Mechanism for resolving nested resources like included/imported schemas.
|
private SchemaBuilder.SchemaLanguage |
schemaLang
Language of schemas.
|
private java.util.List<javax.xml.transform.Source> |
sources
Sources of schema material compatible with JAXP.
|
| Constructor and Description |
|---|
SchemaBuilder()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
SchemaBuilder |
addSchema(java.io.InputStream schemaSource)
Add schemas from the given schema input streams.
|
SchemaBuilder |
addSchema(Resource resource)
Add schemas from the given schema resource.
|
SchemaBuilder |
addSchema(javax.xml.transform.Source schemaSource)
Add schemas from the given schema sources.
|
javax.xml.validation.Schema |
buildSchema()
Build a schema from the given schema sources.
|
SchemaBuilder |
resetSchemas()
Clear the schemas to be included.
|
SchemaBuilder |
setErrorHandler(org.xml.sax.ErrorHandler handler)
Set a custom error handler to use.
|
void |
setFeature(java.lang.String name,
boolean value)
Set a feature for the
SchemaFactory to be built. |
void |
setProperty(java.lang.String name,
java.lang.Object object)
Set the value of a property for the
SchemaFactory to be built. |
SchemaBuilder |
setResourceResolver(org.w3c.dom.ls.LSResourceResolver resolver)
Set the resource resolver to use for included/imported schemas.
|
SchemaBuilder |
setSchemaLanguage(SchemaBuilder.SchemaLanguage lang)
Set the schema language.
|
void |
setSchemaResources(java.util.Collection<Resource> schemaResources)
Set the schemas to load from the given schema resources (replaces any previously added).
|
void |
setSchemas(java.util.Collection<javax.xml.transform.Source> schemaSources)
Set the schemas to load from the given schema sources (replaces any previously added).
|
@Nonnull private final org.slf4j.Logger log
@Nonnull private SchemaBuilder.SchemaLanguage schemaLang
@Nonnull @NonnullElements private java.util.List<javax.xml.transform.Source> sources
@Nullable private org.w3c.dom.ls.LSResourceResolver resourceResolver
@Nullable private org.xml.sax.ErrorHandler errorHandler
@Nonnull private java.util.Map<java.lang.String,java.lang.Boolean> features
@Nonnull private java.util.Map<java.lang.String,java.lang.Object> properties
private boolean alreadyBuilt
@Nonnull public SchemaBuilder setSchemaLanguage(@Nonnull SchemaBuilder.SchemaLanguage lang)
lang - the schema language@Nonnull public SchemaBuilder setResourceResolver(@Nullable org.w3c.dom.ls.LSResourceResolver resolver)
If not set, the default resolver will prevent lookup of any schemas not explicitly added.
resolver - resource resolver@Nonnull public SchemaBuilder setErrorHandler(@Nullable org.xml.sax.ErrorHandler handler)
If not set, a default handler will be used that logs errors before throwing exceptions.
handler - error handlerpublic void setFeature(@Nonnull @NotEmpty java.lang.String name, boolean value)
SchemaFactory to be built.name - The feature name, which is a non-null fully-qualified URI.value - The requested value of the feature (true or false).SchemaFactory.setFeature(String, boolean)public void setProperty(@Nonnull @NotEmpty java.lang.String name, @Nullable java.lang.Object object)
SchemaFactory to be built.name - The property name, which is a non-null fully-qualified URI.object - The requested value for the property.SchemaFactory.setProperty(String, Object)@Nonnull public SchemaBuilder resetSchemas()
@Nonnull public void setSchemas(@Nonnull @NullableElements java.util.Collection<javax.xml.transform.Source> schemaSources)
If the caller wishes to ensure the schemas are loaded in a particular order,
the Collection implementation provided must be one that preserves order.
The method will add the sources in the order returned by the collection.
schemaSources - schema sources@Nonnull public void setSchemaResources(@Nonnull @NullableElements java.util.Collection<Resource> schemaResources)
If the caller wishes to ensure the schemas are loaded in a particular order,
the Collection implementation provided must be one that preserves order.
The method will add the sources in the order returned by the collection.
schemaResources - schema resources@Nonnull public SchemaBuilder addSchema(@Nonnull java.io.InputStream schemaSource)
schemaSource - schema input stream@Nonnull public SchemaBuilder addSchema(@Nonnull javax.xml.transform.Source schemaSource)
schemaSource - schema source@Nonnull public SchemaBuilder addSchema(@Nonnull Resource resource)
resource - schema input resource@Nonnull
public javax.xml.validation.Schema buildSchema()
throws org.xml.sax.SAXException
This method is thread-safe, although the various mutating methods to establish the state of the object are not.
org.xml.sax.SAXException - thrown if there is a problem converting the schema sources into a schema