cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject svn commit: r279470 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl: CachingSchemaParser.java DefaultValidator.java XercesContext.java XercesGrammarParser.java XercesSchema.java
Date Thu, 08 Sep 2005 00:18:32 GMT
Author: pier
Date: Wed Sep  7 17:18:26 2005
New Revision: 279470

URL: http://svn.apache.org/viewcvs?rev=279470&view=rev
Log:
More debugging code (something does not work)

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingSchemaParser.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContext.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchema.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingSchemaParser.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingSchemaParser.java?rev=279470&r1=279469&r2=279470&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingSchemaParser.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingSchemaParser.java
Wed Sep  7 17:18:26 2005
@@ -23,6 +23,7 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
@@ -55,6 +56,8 @@
     protected Store transientStore = null;
     /** <p>A flag indicating whether schemas can be cached or not.</p> */
     private boolean enableCache = true;
+    /** <p>The current logger.</p> */
+    private Logger logger = null;
 
     /**
      * <p>Contextualize this component specifying a {@link ServiceManager} instance.</p>
@@ -74,8 +77,11 @@
      */
     public void configure(Configuration configuration)
     throws ConfigurationException {
+        this.logger = super.getLogger();
         Configuration subconfiguration = configuration.getChild("cache-schemas");
         this.enableCache = subconfiguration.getValueAsBoolean(true);
+        this.logger.debug("Schema caching is " + (this.enableCache? "en": "dis")
+                          + "abled for " + configuration.getAttribute("name"));
     }
 
     /**
@@ -87,7 +93,9 @@
     throws Exception {
         this.entityResolver = (EntityResolver) this.serviceManager.lookup(EntityResolver.ROLE);
         this.sourceResolver = (SourceResolver) this.serviceManager.lookup(SourceResolver.ROLE);
-        this.transientStore = (Store) this.serviceManager.lookup(Store.TRANSIENT_STORE);
+        if (this.enableCache) {
+            this.transientStore = (Store) this.serviceManager.lookup(Store.TRANSIENT_STORE);
+        }
     }
     
     /**
@@ -115,35 +123,45 @@
         }
 
         /* Prepare a key, and try to get the cached copy of the schema */
