@NotThreadSafe public class SchemaBuilder extends 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 ErrorHandler |
errorHandler
Custom error handler.
|
private Map<String,Boolean> |
features
Features to set on factory.
|
private org.slf4j.Logger |
log
Class logger.
|
private Map<String,Object> |
properties
Properties to set on factory.
|
private LSResourceResolver |
resourceResolver
Mechanism for resolving nested resources like included/imported schemas.
|
private SchemaBuilder.SchemaLanguage |
schemaLang
Language of schemas.
|
private List<Source> |
sources
Sources of schema material compatible with JAXP.
|
Constructor and Description |
---|
SchemaBuilder()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
SchemaBuilder |
addSchema(InputStream schemaSource)
Add schemas from the given schema input streams.
|
SchemaBuilder |
addSchema(Resource resource)
Add schemas from the given schema resource.
|
SchemaBuilder |
addSchema(Source schemaSource)
Add schemas from the given schema sources.
|
Schema |
buildSchema()
Build a schema from the given schema sources.
|
SchemaBuilder |
resetSchemas()
Clear the schemas to be included.
|
SchemaBuilder |
setErrorHandler(ErrorHandler handler)
Set a custom error handler to use.
|
void |
setFeature(String name,
boolean value)
Set a feature for the
SchemaFactory to be built. |
void |
setProperty(String name,
Object object)
Set the value of a property for the
SchemaFactory to be built. |
SchemaBuilder |
setResourceResolver(LSResourceResolver resolver)
Set the resource resolver to use for included/imported schemas.
|
SchemaBuilder |
setSchemaLanguage(SchemaBuilder.SchemaLanguage lang)
Set the schema language.
|
void |
setSchemaResources(Collection<Resource> schemaResources)
Set the schemas to load from the given schema resources (replaces any previously added).
|
void |
setSchemas(Collection<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 List<Source> sources
@Nullable private LSResourceResolver resourceResolver
@Nullable private ErrorHandler errorHandler
private boolean alreadyBuilt
@Nonnull public SchemaBuilder setSchemaLanguage(@Nonnull SchemaBuilder.SchemaLanguage lang)
lang
- the schema language@Nonnull public SchemaBuilder setResourceResolver(@Nullable 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 ErrorHandler handler)
If not set, a default handler will be used that logs errors before throwing exceptions.
handler
- error handlerpublic void setFeature(@Nonnull @NotEmpty 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 String name, @Nullable 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 Collection<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 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 InputStream schemaSource)
schemaSource
- schema input stream@Nonnull public SchemaBuilder addSchema(@Nonnull Source schemaSource)
schemaSource
- schema source@Nonnull public SchemaBuilder addSchema(@Nonnull Resource resource)
resource
- schema input resource@Nonnull public Schema buildSchema() throws SAXException
This method is thread-safe, although the various mutating methods to establish the state of the object are not.
SAXException
- thrown if there is a problem converting the schema sources into a schemaCopyright © 1999–2019. All rights reserved.