Debian Codegraph @

mod/jaxp/src/main/com/thaiopensource/validation/SchemaFactory2.java

raw symbols SCIP
1 package com.thaiopensource.validation;
2
3 import org.xml.sax.SAXException;
4 import org.xml.sax.ErrorHandler;
5 import org.xml.sax.SAXNotRecognizedException;
6 import org.xml.sax.SAXNotSupportedException;
7 import org.xml.sax.InputSource;
8 import org.w3c.dom.ls.LSResourceResolver;
9
10 import javax.xml.transform.Source;
11 import javax.xml.transform.sax.SAXSource;
12 import javax.xml.transform.stream.StreamSource;
13 import javax.xml.validation.SchemaFactory;
14 import javax.xml.XMLConstants;
15 import java.io.File;
16 import java.net.URL;
17
18 /**
19 * Extends the SchemaFactory abstract class. All methods of SchemaFactory
20 * that return a Schema are overridden to return a Schema2. Default implementations
21 * of several methods are provided.
22 * @see SchemaFactory
23 */
24 public abstract class SchemaFactory2 extends SchemaFactory {
25 // Corresponds to XMLConstants.FEATURE_SECURE_PROCESSING.
26 private boolean secureProcessing = false;
27 private ErrorHandler errorHandler = null;
28 private LSResourceResolver resourceResolver = null;
29
30 /**
31 * Create a new Schema from a SAXSource. Subclasses must implement this.
32 * @see SchemaFactory#newSchema(Source)
33 */
34 public abstract Schema2 newSchema(SAXSource schema) throws SAXException;
35
36 public Schema2 newSchema(Source[] schemas) throws SAXException {
37 if (schemas.length != 1)
38 throw new UnsupportedOperationException();
39 return newSchema(schemas[0]);
40 }
41
42 /**
43 * This implementation of SchemaFactory#newSchema simply throws UnsupportedOperationException.
44 * @see SchemaFactory#newSchema
45 */
46 public Schema2 newSchema() throws SAXException {
47 throw new UnsupportedOperationException();
48 }
49
50 public Schema2 newSchema(Source source) throws SAXException {
51 if (source == null)
52 throw new NullPointerException();
53 if (source instanceof SAXSource)
54 return newSchema((SAXSource)source);
55 InputSource inputSource = SAXSource.sourceToInputSource(source);
56 // XXX support other types of Source for the schema
57 if (inputSource == null)
58 throw new IllegalArgumentException("unsupported type of Source for schema");
59 return newSchema(new SAXSource(inputSource));
60 }
61
62 public Schema2 newSchema(File schema) throws SAXException {
63 return newSchema(new StreamSource(schema));
64 }
65
66 public Schema2 newSchema(URL schema) throws SAXException {
67 return newSchema(new StreamSource(schema.toExternalForm()));
68 }
69
70 public void setErrorHandler(ErrorHandler errorHandler) {
71 this.errorHandler = errorHandler;
72 }
73
74 public ErrorHandler getErrorHandler() {
75 return errorHandler;
76 }
77
78 public void setResourceResolver(LSResourceResolver resourceResolver) {
79 this.resourceResolver = resourceResolver;
80 }
81
82 public LSResourceResolver getResourceResolver() {
83 return resourceResolver;
84 }
85
86 /**
87 * Extends SchemaFactory.setFeature by implementing the secure processing feature.
88 * The implementation simply sets an internal flag, which can be accessed using
89 * getSecureProcessing.
90 * @see SchemaFactory#setFeature
91 * @see #getSecureProcessing
92 */
93 public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
94 if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name))
95 secureProcessing = value;
96 else
97 super.setFeature(name, value);
98 }
99
100 /**
101 * Extends SchemaFactory.setFeature by implementing the secure processing feature.
102 * The implementation simply sets an internal flag, which can be accessed using
103 * getSecureProcessing.
104 * @see SchemaFactory#getFeature
105 * @see #getSecureProcessing
106 */
107 public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
108 if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name))
109 return secureProcessing;
110 return super.getFeature(name);
111 }
112
113 public void setSecureProcessing(boolean secureProcessing) {
114 this.secureProcessing = secureProcessing;
115 }
116
117 public boolean getSecureProcessing() {
118 return secureProcessing;
119 }
120 }