XMLSchemaFactorypublic final class XMLSchemaFactory extends SchemaFactory {@link SchemaFactory} for XML Schema. |
Fields Summary |
---|
private static final String | SCHEMA_FULL_CHECKINGFeature identifier: schema full checking. | private static final String | USE_GRAMMAR_POOL_ONLYFeature identifier: use grammar pool only. | private static final String | XMLGRAMMAR_POOLProperty identifier: grammar pool. | private static final String | SECURITY_MANAGERProperty identifier: SecurityManager. | private final org.apache.xerces.impl.xs.XMLSchemaLoader | fXMLSchemaLoaderThe XMLSchemaLoader | private ErrorHandler | fErrorHandlerUser-specified ErrorHandler; can be null. | private LSResourceResolver | fLSResourceResolverThe LSResrouceResolver | private final org.apache.xerces.util.DOMEntityResolverWrapper | fDOMEntityResolverWrapperThe DOMEntityResolverWrapper | private final org.apache.xerces.util.ErrorHandlerWrapper | fErrorHandlerWrapperThe ErrorHandlerWrapper | private org.apache.xerces.util.SecurityManager | fSecurityManagerThe SecurityManager. | private final XMLGrammarPoolWrapper | fXMLGrammarPoolWrapperThe container for the real grammar pool. | private boolean | fUseGrammarPoolOnlyWhether or not to allow new schemas to be added to the grammar pool |
Constructors Summary |
---|
public XMLSchemaFactory()
fErrorHandlerWrapper = new ErrorHandlerWrapper(DraconianErrorHandler.getInstance());
fDOMEntityResolverWrapper = new DOMEntityResolverWrapper();
fXMLGrammarPoolWrapper = new XMLGrammarPoolWrapper();
fXMLSchemaLoader.setFeature(SCHEMA_FULL_CHECKING, true);
fXMLSchemaLoader.setProperty(XMLGRAMMAR_POOL, fXMLGrammarPoolWrapper);
fXMLSchemaLoader.setEntityResolver(fDOMEntityResolverWrapper);
fXMLSchemaLoader.setErrorHandler(fErrorHandlerWrapper);
fUseGrammarPoolOnly = true;
|
Methods Summary |
---|
public org.xml.sax.ErrorHandler | getErrorHandler()
return fErrorHandler;
| public boolean | getFeature(java.lang.String name)
if (name == null) {
throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"FeatureNameNull", null));
}
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
return (fSecurityManager != null);
}
else if (name.equals(USE_GRAMMAR_POOL_ONLY)) {
return fUseGrammarPoolOnly;
}
try {
return fXMLSchemaLoader.getFeature(name);
}
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"feature-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"feature-not-supported", new Object [] {identifier}));
}
}
| public java.lang.Object | getProperty(java.lang.String name)
if (name == null) {
throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"ProperyNameNull", null));
}
if (name.equals(SECURITY_MANAGER)) {
return fSecurityManager;
}
else if (name.equals(XMLGRAMMAR_POOL)) {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"property-not-supported", new Object [] {name}));
}
try {
return fXMLSchemaLoader.getProperty(name);
}
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"property-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"property-not-supported", new Object [] {identifier}));
}
}
| public org.w3c.dom.ls.LSResourceResolver | getResourceResolver()
return fLSResourceResolver;
| public boolean | isSchemaLanguageSupported(java.lang.String schemaLanguage)Is specified schema supported by this SchemaFactory ?
if (schemaLanguage == null) {
throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"SchemaLanguageNull", null));
}
if (schemaLanguage.length() == 0) {
throw new IllegalArgumentException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"SchemaLanguageLengthZero", null));
}
// only W3C XML Schema 1.0 is supported
return schemaLanguage.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI);
| public javax.xml.validation.Schema | newSchema(javax.xml.transform.Source[] schemas)
// this will let the loader store parsed Grammars into the pool.
XMLGrammarPoolImplExtension pool = new XMLGrammarPoolImplExtension();
fXMLGrammarPoolWrapper.setGrammarPool(pool);
XMLInputSource[] xmlInputSources = new XMLInputSource[schemas.length];
InputStream inputStream;
Reader reader;
for( int i=0; i<schemas.length; i++ ) {
Source source = schemas[i];
if (source instanceof StreamSource) {
StreamSource streamSource = (StreamSource) source;
String publicId = streamSource.getPublicId();
String systemId = streamSource.getSystemId();
inputStream = streamSource.getInputStream();
reader = streamSource.getReader();
xmlInputSources[i] = new XMLInputSource(publicId, systemId, null);
xmlInputSources[i].setByteStream(inputStream);
xmlInputSources[i].setCharacterStream(reader);
}
else if (source instanceof SAXSource) {
SAXSource saxSource = (SAXSource) source;
InputSource inputSource = saxSource.getInputSource();
if (inputSource == null) {
throw new SAXException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"SAXSourceNullInputSource", null));
}
xmlInputSources[i] = new SAXInputSource(saxSource.getXMLReader(), inputSource);
}
else if (source instanceof DOMSource) {
DOMSource domSource = (DOMSource) source;
Node node = domSource.getNode();
String systemID = domSource.getSystemId();
xmlInputSources[i] = new DOMInputSource(node, systemID);
}
else if (source == null) {
throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"SchemaSourceArrayMemberNull", null));
}
else {
throw new IllegalArgumentException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"SchemaFactorySourceUnrecognized",
new Object [] {source.getClass().getName()}));
}
}
try {
fXMLSchemaLoader.loadGrammar(xmlInputSources);
}
catch (XNIException e) {
// this should have been reported to users already.
throw Util.toSAXException(e);
}
catch (IOException e) {
// this hasn't been reported, so do so now.
SAXParseException se = new SAXParseException(e.getMessage(),null,e);
if (fErrorHandler != null) {
fErrorHandler.error(se);
}
throw se; // and we must throw it.
}
// Clear reference to grammar pool.
fXMLGrammarPoolWrapper.setGrammarPool(null);
// Select Schema implementation based on grammar count.
final int grammarCount = pool.getGrammarCount();
AbstractXMLSchema schema = null;
if (fUseGrammarPoolOnly) {
if (grammarCount > 1) {
schema = new XMLSchema(new ReadOnlyGrammarPool(pool));
}
else if (grammarCount == 1) {
Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
schema = new SimpleXMLSchema(grammars[0]);
}
else {
schema = new EmptyXMLSchema();
}
}
else {
schema = new XMLSchema(new ReadOnlyGrammarPool(pool), false);
}
propagateFeatures(schema);
return schema;
| public javax.xml.validation.Schema | newSchema()
/*
* It would make sense to return an EmptyXMLSchema object here, if
* fUseGrammarPoolOnly is set to true. However, because the default
* value of this feature is true, doing so would change the default
* behaviour of this method. Thus, we return a WeakReferenceXMLSchema
* regardless of the value of fUseGrammarPoolOnly. -PM
*/
// Use a Schema that uses the system id as the equality source.
AbstractXMLSchema schema = new WeakReferenceXMLSchema();
propagateFeatures(schema);
return schema;
| private void | propagateFeatures(AbstractXMLSchema schema)
schema.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, fSecurityManager != null);
String[] features = fXMLSchemaLoader.getRecognizedFeatures();
for (int i = 0; i < features.length; ++i) {
boolean state = fXMLSchemaLoader.getFeature(features[i]);
schema.setFeature(features[i], state);
}
| public void | setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
fErrorHandler = errorHandler;
fErrorHandlerWrapper.setErrorHandler(errorHandler != null ? errorHandler : DraconianErrorHandler.getInstance());
fXMLSchemaLoader.setErrorHandler(fErrorHandlerWrapper);
| public void | setFeature(java.lang.String name, boolean value)
if (name == null) {
throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"FeatureNameNull", null));
}
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
fSecurityManager = value ? new SecurityManager() : null;
fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
return;
}
else if (name.equals(USE_GRAMMAR_POOL_ONLY)) {
fUseGrammarPoolOnly = value;
return;
}
try {
fXMLSchemaLoader.setFeature(name, value);
}
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"feature-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"feature-not-supported", new Object [] {identifier}));
}
}
| public void | setProperty(java.lang.String name, java.lang.Object object)
if (name == null) {
throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"ProperyNameNull", null));
}
if (name.equals(SECURITY_MANAGER)) {
fSecurityManager = (SecurityManager) object;
fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
return;
}
else if (name.equals(XMLGRAMMAR_POOL)) {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"property-not-supported", new Object [] {name}));
}
try {
fXMLSchemaLoader.setProperty(name, object);
}
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"property-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"property-not-supported", new Object [] {identifier}));
}
}
| public void | setResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolver)
fLSResourceResolver = resourceResolver;
fDOMEntityResolverWrapper.setEntityResolver(resourceResolver);
fXMLSchemaLoader.setEntityResolver(fDOMEntityResolverWrapper);
|
|