-        String key = this.getClass().getName() + ":" + uri;
-        Schema schema = (Schema) this.transientStore.get(key);
-        SourceValidity validity = null;
-
-        /* If the schema was found verify its validity and optionally clear */
-        if (schema != null) {
-            super.getLogger().debug("Accessing cached schema " + uri);
-            validity = schema.getValidity();
-            if (validity == null) {
-                super.getLogger().debug("Cached schema " + uri + " has no validity");
-                this.transientStore.remove(key);
-                schema = null;
-            } else if (validity.isValid() != SourceValidity.VALID) {
-                super.getLogger().debug("Cached schema " + uri + " is not valid");
-                this.transientStore.remove(key);
-                schema = null;
+        Schema schema = null;
+
+        if (this.transientStore != null) {
+            String key = this.getClass().getName() + ":" + uri;
+            SourceValidity validity = null;
+            schema = (Schema) this.transientStore.get(key);
+
+            /* If the schema was found verify its validity and optionally clear */
+            if (schema != null) {
+                this.logger.debug("Accessing cached schema " + uri);
+                validity = schema.getValidity();
+                if (validity == null) {
+                    this.logger.debug("Cached schema " + uri + " has no validity");
+                    this.transientStore.remove(key);
+                    schema = null;
+                } else if (validity.isValid() != SourceValidity.VALID) {
+                    this.logger.debug("Cached schema " + uri + " is not valid");
+                    this.transientStore.remove(key);
+                    schema = null;
+                }
             }
-        }
 
-        /* If the schema was not cached or was cleared, parse and cache it */
-        if (schema == null) {
-            super.getLogger().debug("Parsing schema " + uri);
-            schema = this.parseSchema(uri);
-            validity = schema.getValidity();
-            if ((validity != null) && (validity.isValid() == SourceValidity.VALID))
{
-                this.transientStore.store(key, schema);
+            /* If the schema was not cached or was cleared, parse and cache it */
+            if (schema == null) {
+                this.logger.debug("Parsing schema " + uri);
+                schema = this.parseSchema(uri);
+                validity = schema.getValidity();
+                if (validity != null) {
+                    if (validity.isValid() == SourceValidity.VALID) {
+                        this.transientStore.store(key, schema);
+                    }
+                }
             }
+        } else {
+            /* Caching is disabled */
+            schema = this.parseSchema(uri);
         }
-        
+
+
         /* Return the parsed or cached schema */
         return schema;
     }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java?rev=279470&r1=279469&r2=279470&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java
Wed Sep  7 17:18:26 2005
@@ -142,7 +142,6 @@
         Configuration configurations[] = this.conf.getChildren(this.shorthand);
         this.logger.debug("Configuring " + configurations.length + " schema parsers"
                           + " from " + this.conf.getLocation());
-
         for (int x = 0; x < configurations.length; x++) try {
             Configuration configuration = configurations[x];
             String className = configuration.getAttribute("class");
@@ -179,15 +178,17 @@
                 SchemaParser parser = (SchemaParser) component;
                 String grammars[] = parser.getSupportedGrammars();
                 if (grammars != null) {
-                    for (int k = 0; x < grammars.length; x++) {
-                        if (this.selections.containsKey(grammars[x])) continue;
-                        this.selections.put(grammars[x], component);
-                        this.logger.debug("SchemaParser " + selectionKey
-                                          + "provides grammar " + grammars[x]);
+                    for (int k = 0; k < grammars.length; k++) {
+                        if (this.selections.containsKey(grammars[k])) continue;
+                        this.selections.put(grammars[k], component);
+                        this.logger.debug("SchemaParser " + selectionKey +
+                                          "provides grammar " + grammars[k]);
                     }
                 }
             }
         } catch (Exception exception) {
+            this.logger.warn("Exception creating schema parsers", exception);
+
             Iterator iterator = this.components.iterator();
             while (iterator.hasNext()) try {
                 this.decommissionComponent(iterator.next());
@@ -204,6 +205,7 @@
                 throw new ConfigurationException(message, configuration, exception);
             }
         }
+        this.logger.debug("Configured successfully");
     }
 
     /**

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContext.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContext.java?rev=279470&r1=279469&r2=279470&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContext.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContext.java
Wed Sep  7 17:18:26 2005
@@ -29,6 +29,7 @@
 import org.apache.xerces.xni.XNIException;
 import org.apache.xerces.xni.grammars.XMLGrammarPool;
 import org.apache.xerces.xni.parser.XMLComponent;
+import org.apache.xerces.xni.parser.XMLComponentManager;
 import org.apache.xerces.xni.parser.XMLEntityResolver;
 import org.apache.xerces.xni.parser.XMLErrorHandler;
 import org.apache.xerces.xni.parser.XMLParseException;
@@ -129,14 +130,35 @@
         super.setFeature(F_VALIDATION,            true);
         super.setFeature(F_SCHEMA_VALIDATION,     true);
 
-        /* Initialize the configured Error Reporter */
+        /* Initialize all known components */
         Iterator iterator = super.fProperties.values().iterator();
-        while (iterator.hasNext()) {
-            Object object = iterator.next();
-            if (object instanceof XMLComponent) {
-                ((XMLComponent) object).reset(this);
-            }
+        while (iterator.hasNext()) this.initialize(iterator.next());
+    }
+    
+    public Object initialize(Object object) {
+        if (!(object instanceof XMLComponent)) return object;
+        XMLComponent component = (XMLComponent) object;
+        component.reset(this);
+
+        /* Force setting all known features */
+        Iterator features = super.fFeatures.keySet().iterator();
+        while (features.hasNext()) try {
+            String featureName = (String) features.next();
+            component.setFeature(featureName, this.getFeature(featureName));
+        } catch (XNIException exception) {
+            // Swallow any exception;
         }
+
+        /* Force setting all known properties */
+        Iterator properties = super.fProperties.keySet().iterator();
+        while (properties.hasNext()) try {
+            String propertyName = (String) properties.next();
+            component.setProperty(propertyName, this.getProperty(propertyName));
+        } catch (XNIException exception) {
+            // Swallow any exception;
+        }
+        
+        return object;
     }
 
     /**
@@ -153,33 +175,39 @@
 
         public void warning(String domain, String key, XMLParseException e)
         throws XNIException {
+            System.err.println("DETECTED " + e.getMessage() + "/" + this.errorHandler);
             if (this.errorHandler != null) try {
                 this.errorHandler.warning(this.makeException(e));
             } catch (SAXException saxException) {
                 throw new XNIException(saxException);
             } else {
+                System.err.println("THROWING " + e.getMessage());
                 throw e;
             }
         }
 
         public void error(String domain, String key, XMLParseException e)
         throws XNIException {
+            System.err.println("DETECTED " + e.getMessage() + "/" + this.errorHandler);
             if (this.errorHandler != null) try {
                 this.errorHandler.warning(this.makeException(e));
             } catch (SAXException saxException) {
                 throw new XNIException(saxException);
             } else {
+                System.err.println("THROWING " + e.getMessage());
                 throw e;
             }
         }
 
         public void fatalError(String domain, String key, XMLParseException e)
         throws XNIException {
+            System.err.println("DETECTED " + e.getMessage() + "/" + this.errorHandler);
             if (this.errorHandler != null) try {
                 this.errorHandler.warning(this.makeException(e));
             } catch (SAXException saxException) {
                 throw new XNIException(saxException);
             } else {
+                System.err.println("THROWING " + e.getMessage());
                 throw e;
             }
         }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java?rev=279470&r1=279469&r2=279470&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java
Wed Sep  7 17:18:26 2005
@@ -23,7 +23,6 @@
 import org.apache.xerces.util.XMLGrammarPoolImpl;
 import org.apache.xerces.xni.grammars.XMLGrammarLoader;
 import org.apache.xerces.xni.grammars.XMLGrammarPool;
-import org.apache.xerces.xni.parser.XMLComponent;
 import org.xml.sax.SAXException;
 
 /**
@@ -62,10 +61,12 @@
 
         /* Create a new XML Schema Loader and set the pool into it */
         XMLGrammarLoader loader = this.newGrammarLoader();
-        ((XMLComponent) loader).reset(context);
+        context.initialize(loader);
 
         /* Load (parse and interpret) the grammar */
+        this.getLogger().debug("Loading grammar from " + uri);
         loader.loadGrammar(res.resolveUri(uri));
+        this.getLogger().debug("Grammar successfully loaded from " + uri);
 
         /* Return a new Schema instance */
         SourceValidity validity = res.getSourceValidity();

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchema.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchema.java?rev=279470&r1=279469&r2=279470&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchema.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchema.java
Wed Sep  7 17:18:26 2005
@@ -18,7 +18,6 @@
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.xerces.xni.XMLDocumentHandler;
 import org.apache.xerces.xni.grammars.XMLGrammarPool;
-import org.apache.xerces.xni.parser.XMLComponent;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.SAXException;
@@ -58,8 +57,7 @@
                                                   new XercesEntityResolver(),
                                                   errorHandler);
         try {
-            Object instance = this.validatorClass.newInstance();
-            ((XMLComponent) instance).reset(context);
+            Object instance = context.initialize(this.validatorClass.newInstance());
             return new XercesContentHandler((XMLDocumentHandler) instance);
         } catch (Exception exception) {
             throw new SAXException("Unable to access validator", exception);



Mime
View raw message