cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject svn commit: r280342 - /cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/
Date Mon, 12 Sep 2005 13:49:41 GMT
Author: pier
Date: Mon Sep 12 06:49:35 2005
New Revision: 280342

URL: http://svn.apache.org/viewcvs?rev=280342&view=rev
Log:
Fixes on caching and SourceValidity, more debugging for caches

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/AbstractValidator.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingValidator.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/JingContext.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingSchemaParser.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesEntityResolver.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/AbstractValidator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/AbstractValidator.java?rev=280342&r1=280341&r2=280342&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/AbstractValidator.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/AbstractValidator.java
Mon Sep 12 06:49:35 2005
@@ -428,7 +428,10 @@
      */
     protected String detectGrammar(Source source)
     throws IOException, SAXException, ValidatorException {
-        this.logger.debug("Detecting grammar for \"" + source.getURI() + "\"");
+        if (this.logger.isDebugEnabled()) {
+            this.logger.debug("Detecting grammar for \"" + source.getURI() + "\"");
+        }
+
         SAXParser xmlParser = null;
         String grammar = null;
 

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingValidator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingValidator.java?rev=280342&r1=280341&r2=280342&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingValidator.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingValidator.java
Mon Sep 12 06:49:35 2005
@@ -100,14 +100,21 @@
                 this.store.remove(key);
                 schema = null;
             } else if (validity.isValid() != SourceValidity.VALID) {
+                if (this.logger.isDebugEnabled()) {
+                    this.logger.warn("Cached schema " + uri + " is no longer valid");
+                }
                 this.store.remove(key);
                 schema = null;
+            } else if (this.logger.isDebugEnabled()) {
+                String m = "Valid cached schema found for " + uri;
+                this.logger.debug(m);
             }
