You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2007/10/19 03:45:48 UTC

svn commit: r586214 - in /cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation: ./ impl/

Author: vgritsenko
Date: Thu Oct 18 18:45:47 2007
New Revision: 586214

URL: http://svn.apache.org/viewvc?rev=586214&view=rev
Log:
switching to new AbstractLogEnabled

Modified:
    cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/SchemaParser.java
    cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/AbstractSchemaParser.java
    cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/AbstractValidator.java
    cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/CachingValidator.java
    cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java

Modified: cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/SchemaParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/SchemaParser.java?rev=586214&r1=586213&r2=586214&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/SchemaParser.java (original)
+++ cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/SchemaParser.java Thu Oct 18 18:45:47 2007
@@ -29,7 +29,8 @@
  * <p>A {@link SchemaParser} might be able to understand more than one grammar
  * language at the same time. The list of all supported grammar languages must be
  * returned by the {@link #getSupportedGrammars()} method.</p>
- * 
+ *
+ * @version $Id$
  */
 public interface SchemaParser {
 
@@ -40,7 +41,7 @@
      * <p>Parse the specified {@link Source} and return a new {@link Schema}.</p>
      * 
      * <p>The returned {@link Schema} must be able to validate multiple documents
-     * via multiple invocations of {@link Schema#createValidator(ErrorHandler)}.</p> 
+     * via multiple invocations of {@link Schema#createValidator(org.xml.sax.ErrorHandler)}.</p>
      *
      * @param source the {@link Source} associated with the {@link Schema} to return.
      * @return a <b>non-null</b> {@link Schema} instance.

Modified: cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/AbstractSchemaParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/AbstractSchemaParser.java?rev=586214&r1=586213&r2=586214&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/AbstractSchemaParser.java (original)
+++ cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/AbstractSchemaParser.java Thu Oct 18 18:45:47 2007
@@ -18,45 +18,42 @@
 
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.logger.LogEnabled;
-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;
-import org.apache.cocoon.components.validation.SchemaParser;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.excalibur.xml.EntityResolver;
 
+import org.apache.cocoon.components.validation.SchemaParser;
+import org.apache.cocoon.util.AbstractLogEnabled;
+
 /**
- * <p>A {@link SchemaParser} caching {@link Schema} instance for multiple use.</p>
+ * <p>A {@link SchemaParser} caching {@link org.apache.cocoon.components.validation.Schema}
+ * instances for multiple use.</p>
  *
- * <p>A {@link Schema} will be cached until its {@link SourceValidity} expires.</p>
+ * <p>A {@link org.apache.cocoon.components.validation.Schema} will be cached until its
+ * {@link org.apache.excalibur.source.SourceValidity} expires.</p>
  *
+ * @version $Id$
  */
-public abstract class AbstractSchemaParser
-implements LogEnabled, Serviceable, Initializable, Disposable, SchemaParser {
+public abstract class AbstractSchemaParser extends AbstractLogEnabled
+                implements Serviceable, Initializable, Disposable, SchemaParser {
 
     /** <p>The {@link ServiceManager} configured for this instance.</p> */
-    protected ServiceManager serviceManager = null;
-    /** <p>The {@link SourceResolver} to resolve URIs into {@link Source}s.</p> */
-    protected SourceResolver sourceResolver = null;
+    protected ServiceManager serviceManager;
+
+    /** <p>The {@link SourceResolver} to resolve URIs into {@link org.apache.excalibur.source.Source}s.</p> */
+    protected SourceResolver sourceResolver;
+
     /** <p>The {@link EntityResolver} resolving against catalogs of public IDs.</p> */
-    protected EntityResolver entityResolver = null;
-    /** <p>The {@link Logger} configured for this instance.</p> */
-    protected Logger logger = null;
+    protected EntityResolver entityResolver;
+
 
     /**
      * <p>Create a new {@link AbstractSchemaParser} instance.</p>
      */
     public AbstractSchemaParser() {
         super();
-    }
-
-    /**
-     * <p>Enable logging.</p>
-     */
-    public void enableLogging(Logger logger) {
-        this.logger = logger;
     }
 
     /**

Modified: cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/AbstractValidator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/AbstractValidator.java?rev=586214&r1=586213&r2=586214&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/AbstractValidator.java (original)
+++ cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/AbstractValidator.java Thu Oct 18 18:45:47 2007
@@ -19,21 +19,22 @@
 import java.io.IOException;
 
 import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.logger.LogEnabled;
-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;
-import org.apache.cocoon.components.validation.Schema;
-import org.apache.cocoon.components.validation.SchemaParser;
-import org.apache.cocoon.components.validation.ValidationHandler;
-import org.apache.cocoon.components.validation.Validator;
-import org.apache.cocoon.components.validation.ValidatorException;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.excalibur.xml.sax.NOPContentHandler;
 import org.apache.excalibur.xml.sax.SAXParser;
 import org.apache.excalibur.xml.sax.XMLizable;
+
+import org.apache.cocoon.components.validation.Schema;
+import org.apache.cocoon.components.validation.SchemaParser;
+import org.apache.cocoon.components.validation.ValidationHandler;
+import org.apache.cocoon.components.validation.Validator;
+import org.apache.cocoon.components.validation.ValidatorException;
+import org.apache.cocoon.util.AbstractLogEnabled;
+
 import org.xml.sax.Attributes;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
@@ -55,16 +56,17 @@
  * can be overridden by reimplementing the {@link #detectGrammar(Source)} method
  * provided by this class.</p>
  *
+ * @version $Id$
  */
-public abstract class AbstractValidator
-implements Validator, Serviceable, Disposable, LogEnabled {
+public abstract class AbstractValidator extends AbstractLogEnabled
+                                        implements Validator, Serviceable, Disposable {
 
     /** <p>The configured {@link ServiceManager} instance.</p> */
-    protected ServiceManager manager = null;
+    protected ServiceManager manager;
+
     /** <p>The configured {@link SourceResolver} instance.</p> */
-    protected SourceResolver resolver = null;
-    /** <p>The configured {@link Logger} instance.</p> */
-    protected Logger logger = null;
+    protected SourceResolver resolver;
+
 
     /**
      * <p>Create a new {@link AbstractValidator} instance.</p>
@@ -74,13 +76,6 @@
     }
 
     /**
-     * <p>Enable logging.</p>
-     */
-    public void enableLogging(Logger logger) {
-        this.logger = logger;
-    }
-
-    /**
      * <p>Specify the {@link ServiceManager} available to this instance.</p>
      */
     public void service(ServiceManager manager)
@@ -400,8 +395,8 @@
      */
     protected Schema getSchema(SchemaParser parser, Source source, String grammar)
     throws IOException, SAXException {
-        if (this.logger.isDebugEnabled()) {
-            this.logger.debug("Parsing schema \"" + source.getURI() + "\" using " +
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Parsing schema \"" + source.getURI() + "\" using " +
                               "grammar \"" + grammar + "\" and SourceParser " +
                               parser.getClass().getName());
         }
@@ -426,8 +421,8 @@
      */
     protected String detectGrammar(Source source)
     throws IOException, SAXException, ValidatorException {
-        if (this.logger.isDebugEnabled()) {
-            this.logger.debug("Detecting grammar for \"" + source.getURI() + "\"");
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Detecting grammar for \"" + source.getURI() + "\"");
         }
 
         SAXParser xmlParser = null;
@@ -457,8 +452,8 @@
             String message = "Unable to detect grammar for schema at ";
             throw new ValidatorException(message + source.getURI());
         } else {
-            if (this.logger.isDebugEnabled()) {
-                this.logger.debug("Grammar \"" + grammar + "\" detected for " +
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Grammar \"" + grammar + "\" detected for " +
                                   "schema \"" + source.getURI());
             }
             return grammar;

Modified: cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/CachingValidator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/CachingValidator.java?rev=586214&r1=586213&r2=586214&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/CachingValidator.java (original)
+++ cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/CachingValidator.java Thu Oct 18 18:45:47 2007
@@ -37,7 +37,7 @@
 public class CachingValidator extends DefaultValidator {
 
     /** <p>The {@link Store} used for caching {@link Schema}s (if enabled).</p> */
-    private Store store = null;
+    private Store store;
 
     /**
      * <p>Create a new {@link CachingValidator} instance.</p>
@@ -62,7 +62,9 @@
         try {
             super.dispose();
         } finally {
-            if (this.store != null) this.manager.release(this.store);
+            if (this.store != null) {
+                this.manager.release(this.store);
+            }
         }
     }
 
@@ -94,8 +96,8 @@
         String uri = source.getURI();
         String key = this.getClass().getName() + "[" + parser.getClass().getName()
                      + ":" + grammar + "]@" + source.getURI();
-        Schema schema = null;
-        SourceValidity validity = null;
+        Schema schema;
+        SourceValidity validity;
         schema = (Schema) this.store.get(key);
 
         /* If the schema was found verify its validity and optionally clear */
@@ -103,20 +105,20 @@
             validity = schema.getValidity();
             if (validity == null) {
                 /* Why did we cache it in the first place? */
-                this.logger.warn("Cached schema " + uri + " has null validity");
+                getLogger().warn("Cached schema " + uri + " has null validity");
                 this.store.remove(key);
                 schema = null;
             } else if (validity.isValid() != SourceValidity.VALID) {
-                if (this.logger.isDebugEnabled()) {
-                    this.logger.debug("Cached schema " + uri + " no longer valid");
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Cached schema " + uri + " no longer valid");
                 }
                 this.store.remove(key);
                 schema = null;
-            } else if (this.logger.isDebugEnabled()) {
-                this.logger.debug("Valid cached schema found for " + uri);
+            } else if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Valid cached schema found for " + uri);
             }
-        } else if (this.logger.isDebugEnabled()) {
-            this.logger.debug("Schema " + uri + " not found in cache");
+        } else if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Schema " + uri + " not found in cache");
         }
 
         /* If the schema was not cached or was cleared, parse and cache it */
@@ -152,24 +154,24 @@
         String uri = source.getURI();
         String key = this.getClass().getName() + "@" + source.getURI();
 
-        CachedGrammar grammar = null;
+        CachedGrammar grammar;
         grammar = (CachedGrammar) this.store.get(key);
 
         /* If the schema was found verify its validity and optionally clear */
         if (grammar != null) {
             if (grammar.validity == null) {
                 /* Why did we cache it in the first place? */
-                this.logger.warn("Grammar for " + uri + " has null validity");
+                getLogger().warn("Grammar for " + uri + " has null validity");
                 this.store.remove(key);
                 grammar = null;
             } else if (grammar.validity.isValid() != SourceValidity.VALID) {
-                if (this.logger.isDebugEnabled()) {
-                    this.logger.debug("Grammar for " + uri + " no longer valid");
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Grammar for " + uri + " no longer valid");
                 }
                 this.store.remove(key);
                 grammar = null;
-            } else if (this.logger.isDebugEnabled()) {
-                this.logger.debug("Valid cached grammar " + grammar + " for " + uri);
+            } else if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Valid cached grammar " + grammar + " for " + uri);
             }
         }
 
@@ -195,6 +197,7 @@
     private static final class CachedGrammar {
         private final SourceValidity validity;
         private final String grammar;
+
         private CachedGrammar(SourceValidity validity, String grammar) {
             this.validity = validity;
             this.grammar = grammar;

Modified: cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java?rev=586214&r1=586213&r2=586214&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java (original)
+++ cocoon/trunk/blocks/cocoon-validation/cocoon-validation-impl/src/main/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java Thu Oct 18 18:45:47 2007
@@ -31,18 +31,19 @@
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.logger.LogEnabled;
-import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.parameters.Parameterizable;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.avalon.framework.thread.ThreadSafe;
+
 import org.apache.cocoon.components.validation.SchemaParser;
+import org.apache.cocoon.util.avalon.CLLoggerWrapper;
 
 /**
- * <p>The default implementation of the {@link Validator} interface provides
- * core management for a number of {@link SchemaParser} instances.</p>
+ * <p>The default implementation of the {@link org.apache.cocoon.components.validation.Validator}
+ * interface provides core management for a number of {@link SchemaParser} instances.</p>
  * 
  * <p>Given the simplicity of this implementation, only {@link SchemaParser}s
  * implementing the {@link ThreadSafe} interface can be managed, and they can be
@@ -52,9 +53,11 @@
  * <p>That said, normally selection would occur using the methods declared by the
  * {@link AbstractValidator} class and implemented here.</p>
  *
+ * @version $Id$
  */
-public class DefaultValidator extends AbstractValidator implements ServiceSelector,
-ThreadSafe, Contextualizable, Initializable, Disposable, Configurable {
+public class DefaultValidator extends AbstractValidator
+                              implements ServiceSelector, ThreadSafe, Contextualizable,
+                                         Initializable, Disposable, Configurable {
 
     /** <p>A {@link Map} associating {@link SchemaParser}s with their names.</p> */
     private final Map components = Collections.synchronizedMap(new HashMap());
@@ -62,9 +65,11 @@
     private final Map grammars = Collections.synchronizedMap(new HashMap());
 
     /** <p>The configured {@link Context} instance.</p> */
-    private Context context = null;
+    private Context context;
+
     /** <p>The configured {@link Configuration} instance.</p> */
-    private Configuration conf = null;
+    private Configuration conf;
+
 
     /**
      * <p>Create a new {@link DefaultValidator} instance.</p>
@@ -94,15 +99,14 @@
      */
     public void initialize()
     throws Exception {
-        this.logger.debug("Initializing " + this.getClass().getName());
+        getLogger().debug("Initializing " + this.getClass().getName());
 
-        if (this.logger == null) throw new IllegalStateException("Null logger");
         if (this.context == null) throw new IllegalStateException("Null context");
         if (this.manager == null) throw new IllegalStateException("Null manager");
         if (this.conf == null) throw new IllegalStateException("Null configuration");
 
         Configuration configurations[] = this.conf.getChildren("schema-parser");
-        this.logger.debug("Configuring " + configurations.length + " schema parsers"
+        getLogger().debug("Configuring " + configurations.length + " schema parsers"
                           + " from " + this.conf.getLocation());
 
         /* Iterate through all the sub-confiuration instances */
@@ -118,7 +122,7 @@
             }
 
             /* Dump some debugging information, just in case */
-            this.logger.debug("Configuring schema parser " + selectionKey + " as "
+            getLogger().debug("Configuring schema parser " + selectionKey + " as "
                               + className + " from " + configuration.getLocation());
 
             /* Try to load and instantiate the SchemaParser */
@@ -143,7 +147,7 @@
 
                 /* Instantiate and set up the new SchemaParser */
                 schemaParser = (SchemaParser) clazz.newInstance();
-                this.setupComponent(selectionKey, schemaParser, configuration);
+                setupComponent(selectionKey, schemaParser, configuration);
 
             } catch (ConfigurationException exception) {
                 throw exception;
@@ -154,7 +158,7 @@
 
             /* Store this instance (and report about it) */
             this.components.put(selectionKey, schemaParser);
-            this.logger.debug("SchemaParser \"" + selectionKey + "\" instantiated" +
+            getLogger().debug("SchemaParser \"" + selectionKey + "\" instantiated" +
                               " from class " + className);
 
             /* Analyze the grammars provided by the current SchemaParser */
@@ -164,8 +168,8 @@
             /* Iterate through the grammars and store them (default lookup) */
             for (int k = 0; k < grammars.length; k++) {
                 if (this.grammars.containsKey(grammars[k])) {
-                    if (this.logger.isDebugEnabled()) {
-                        this.logger.debug("SchemaParser \"" + selectionKey + "\" " +
+                    if (getLogger().isDebugEnabled()) {
+                        getLogger().debug("SchemaParser \"" + selectionKey + "\" " +
                                           "supports grammar \"" + grammars[k] +
                                           "\" but is not the default provider");
                     }
@@ -174,8 +178,8 @@
 
                 /* Noone yet supports this grammar, make this the default */
                 this.grammars.put(grammars[k], selectionKey);
-                if (this.logger.isDebugEnabled()) {
-                    this.logger.debug("SchemaParser \"" + selectionKey + "\" is the "
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("SchemaParser \"" + selectionKey + "\" is the "
                                       + "default grammar provider for "+grammars[k]);
                 }
             }
@@ -183,14 +187,14 @@
         } catch (Exception exception) {
             /* Darn, we had an exception instantiating one of the components */
             exception.printStackTrace();
-            this.logger.fatalError("Exception creating schema parsers", exception);
+            getLogger().fatal("Exception creating schema parsers", exception);
 
             /* Dispose all previously stored component instances */
             Iterator iterator = this.components.values().iterator();
             while (iterator.hasNext()) try {
                 this.decommissionComponent(iterator.next());
             } catch (Exception nested) {
-                this.logger.fatalError("Error decommissioning component", nested);
+                getLogger().fatal("Error decommissioning component", nested);
             }
 
             /* Depending on the exception type, re-throw it or wrap it */
@@ -216,7 +220,7 @@
         while (iterator.hasNext()) try {
             this.decommissionComponent(iterator.next());
         } catch (Exception exception) {
-            this.logger.fatalError("Error decommissioning component", exception);
+            getLogger().fatal("Error decommissioning component", exception);
         }
     }
 
@@ -261,7 +265,8 @@
      * original component manager.</p>
      * 
      * <p>This method is supplied in case solid implementations of this class relied
-     * on the {@link ServiceManager} to manage {@link SchemaParser}s instances.</p>
+     * on the {@link org.apache.avalon.framework.service.ServiceManager} to manage
+     * {@link SchemaParser}s instances.</p>
      * 
      * @param parser the {@link SchemaParser} whose instance is to be released.
      */
@@ -319,9 +324,9 @@
         boolean started = false;
 
         try {
+            // All SchemaParsers are now using commons logging. This is legacy support code.
             if (component instanceof LogEnabled) {
-                Logger logger = this.logger.getChildLogger(name);
-                ((LogEnabled) component).enableLogging(logger);
+                ((LogEnabled) component).enableLogging(new CLLoggerWrapper(getLogger()));
             }
     
             if (component instanceof Contextualizable) {
@@ -357,12 +362,12 @@
             if ((started) && (component instanceof Startable)) try {
                 ((Startable) component).stop();
             } catch (Exception nested) {
-                this.logger.fatalError("Error stopping component", nested);
+                getLogger().fatal("Error stopping component", nested);
             }
             if ((initialized) && (component instanceof Disposable)) try {
                 ((Disposable) component).dispose();
             } catch (Exception nested) {
-                this.logger.fatalError("Error disposing component", nested);
+                getLogger().fatal("Error disposing component", nested);
             }
             throw exception;
         }