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 | XMLGRAMMAR_POOLProperty identifier: grammar pool. | private static final String | SECURITY_MANAGERProperty identifier: SecurityManager. | private final XMLSchemaLoader | fXMLSchemaLoaderThe XMLSchemaLoader | private ErrorHandler | fErrorHandlerUser-specified ErrorHandler; can be null. | private LSResourceResolver | fLSResourceResolverThe LSResrouceResolver | private final DOMEntityResolverWrapper | fDOMEntityResolverWrapperThe DOMEntityResolverWrapper | private ErrorHandlerWrapper | fErrorHandlerWrapperThe ErrorHandlerWrapper | private SecurityManager | fSecurityManagerThe SecurityManager. | private XMLGrammarPoolWrapper | fXMLGrammarPoolWrapperThe container for the real 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);
// Enable secure processing feature by default
fSecurityManager = new SecurityManager();
fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
|
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);
}
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);
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();
if (grammarCount > 1) {
return new XMLSchema(new ReadOnlyGrammarPool(pool));
}
else if (grammarCount == 1) {
Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
return new SimpleXMLSchema(grammars[0]);
}
else {
return EmptyXMLSchema.getInstance();
}
| public javax.xml.validation.Schema | newSchema()
// Use a Schema that uses the system id as the equality source.
return new WeakReferenceXMLSchema();
| 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;
}
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);
|
|