+        } else if (this.logger.isDebugEnabled()) {
+            this.logger.warn("Schema " + uri + " not found in cache");
         }
 
         /* If the schema was not cached or was cleared, parse and cache it */
         if (schema == null) {
-            this.logger.debug("Parsing schema \"" + uri + "\"");
             schema = super.getSchema(parser, source, grammar);
             validity = schema.getValidity();
             if (validity != null) {
@@ -146,12 +153,19 @@
         if (grammar != null) {
             if (grammar.validity == null) {
                 /* Why did we cache it in the first place? */
-                this.logger.warn("Cached grammar " + uri + " has null validity");
+                this.logger.warn("Cached grammar for " + uri + " has null validity");
                 this.store.remove(key);
                 grammar = null;
             } else if (grammar.validity.isValid() != SourceValidity.VALID) {
+                if (this.logger.isDebugEnabled()) {
+                    String m = "Cached grammar for " + uri + " is no longer valid";
+                    this.logger.debug(m);
+                }
                 this.store.remove(key);
                 grammar = null;
+            } else if (this.logger.isDebugEnabled()) {
+                String m = "Valid cached grammar " + grammar + " for " + uri;
+                this.logger.debug(m);
             }
         }
 
@@ -159,7 +173,6 @@
         if (grammar != null) {
             return grammar.grammar;
         } else {
-            this.logger.debug("Detecting grammar for schema \"" + uri + "\"");
             String language = super.detectGrammar(source);
             SourceValidity validity = source.getValidity();
             if (validity != null) {

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=280342&r1=280341&r2=280342&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
Mon Sep 12 06:49:35 2005
@@ -59,7 +59,7 @@
 ThreadSafe, Contextualizable, Initializable, Disposable, Configurable {
 
     /** <p>A {@link Map} associating {@link SchemaParser}s with their names.</p>
*/
-    private final Map componentx = Collections.synchronizedMap(new HashMap());
+    private final Map components = Collections.synchronizedMap(new HashMap());
     /** <p>A {@link Map} associating component names with grammars.</p> */
     private final Map grammars = Collections.synchronizedMap(new HashMap());
 
@@ -114,7 +114,7 @@
             final String selectionKey = configuration.getAttribute("name");
             
             /* Check that we don't have a duplicate schema parser name in configs */
-            if (this.componentx.containsKey(selectionKey)) {
+            if (this.components.containsKey(selectionKey)) {
                 String message = "Duplicate schema parser \"" + selectionKey + "\"";
                 throw new ConfigurationException(message, configuration);
             }
@@ -155,7 +155,7 @@
             }
 
             /* Store this instance (and report about it) */
-            this.componentx.put(selectionKey, schemaParser);
+            this.components.put(selectionKey, schemaParser);
             this.logger.debug("SchemaParser \"" + selectionKey + "\" instantiated" +
                               " from class " + className);
 
@@ -178,7 +178,7 @@
             this.logger.warn("Exception creating schema parsers", exception);
 
             /* Dispose all previously stored component instances */
-            Iterator iterator = this.componentx.values().iterator();
+            Iterator iterator = this.components.values().iterator();
             while (iterator.hasNext()) try {
                 this.decommissionComponent(iterator.next());
             } catch (Exception nested) {
@@ -204,7 +204,7 @@
      * method is called.</p>
      */
     public void dispose() {
-        Iterator iterator = this.componentx.values().iterator();
+        Iterator iterator = this.components.values().iterator();
         while (iterator.hasNext()) try {
             this.decommissionComponent(iterator.next());
         } catch (Exception exception) {
@@ -272,8 +272,8 @@
     public Object select(Object selectionKey)
     throws ServiceException {
         /* Look up for the specified component and return it if found */
-        if ( this.componentx.containsKey(selectionKey)) {
-            return this.componentx.get(selectionKey);
+        if ( this.components.containsKey(selectionKey)) {
+            return this.components.get(selectionKey);
         }
 
         /* Fail miserably */
@@ -287,7 +287,7 @@
      * this {@link ServiceSelector} instance.</p>
      */
     public boolean isSelectable(Object selectionKey) {
-        return this.componentx.containsKey(selectionKey);
+        return this.components.containsKey(selectionKey);
     }
 
     /**

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingContext.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingContext.java?rev=280342&r1=280341&r2=280342&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingContext.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingContext.java
Mon Sep 12 06:49:35 2005
@@ -58,7 +58,8 @@
     /**
      * <p>Create a new {@link JingContext} instance.</p>
      */
-    protected JingContext(SourceResolver sourceResolver, EntityResolver entityResolver) {
+    protected JingContext(SourceResolver sourceResolver,
+                          EntityResolver entityResolver) {
         PropertyMapBuilder builder = new PropertyMapBuilder();
         ValidateProperty.ENTITY_RESOLVER.put(builder, this);
         ValidateProperty.ERROR_HANDLER.put(builder, new DraconianErrorHandler());
@@ -103,6 +104,28 @@
     }
 
     /* =========================================================================== */
+    /* INTERNAL EXCALIBUR SOURCE RESOLUTION AND CONVERSION METHODS                 */
+    /* =========================================================================== */
+
+    /**
+     * <p>Produce an {@link InputSource} from the specified {@link Source} adding
+     * its {@link SourceValidity} to the aggregate managed by this instance.</p>
+     * 
+     * @param source the {@link Source} to resolve and whose validity must be added.
+     * @return a <b>non-null</b> {@link InputSource} instance.
+     * @throws IOException if an I/O error occurred accessing the {@link Source}.
+     */
+    public InputSource resolveSource(Source source)
+    throws IOException {
+        this.sourceValidity.add(source.getValidity());
+        InputSource inputSource = new InputSource();
+        inputSource.setSystemId(source.getURI());
+        inputSource.setByteStream(source.getInputStream());
+        return inputSource;
+    }
+
+
+    /* =========================================================================== */
     /* SAX2 ENTITY RESOLVER INTERFACE IMPLEMENTATION                               */
     /* =========================================================================== */
 
@@ -155,12 +178,9 @@
         String base = parsing != null? parsing.getSystemId(): null;
         Source source = this.sourceResolver.resolveURI(systemId, base, null);
         try {
-            this.sourceValidity.add(source.getValidity());
-            InputSource inputSource = new InputSource();
-            inputSource.setSystemId(source.getURI());
-            inputSource.setPublicId(publicId);
-            inputSource.setByteStream(source.getInputStream());
-            return inputSource;
+            final InputSource input = this.resolveSource(source);
+            if (publicId != null) input.setPublicId(publicId);
+            return input;
         } finally {
             this.sourceResolver.release(source);
         }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingSchemaParser.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingSchemaParser.java?rev=280342&r1=280341&r2=280342&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingSchemaParser.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingSchemaParser.java
Mon Sep 12 06:49:35 2005
@@ -68,10 +68,7 @@
 
         SchemaReader schemaReader = SAXSchemaReader.getInstance();
         JingContext context = new JingContext(sourceResolver, entityResolver);
-        InputSource input = new InputSource();
-        input.setByteStream(source.getInputStream());
-        input.setSystemId(source.getURI());
-        context.pushInputSource(input);
+        InputSource input = context.resolveSource(source);
 
         try {
             final com.thaiopensource.validate.Schema schema;

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesEntityResolver.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesEntityResolver.java?rev=280342&r1=280341&r2=280342&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesEntityResolver.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesEntityResolver.java
Mon Sep 12 06:49:35 2005
@@ -58,18 +58,24 @@
         return this.sourceValidity;
     }
 
+    public XMLInputSource resolveSource(Source source)
+    throws XNIException, IOException {
+        this.sourceValidity.add(source.getValidity());
+        String location = source.getURI();
+        XMLInputSource input = new XMLInputSource(null, location, location);
+        input.setByteStream(source.getInputStream());
+        return input;
+    }
+
     public XMLInputSource resolveUri(String location)
     throws XNIException, IOException {
         if (this.sourceResolver == null) throw new IOException("Can't resolve now");
 
-        /* Use Cocoon's SourceResolver to resolve the system id */
+        /* Use Excalibur's SourceResolver to resolve the system id */
         Source source = this.sourceResolver.resolveURI(location);
         location = source.getURI();
         try {
-            this.sourceValidity.add(source.getValidity());
-            XMLInputSource input = new XMLInputSource(null, location, location);
-            input.setByteStream(source.getInputStream());
-            return input;
+            return this.resolveSource(source);
         } finally {
             this.sourceResolver.release(source);
         }

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=280342&r1=280341&r2=280342&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
Mon Sep 12 06:49:35 2005
@@ -25,7 +25,6 @@
 import org.apache.xerces.xni.XNIException;
 import org.apache.xerces.xni.grammars.XMLGrammarLoader;
 import org.apache.xerces.xni.grammars.XMLGrammarPool;
-import org.apache.xerces.xni.parser.XMLInputSource;
 import org.apache.xerces.xni.parser.XMLParseException;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.SAXException;
@@ -79,12 +78,9 @@
             context.initialize(loader);
 
             /* Load (parse and interpret) the grammar */
-            String uri = source.getURI();
-            this.getLogger().debug("Loading grammar from " + uri);
-            XMLInputSource input = new XMLInputSource(null, uri, uri);
-            input.setByteStream(source.getInputStream());
-            loader.loadGrammar(input);
-            this.getLogger().debug("Grammar successfully loaded from " + uri);
+            this.getLogger().debug("Loading grammar from " + source.getURI());
+            loader.loadGrammar(r.resolveSource(source));
+            this.getLogger().debug("Grammar loaded from " + source.getURI());
 
             /* Return a new Schema instance */
             SourceValidity validity = r.getSourceValidity();



Mime
View raw message