1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
package net.sf.saxon.s9api;
import net.sf.saxon.Configuration;
import net.sf.saxon.event.Receiver;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.SchemaException;
import net.sf.saxon.type.SchemaURIResolver;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.Source;
/**
* The SchemaManager is used to load schema documents, and to set options for the way in which they are loaded.
* At present all the resulting schema components are held in a single pool owned by the Processor object.
*/
public class SchemaManager {
private Configuration config;
private ErrorListener errorListener;
protected SchemaManager(Configuration config) {
this.config = config;
this.errorListener = null;
}
/**
* Set the ErrorListener to be used while loading and validating schema documents
* @param listener The error listener to be used. This is notified of all errors detected during the
* compilation.
*/
public void setErrorListener(ErrorListener listener) {
this.errorListener = listener;
}
/**
* Get the ErrorListener being used while loading and validating schema documents
* @return listener The error listener in use. This is notified of all errors detected during the
* compilation. Returns null if no user-supplied ErrorListener has been set.
*/
public ErrorListener getErrorListener() {
return errorListener;
}
/**
* Set the SchemaURIResolver to be used during schema loading. This SchemaURIResolver, despite its name,
* is <b>not</b> used for resolving relative URIs against a base URI; it is used for dereferencing
* an absolute URI (after resolution) to return a {@link javax.xml.transform.Source} representing the
* location where a schema document can be found.
*
* <p>This SchemaURIResolver is used to dereference the URIs appearing in <code>xs:import</code>,
* <code>xs:include</code>, and <code>xs:redefine</code> declarations.
*
* @param resolver the SchemaURIResolver to be used during schema loading.
*/
public void setSchemaURIResolver(SchemaURIResolver resolver) {
config.setSchemaURIResolver(resolver);
}
/**
* Get the SchemaURIResolver to be used during schema loading.
*
* @return the URIResolver used during stylesheet compilation. Returns null if no user-supplied
* URIResolver has been set.
*/
public SchemaURIResolver getSchemaURIResolver() {
return config.getSchemaURIResolver();
}
/**
* Load a schema document from a given Source. The schema components derived from this schema
* document are added to the cache of schema components maintained by this SchemaManager
* @param source the document containing the schema. The getSystemId() method applied to this Source
* must return a base URI suitable for resolving <code>xs:include</code> and <code>xs:import</code>
* directives.
* @throws SaxonApiException if the schema document is not valid, or if its contents are inconsistent
* with the schema components already held by this SchemaManager.
*/
public void load(Source source) throws SaxonApiException {
try {
config.addSchemaSource(source, errorListener);
} catch (SchemaException e) {
throw new SaxonApiException(e);
}
}
/**
* Import a precompiled Schema Component Model from a given Source. The schema components derived from this schema
* document are added to the cache of schema components maintained by this SchemaManager
* @param source the XML file containing the schema component model, as generated by a previous call on
* {@link #exportComponents}
*/
public void importComponents(Source source) throws SaxonApiException {
throw new SaxonApiException("proprietary schema support disabled in this version");
}
/**
* Export a precompiled Schema Component Model containing all the components (except built-in components)
* that have been loaded into this Processor.
* @param destination the destination to recieve the precompiled Schema Component Model in the form of an
* XML document
*/
public void exportComponents(Destination destination) throws SaxonApiException {
throw new SaxonApiException("proprietary schema support disabled in this version");
}
/**
* Create a SchemaValidator which can be used to validate instance documents against the schema held by this
* SchemaManager
* @return a new SchemaValidator
*/
public SchemaValidator newSchemaValidator() {
return new SchemaValidator(config);
}
}
//
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
// you may not use this file except in compliance with the License. You may obtain a copy of the
// License at http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
// See the License for the specific language governing rights and limitations under the License.
//
// The Original Code is: all this file
//
// The Initial Developer of the Original Code is Michael H. Kay.
//
// Contributor(s):
//
|