Author: mrglavas
Date: Sun Feb 26 10:20:57 2006
New Revision: 381134
URL: http://svn.apache.org/viewcvs?rev=381134&view=rev
Log:
JIRA Issue #1143:
http://issues.apache.org/jira/browse/XERCESJ-1143
JAXP 1.4 clarifies that features set on the SchemaFactory should be propogated
to the Schemas created from the factory and in turn ValidatorHandlers and
Validators constructed from those Schema objects. Feature propogation is now
supported thanks to the patch by Peter McCracken which I've modified slightly
so that the secure processing feature is set correctly.
Modified:
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/AbstractXMLSchema.java
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/EmptyXMLSchema.java
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaValidatorComponentManager.java
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XSGrammarPoolContainer.java
Modified:
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/AbstractXMLSchema.java
URL:
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/AbstractXMLSchema.java?rev=381134&r1=381133&r2=381134&view=diff
==============================================================================
---
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/AbstractXMLSchema.java
(original)
+++
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/AbstractXMLSchema.java
Sun Feb 26 10:20:57 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package org.apache.xerces.jaxp.validation;
+import java.util.HashMap;
+
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;
import javax.xml.validation.ValidatorHandler;
@@ -29,6 +31,16 @@
abstract class AbstractXMLSchema extends Schema implements
XSGrammarPoolContainer {
+ /**
+ * Map containing the initial values of features for
+ * validators created using this grammar pool container.
+ */
+ private final HashMap fFeatures;
+
+ public AbstractXMLSchema() {
+ fFeatures = new HashMap();
+ }
+
/*
* Schema methods
*/
@@ -45,6 +57,27 @@
*/
public final ValidatorHandler newValidatorHandler() {
return new ValidatorHandlerImpl(this);
+ }
+
+ /*
+ * XSGrammarPoolContainer methods
+ */
+
+ /**
+ * Returns the initial value of a feature for validators created
+ * using this grammar pool container or null if the validators
+ * should use the default value.
+ */
+ public final Boolean getFeature(String featureId) {
+ return (Boolean) fFeatures.get(featureId);
+ }
+
+ /*
+ * Other methods
+ */
+
+ final void setFeature(String featureId, boolean state) {
+ fFeatures.put(featureId, state ? Boolean.TRUE : Boolean.FALSE);
}
} // AbstractXMLSchema
Modified:
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/EmptyXMLSchema.java
URL:
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/EmptyXMLSchema.java?rev=381134&r1=381133&r2=381134&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/jaxp/validation/EmptyXMLSchema.java
(original)
+++ xerces/java/trunk/src/org/apache/xerces/jaxp/validation/EmptyXMLSchema.java
Sun Feb 26 10:20:57 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,17 +29,10 @@
*/
final class EmptyXMLSchema extends AbstractXMLSchema implements XMLGrammarPool
{
- private static EmptyXMLSchema EMPTY_XML_SCHEMA_INSTANCE = new
EmptyXMLSchema();
-
/** Zero length grammar array. */
private static final Grammar [] ZERO_LENGTH_GRAMMAR_ARRAY = new Grammar
[0];
- /** Returns the one and only instance of this class. */
- public static EmptyXMLSchema getInstance() {
- return EMPTY_XML_SCHEMA_INSTANCE;
- }
-
- private EmptyXMLSchema() {}
+ public EmptyXMLSchema() {}
/*
* XMLGrammarPool methods
Modified:
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java
URL:
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java?rev=381134&r1=381133&r2=381134&view=diff
==============================================================================
---
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java
(original)
+++
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java
Sun Feb 26 10:20:57 2006
@@ -231,21 +231,24 @@
// Select Schema implementation based on grammar count.
final int grammarCount = pool.getGrammarCount();
+ AbstractXMLSchema schema = null;
if (fUseGrammarPoolOnly) {
if (grammarCount > 1) {
- return new XMLSchema(new ReadOnlyGrammarPool(pool));
+ schema = new XMLSchema(new ReadOnlyGrammarPool(pool));
}
else if (grammarCount == 1) {
Grammar[] grammars =
pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
- return new SimpleXMLSchema(grammars[0]);
+ schema = new SimpleXMLSchema(grammars[0]);
}
else {
- return EmptyXMLSchema.getInstance();
+ schema = new EmptyXMLSchema();
}
}
else {
- return new XMLSchema(new ReadOnlyGrammarPool(pool), false);
+ schema = new XMLSchema(new ReadOnlyGrammarPool(pool), false);
}
+ propagateFeatures(schema);
+ return schema;
}
public Schema newSchema() throws SAXException {
@@ -258,7 +261,9 @@
*/
// Use a Schema that uses the system id as the equality source.
- return new WeakReferenceXMLSchema();
+ AbstractXMLSchema schema = new WeakReferenceXMLSchema();
+ propagateFeatures(schema);
+ return schema;
}
public boolean getFeature(String name)
@@ -387,6 +392,15 @@
SAXMessageFormatter.formatMessage(Locale.getDefault(),
"property-not-supported", new Object [] {identifier}));
}
+ }
+ }
+
+ 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);
}
}
Modified:
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaValidatorComponentManager.java
URL:
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaValidatorComponentManager.java?rev=381134&r1=381133&r2=381134&view=diff
==============================================================================
---
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaValidatorComponentManager.java
(original)
+++
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaValidatorComponentManager.java
Sun Feb 26 10:20:57 2006
@@ -17,6 +17,8 @@
package org.apache.xerces.jaxp.validation;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import javax.xml.XMLConstants;
@@ -160,6 +162,19 @@
private ValidationManager fValidationManager;
//
+ // Configuration
+ //
+
+ /** Stores initial feature values for validator reset. */
+ private HashMap fInitFeatures = new HashMap();
+
+ /** Stores initial property values for validator reset. */
+ private HashMap fInitProperties = new HashMap();
+
+ /** Stores the initial security manager. */
+ private SecurityManager fInitSecurityManager = null;
+
+ //
// User Objects
//
@@ -171,6 +186,7 @@
/** Constructs a component manager suitable for Xerces' schema validator.
*/
public XMLSchemaValidatorComponentManager(XSGrammarPoolContainer
grammarContainer) {
+
// setup components
fEntityManager = new XMLEntityManager();
fComponents.put(ENTITY_MANAGER, fEntityManager);
@@ -201,9 +217,16 @@
fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN,
new XSMessageFormatter());
// add all recognized features and properties and apply their defaults
- addRecognizedParamsAndSetDefaults(fEntityManager);
- addRecognizedParamsAndSetDefaults(fErrorReporter);
- addRecognizedParamsAndSetDefaults(fSchemaValidator);
+ addRecognizedParamsAndSetDefaults(fEntityManager, grammarContainer);
+ addRecognizedParamsAndSetDefaults(fErrorReporter, grammarContainer);
+ addRecognizedParamsAndSetDefaults(fSchemaValidator, grammarContainer);
+
+ // if the secure processing feature is set to true, add a security
manager to the configuration
+ Boolean secureProcessing =
grammarContainer.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
+ if (Boolean.TRUE.equals(secureProcessing)) {
+ fInitSecurityManager = new SecurityManager();
+ }
+ fComponents.put(SECURITY_MANAGER, fInitSecurityManager);
/* TODO: are other XMLSchemaValidator default values never set?
* Initial investigation indicates that they aren't set, but
@@ -263,14 +286,18 @@
else if (USE_GRAMMAR_POOL_ONLY.equals(featureId) && value !=
fUseGrammarPoolOnly) {
throw new
XMLConfigurationException(XMLConfigurationException.NOT_SUPPORTED, featureId);
}
- fConfigUpdated = true;
if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(featureId)) {
setProperty(SECURITY_MANAGER, value ? new SecurityManager() :
null);
return;
}
+ fConfigUpdated = true;
fEntityManager.setFeature(featureId, value);
fErrorReporter.setFeature(featureId, value);
fSchemaValidator.setFeature(featureId, value);
+ if (!fInitFeatures.containsKey(featureId)) {
+ boolean current = super.getFeature(featureId);
+ fInitFeatures.put(featureId, current ? Boolean.TRUE :
Boolean.FALSE);
+ }
super.setFeature(featureId, value);
}
@@ -322,6 +349,9 @@
fComponents.put(propertyId, value);
return;
}
+ if (!fInitProperties.containsKey(propertyId)) {
+ fInitProperties.put(propertyId, super.getProperty(propertyId));
+ }
super.setProperty(propertyId, value);
}
@@ -334,7 +364,7 @@
* @param component The component whose recognized features
* and properties will be added to the configuration
*/
- public void addRecognizedParamsAndSetDefaults(XMLComponent component) {
+ public void addRecognizedParamsAndSetDefaults(XMLComponent component,
XSGrammarPoolContainer grammarContainer) {
// register component's recognized features
final String[] recognizedFeatures = component.getRecognizedFeatures();
@@ -345,7 +375,7 @@
addRecognizedProperties(recognizedProperties);
// set default values
- setFeatureDefaults(component, recognizedFeatures);
+ setFeatureDefaults(component, recognizedFeatures, grammarContainer);
setPropertyDefaults(component, recognizedProperties);
}
@@ -383,29 +413,46 @@
void restoreInitialState() {
fConfigUpdated = true;
- // Clear feature and property tables.
- fFeatures.clear();
- fProperties.clear();
-
// Remove error resolver and error handler
fComponents.put(ENTITY_RESOLVER, null);
fComponents.put(ERROR_HANDLER, null);
- // Restore component defaults.
- setFeatureDefaults(fEntityManager,
fEntityManager.getRecognizedFeatures());
- setPropertyDefaults(fEntityManager,
fEntityManager.getRecognizedProperties());
- setFeatureDefaults(fErrorReporter,
fErrorReporter.getRecognizedFeatures());
- setPropertyDefaults(fErrorReporter,
fErrorReporter.getRecognizedProperties());
- setFeatureDefaults(fSchemaValidator,
fSchemaValidator.getRecognizedFeatures());
- setPropertyDefaults(fSchemaValidator,
fSchemaValidator.getRecognizedProperties());
+ // Restore initial security manager
+ fComponents.put(SECURITY_MANAGER, fInitSecurityManager);
+
+ // Reset feature and property values to their initial values
+ if (!fInitFeatures.isEmpty()) {
+ Iterator iter = fInitFeatures.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ String name = (String) entry.getKey();
+ boolean value = ((Boolean) entry.getValue()).booleanValue();
+ super.setFeature(name, value);
+ }
+ fInitFeatures.clear();
+ }
+ if (!fInitProperties.isEmpty()) {
+ Iterator iter = fInitProperties.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ String name = (String) entry.getKey();
+ Object value = entry.getValue();
+ super.setProperty(name, value);
+ }
+ fInitProperties.clear();
+ }
}
/** Sets feature defaults for the given component on this configuration. */
- private void setFeatureDefaults(final XMLComponent component, final String
[] recognizedFeatures) {
+ private void setFeatureDefaults(final XMLComponent component,
+ final String [] recognizedFeatures, XSGrammarPoolContainer
grammarContainer) {
if (recognizedFeatures != null) {
for (int i = 0; i < recognizedFeatures.length; ++i) {
String featureId = recognizedFeatures[i];
- Boolean state = component.getFeatureDefault(featureId);
+ Boolean state = grammarContainer.getFeature(featureId);
+ if (state == null) {
+ state = component.getFeatureDefault(featureId);
+ }
if (state != null) {
// Do not overwrite values already set on the
configuration.
if (!fFeatures.containsKey(featureId)) {
Modified:
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XSGrammarPoolContainer.java
URL:
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XSGrammarPoolContainer.java?rev=381134&r1=381133&r2=381134&view=diff
==============================================================================
---
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XSGrammarPoolContainer.java
(original)
+++
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XSGrammarPoolContainer.java
Sun Feb 26 10:20:57 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,5 +43,12 @@
* can be considered to be a fully composed schema
*/
public boolean isFullyComposed();
+
+ /**
+ * Returns the initial value of a feature for validators created
+ * using this grammar pool container or null if the validators
+ * should use the default value.
+ */
+ public Boolean getFeature(String featureId);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]