src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaLoader.java

Print this page




  59 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  60 import com.sun.org.apache.xerces.internal.xs.LSInputList;
  61 import com.sun.org.apache.xerces.internal.xs.StringList;
  62 import com.sun.org.apache.xerces.internal.xs.XSLoader;
  63 import com.sun.org.apache.xerces.internal.xs.XSModel;
  64 import java.io.BufferedInputStream;
  65 import java.io.File;
  66 import java.io.FileInputStream;
  67 import java.io.FileNotFoundException;
  68 import java.io.IOException;
  69 import java.io.InputStream;
  70 import java.io.Reader;
  71 import java.io.StringReader;
  72 import java.util.ArrayList;
  73 import java.util.HashMap;
  74 import java.util.Locale;
  75 import java.util.Map;
  76 import java.util.StringTokenizer;
  77 import java.util.WeakHashMap;
  78 import javax.xml.XMLConstants;

  79 import org.w3c.dom.DOMConfiguration;
  80 import org.w3c.dom.DOMError;
  81 import org.w3c.dom.DOMErrorHandler;
  82 import org.w3c.dom.DOMException;
  83 import org.w3c.dom.DOMStringList;
  84 import org.w3c.dom.ls.LSInput;
  85 import org.w3c.dom.ls.LSResourceResolver;
  86 import org.xml.sax.InputSource;
  87 
  88 /**
  89  * This class implements xni.grammars.XMLGrammarLoader.
  90  * It also serves as implementation of xs.XSLoader interface and DOMConfiguration interface.
  91  *
  92  * This class is designed to interact either with a proxy for a user application
  93  * which wants to preparse schemas, or with our own Schema validator.
  94  * It is hoped that none of these "external" classes will therefore need to communicate directly
  95  * with XSDHandler in future.
  96  * <p>This class only knows how to make XSDHandler do its thing.
  97  * The caller must ensure that all its properties (schemaLocation, JAXPSchemaSource
  98  * etc.) have been properly set.


 156 
 157     /** Property identifier: Schema DV Factory */
 158     protected static final String SCHEMA_DV_FACTORY =
 159         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
 160 
 161     protected static final String USE_SERVICE_MECHANISM = Constants.ORACLE_FEATURE_SERVICE_MECHANISM;
 162 
 163     // recognized features:
 164     private static final String[] RECOGNIZED_FEATURES = {
 165         SCHEMA_FULL_CHECKING,
 166         AUGMENT_PSVI,
 167         CONTINUE_AFTER_FATAL_ERROR,
 168         ALLOW_JAVA_ENCODINGS,
 169         STANDARD_URI_CONFORMANT_FEATURE,
 170         DISALLOW_DOCTYPE,
 171         GENERATE_SYNTHETIC_ANNOTATIONS,
 172         VALIDATE_ANNOTATIONS,
 173         HONOUR_ALL_SCHEMALOCATIONS,
 174         NAMESPACE_GROWTH,
 175         TOLERATE_DUPLICATES,
 176         USE_SERVICE_MECHANISM

 177     };
 178 
 179     // property identifiers
 180 
 181     /** Property identifier: symbol table. */
 182     public static final String SYMBOL_TABLE =
 183         Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
 184 
 185     /** Property identifier: error reporter. */
 186     public static final String ERROR_REPORTER =
 187         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
 188 
 189     /** Property identifier: error handler. */
 190     protected static final String ERROR_HANDLER =
 191         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
 192 
 193     /** Property identifier: entity resolver. */
 194     public static final String ENTITY_RESOLVER =
 195         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
 196 
 197     /** Property identifier: grammar pool. */
 198     public static final String XMLGRAMMAR_POOL =
 199         Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
 200 
 201     /** Property identifier: schema location. */
 202     protected static final String SCHEMA_LOCATION =
 203         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION;
 204 
 205     /** Property identifier: no namespace schema location. */
 206     protected static final String SCHEMA_NONS_LOCATION =
 207         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;
 208 
 209     /** Property identifier: JAXP schema source. */
 210     protected static final String JAXP_SCHEMA_SOURCE =


 227     /** Property identifier: access to external dtd */
 228     public static final String ACCESS_EXTERNAL_DTD = XMLConstants.ACCESS_EXTERNAL_DTD;
 229 
 230     /** Property identifier: access to external schema */
 231     public static final String ACCESS_EXTERNAL_SCHEMA = XMLConstants.ACCESS_EXTERNAL_SCHEMA;
 232 
 233     // recognized properties
 234     private static final String [] RECOGNIZED_PROPERTIES = {
 235         ENTITY_MANAGER,
 236         SYMBOL_TABLE,
 237         ERROR_REPORTER,
 238         ERROR_HANDLER,
 239         ENTITY_RESOLVER,
 240         XMLGRAMMAR_POOL,
 241         SCHEMA_LOCATION,
 242         SCHEMA_NONS_LOCATION,
 243         JAXP_SCHEMA_SOURCE,
 244         SECURITY_MANAGER,
 245         LOCALE,
 246         SCHEMA_DV_FACTORY,
 247         XML_SECURITY_PROPERTY_MANAGER




 248     };
 249 
 250     // Data
 251 
 252     // features and properties
 253     private final ParserConfigurationSettings fLoaderConfig = new ParserConfigurationSettings();
 254     private XMLErrorReporter fErrorReporter = new XMLErrorReporter ();
 255     private XMLEntityManager fEntityManager = null;
 256     private XMLEntityResolver fUserEntityResolver = null;
 257     private XMLGrammarPool fGrammarPool = null;
 258     private String fExternalSchemas = null;
 259     private String fExternalNoNSSchema = null;
 260     // JAXP property: schema source
 261     private Object fJAXPSource = null;
 262     // is Schema Full Checking enabled
 263     private boolean fIsCheckedFully = false;
 264     // boolean that tells whether we've tested the JAXP property.
 265     private boolean fJAXPProcessed = false;
 266     // if features/properties has not been changed, the value of this attribute is "false"
 267     private boolean fSettingsChanged = true;


 796         }
 797         else if ( (componentType != Object.class) &&
 798                 (componentType != String.class) &&
 799                 !File.class.isAssignableFrom(componentType) &&
 800                 !InputStream.class.isAssignableFrom(componentType) &&
 801                 !InputSource.class.isAssignableFrom(componentType) &&
 802                 !componentType.isInterface()
 803         ) {
 804             // Not an Object[], String[], File[], InputStream[], InputSource[]
 805             MessageFormatter mf = fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN);
 806             throw new XMLConfigurationException(
 807                     Status.NOT_SUPPORTED,
 808                     mf.formatMessage(fErrorReporter.getLocale(), "jaxp12-schema-source-type.2",
 809                     new Object [] {componentType.getName()}));
 810         }
 811 
 812         // JAXP spec. allow []s of type String, File, InputStream,
 813         // InputSource also, apart from [] of type Object.
 814         Object[] objArr = (Object[]) fJAXPSource;
 815         // make local array for storing target namespaces of schemasources specified in object arrays.
 816         ArrayList jaxpSchemaSourceNamespaces = new ArrayList();
 817         for (int i = 0; i < objArr.length; i++) {
 818             if (objArr[i] instanceof InputStream ||
 819                     objArr[i] instanceof InputSource) {
 820                 SchemaGrammar g = (SchemaGrammar)fJAXPCache.get(objArr[i]);
 821                 if (g != null) {
 822                     fGrammarBucket.putGrammar(g);
 823                     continue;
 824                 }
 825             }
 826             fXSDDescription.reset();
 827             xis = xsdToXMLInputSource(objArr[i]);
 828             sid = xis.getSystemId();
 829             fXSDDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
 830             if (sid != null) {
 831                 fXSDDescription.setBaseSystemId(xis.getBaseSystemId());
 832                 fXSDDescription.setLiteralSystemId(sid);
 833                 fXSDDescription.setExpandedSystemId(sid);
 834                 fXSDDescription.fLocationHints = new String[]{sid};
 835             }
 836             String targetNamespace = null ;


1263             Object property;
1264             try {
1265                 property = getProperty(name);
1266                 return property;
1267             } catch (Exception ex) {
1268                 String msg =
1269                     DOMMessageFormatter.formatMessage(
1270                             DOMMessageFormatter.DOM_DOMAIN,
1271                             "FEATURE_NOT_SUPPORTED",
1272                             new Object[] { name });
1273                 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
1274             }
1275         }
1276     }
1277 
1278     /* (non-Javadoc)
1279      * @see DOMConfiguration#getParameterNames()
1280      */
1281     public DOMStringList getParameterNames() {
1282         if (fRecognizedParameters == null){
1283             ArrayList v = new ArrayList();
1284             v.add(Constants.DOM_VALIDATE);
1285             v.add(Constants.DOM_ERROR_HANDLER);
1286             v.add(Constants.DOM_RESOURCE_RESOLVER);
1287             v.add(SYMBOL_TABLE);
1288             v.add(ERROR_REPORTER);
1289             v.add(ERROR_HANDLER);
1290             v.add(ENTITY_RESOLVER);
1291             v.add(XMLGRAMMAR_POOL);
1292             v.add(SCHEMA_LOCATION);
1293             v.add(SCHEMA_NONS_LOCATION);
1294             v.add(JAXP_SCHEMA_SOURCE);
1295             v.add(SCHEMA_FULL_CHECKING);
1296             v.add(CONTINUE_AFTER_FATAL_ERROR);
1297             v.add(ALLOW_JAVA_ENCODINGS);
1298             v.add(STANDARD_URI_CONFORMANT_FEATURE);
1299             v.add(VALIDATE_ANNOTATIONS);
1300             v.add(GENERATE_SYNTHETIC_ANNOTATIONS);
1301             v.add(HONOUR_ALL_SCHEMALOCATIONS);
1302             v.add(NAMESPACE_GROWTH);
1303             v.add(TOLERATE_DUPLICATES);




  59 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  60 import com.sun.org.apache.xerces.internal.xs.LSInputList;
  61 import com.sun.org.apache.xerces.internal.xs.StringList;
  62 import com.sun.org.apache.xerces.internal.xs.XSLoader;
  63 import com.sun.org.apache.xerces.internal.xs.XSModel;
  64 import java.io.BufferedInputStream;
  65 import java.io.File;
  66 import java.io.FileInputStream;
  67 import java.io.FileNotFoundException;
  68 import java.io.IOException;
  69 import java.io.InputStream;
  70 import java.io.Reader;
  71 import java.io.StringReader;
  72 import java.util.ArrayList;
  73 import java.util.HashMap;
  74 import java.util.Locale;
  75 import java.util.Map;
  76 import java.util.StringTokenizer;
  77 import java.util.WeakHashMap;
  78 import javax.xml.XMLConstants;
  79 import jdk.xml.internal.JdkXmlUtils;
  80 import org.w3c.dom.DOMConfiguration;
  81 import org.w3c.dom.DOMError;
  82 import org.w3c.dom.DOMErrorHandler;
  83 import org.w3c.dom.DOMException;
  84 import org.w3c.dom.DOMStringList;
  85 import org.w3c.dom.ls.LSInput;
  86 import org.w3c.dom.ls.LSResourceResolver;
  87 import org.xml.sax.InputSource;
  88 
  89 /**
  90  * This class implements xni.grammars.XMLGrammarLoader.
  91  * It also serves as implementation of xs.XSLoader interface and DOMConfiguration interface.
  92  *
  93  * This class is designed to interact either with a proxy for a user application
  94  * which wants to preparse schemas, or with our own Schema validator.
  95  * It is hoped that none of these "external" classes will therefore need to communicate directly
  96  * with XSDHandler in future.
  97  * <p>This class only knows how to make XSDHandler do its thing.
  98  * The caller must ensure that all its properties (schemaLocation, JAXPSchemaSource
  99  * etc.) have been properly set.


 157 
 158     /** Property identifier: Schema DV Factory */
 159     protected static final String SCHEMA_DV_FACTORY =
 160         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
 161 
 162     protected static final String USE_SERVICE_MECHANISM = Constants.ORACLE_FEATURE_SERVICE_MECHANISM;
 163 
 164     // recognized features:
 165     private static final String[] RECOGNIZED_FEATURES = {
 166         SCHEMA_FULL_CHECKING,
 167         AUGMENT_PSVI,
 168         CONTINUE_AFTER_FATAL_ERROR,
 169         ALLOW_JAVA_ENCODINGS,
 170         STANDARD_URI_CONFORMANT_FEATURE,
 171         DISALLOW_DOCTYPE,
 172         GENERATE_SYNTHETIC_ANNOTATIONS,
 173         VALIDATE_ANNOTATIONS,
 174         HONOUR_ALL_SCHEMALOCATIONS,
 175         NAMESPACE_GROWTH,
 176         TOLERATE_DUPLICATES,
 177         USE_SERVICE_MECHANISM,
 178         XMLConstants.USE_CATALOG
 179     };
 180 
 181     // property identifiers
 182 
 183     /** Property identifier: symbol table. */
 184     public static final String SYMBOL_TABLE =
 185         Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
 186 
 187     /** Property identifier: error reporter. */
 188     public static final String ERROR_REPORTER =
 189         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
 190 
 191     /** Property identifier: error handler. */
 192     public static final String ERROR_HANDLER =
 193         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
 194 
 195     /** Property identifier: entity resolver. */
 196     public static final String ENTITY_RESOLVER =
 197         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
 198 
 199     /** Property identifier: grammar pool. */
 200     public static final String XMLGRAMMAR_POOL =
 201         Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
 202 
 203     /** Property identifier: schema location. */
 204     protected static final String SCHEMA_LOCATION =
 205         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION;
 206 
 207     /** Property identifier: no namespace schema location. */
 208     protected static final String SCHEMA_NONS_LOCATION =
 209         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;
 210 
 211     /** Property identifier: JAXP schema source. */
 212     protected static final String JAXP_SCHEMA_SOURCE =


 229     /** Property identifier: access to external dtd */
 230     public static final String ACCESS_EXTERNAL_DTD = XMLConstants.ACCESS_EXTERNAL_DTD;
 231 
 232     /** Property identifier: access to external schema */
 233     public static final String ACCESS_EXTERNAL_SCHEMA = XMLConstants.ACCESS_EXTERNAL_SCHEMA;
 234 
 235     // recognized properties
 236     private static final String [] RECOGNIZED_PROPERTIES = {
 237         ENTITY_MANAGER,
 238         SYMBOL_TABLE,
 239         ERROR_REPORTER,
 240         ERROR_HANDLER,
 241         ENTITY_RESOLVER,
 242         XMLGRAMMAR_POOL,
 243         SCHEMA_LOCATION,
 244         SCHEMA_NONS_LOCATION,
 245         JAXP_SCHEMA_SOURCE,
 246         SECURITY_MANAGER,
 247         LOCALE,
 248         SCHEMA_DV_FACTORY,
 249         XML_SECURITY_PROPERTY_MANAGER,
 250         JdkXmlUtils.CATALOG_DEFER,
 251         JdkXmlUtils.CATALOG_FILES,
 252         JdkXmlUtils.CATALOG_PREFER,
 253         JdkXmlUtils.CATALOG_RESOLVE
 254     };
 255 
 256     // Data
 257 
 258     // features and properties
 259     private final ParserConfigurationSettings fLoaderConfig = new ParserConfigurationSettings();
 260     private XMLErrorReporter fErrorReporter = new XMLErrorReporter ();
 261     private XMLEntityManager fEntityManager = null;
 262     private XMLEntityResolver fUserEntityResolver = null;
 263     private XMLGrammarPool fGrammarPool = null;
 264     private String fExternalSchemas = null;
 265     private String fExternalNoNSSchema = null;
 266     // JAXP property: schema source
 267     private Object fJAXPSource = null;
 268     // is Schema Full Checking enabled
 269     private boolean fIsCheckedFully = false;
 270     // boolean that tells whether we've tested the JAXP property.
 271     private boolean fJAXPProcessed = false;
 272     // if features/properties has not been changed, the value of this attribute is "false"
 273     private boolean fSettingsChanged = true;


 802         }
 803         else if ( (componentType != Object.class) &&
 804                 (componentType != String.class) &&
 805                 !File.class.isAssignableFrom(componentType) &&
 806                 !InputStream.class.isAssignableFrom(componentType) &&
 807                 !InputSource.class.isAssignableFrom(componentType) &&
 808                 !componentType.isInterface()
 809         ) {
 810             // Not an Object[], String[], File[], InputStream[], InputSource[]
 811             MessageFormatter mf = fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN);
 812             throw new XMLConfigurationException(
 813                     Status.NOT_SUPPORTED,
 814                     mf.formatMessage(fErrorReporter.getLocale(), "jaxp12-schema-source-type.2",
 815                     new Object [] {componentType.getName()}));
 816         }
 817 
 818         // JAXP spec. allow []s of type String, File, InputStream,
 819         // InputSource also, apart from [] of type Object.
 820         Object[] objArr = (Object[]) fJAXPSource;
 821         // make local array for storing target namespaces of schemasources specified in object arrays.
 822         ArrayList<String> jaxpSchemaSourceNamespaces = new ArrayList<>();
 823         for (int i = 0; i < objArr.length; i++) {
 824             if (objArr[i] instanceof InputStream ||
 825                     objArr[i] instanceof InputSource) {
 826                 SchemaGrammar g = (SchemaGrammar)fJAXPCache.get(objArr[i]);
 827                 if (g != null) {
 828                     fGrammarBucket.putGrammar(g);
 829                     continue;
 830                 }
 831             }
 832             fXSDDescription.reset();
 833             xis = xsdToXMLInputSource(objArr[i]);
 834             sid = xis.getSystemId();
 835             fXSDDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
 836             if (sid != null) {
 837                 fXSDDescription.setBaseSystemId(xis.getBaseSystemId());
 838                 fXSDDescription.setLiteralSystemId(sid);
 839                 fXSDDescription.setExpandedSystemId(sid);
 840                 fXSDDescription.fLocationHints = new String[]{sid};
 841             }
 842             String targetNamespace = null ;


1269             Object property;
1270             try {
1271                 property = getProperty(name);
1272                 return property;
1273             } catch (Exception ex) {
1274                 String msg =
1275                     DOMMessageFormatter.formatMessage(
1276                             DOMMessageFormatter.DOM_DOMAIN,
1277                             "FEATURE_NOT_SUPPORTED",
1278                             new Object[] { name });
1279                 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
1280             }
1281         }
1282     }
1283 
1284     /* (non-Javadoc)
1285      * @see DOMConfiguration#getParameterNames()
1286      */
1287     public DOMStringList getParameterNames() {
1288         if (fRecognizedParameters == null){
1289             ArrayList<String> v = new ArrayList<>();
1290             v.add(Constants.DOM_VALIDATE);
1291             v.add(Constants.DOM_ERROR_HANDLER);
1292             v.add(Constants.DOM_RESOURCE_RESOLVER);
1293             v.add(SYMBOL_TABLE);
1294             v.add(ERROR_REPORTER);
1295             v.add(ERROR_HANDLER);
1296             v.add(ENTITY_RESOLVER);
1297             v.add(XMLGRAMMAR_POOL);
1298             v.add(SCHEMA_LOCATION);
1299             v.add(SCHEMA_NONS_LOCATION);
1300             v.add(JAXP_SCHEMA_SOURCE);
1301             v.add(SCHEMA_FULL_CHECKING);
1302             v.add(CONTINUE_AFTER_FATAL_ERROR);
1303             v.add(ALLOW_JAVA_ENCODINGS);
1304             v.add(STANDARD_URI_CONFORMANT_FEATURE);
1305             v.add(VALIDATE_ANNOTATIONS);
1306             v.add(GENERATE_SYNTHETIC_ANNOTATIONS);
1307             v.add(HONOUR_ALL_SCHEMALOCATIONS);
1308             v.add(NAMESPACE_GROWTH);
1309             v.add(TOLERATE_DUPLICATES);