Author: sylvain
Date: Sat Mar 12 14:42:07 2005
New Revision: 157288

URL: http://svn.apache.org/viewcvs?view=rev&rev=157288
Log:
Refactor deprecation to automatically throw DeprecationException depending on a 
chosen limit

Added:
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/Deprecation.java
      - copied, changed from r157059, 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/DeprecationLogger.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/DeprecationException.java
   (with props)
    
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/test/DeprecationTestCase.java
   (with props)
Removed:
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/DeprecationLogger.java
Modified:
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinitionBuilder.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinitionBuilder.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinitionBuilder.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/StructDefinitionBuilder.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/FormsPipelineConfig.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailCommandSelector.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/generation/XMLDBGenerator.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/Cocoon.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java
    
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
    cocoon/branches/BRANCH_2_1_X/src/webapp/WEB-INF/web.xml
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java
 Sat Mar 12 14:42:07 2005
@@ -16,7 +16,7 @@
 package org.apache.cocoon.forms.binding;
 
 import org.apache.cocoon.forms.util.DomHelper;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 import org.w3c.dom.Element;
 
 /**
@@ -38,7 +38,7 @@
 
     public JXPathBindingBase buildBinding(Element bindingElm, 
JXPathBindingManager.Assistant assistant)
             throws BindingException {
-        DeprecationLogger.log("'fb:struct' is deprecated and replaced by 
'fb:group' at " + DomHelper.getLocation(bindingElm));
+        Deprecation.logger.info("'fb:struct' is deprecated and replaced by 
'fb:group' at " + DomHelper.getLocation(bindingElm));
         try {
             String widgetId = DomHelper.getAttribute(bindingElm, "id");
             CommonAttributes commonAtts = 
JXPathBindingBuilderBase.getCommonAttributes(bindingElm);

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinitionBuilder.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinitionBuilder.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinitionBuilder.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ActionDefinitionBuilder.java
 Sat Mar 12 14:42:07 2005
@@ -19,7 +19,7 @@
 
 import org.apache.cocoon.forms.event.ActionListener;
 import org.apache.cocoon.forms.util.DomHelper;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 import org.w3c.dom.Element;
 
 /**
@@ -48,7 +48,7 @@
         if (actionCommand == null) {
             actionCommand = DomHelper.getAttribute(widgetElement, 
"action-command", null);
             if (actionCommand != null) {
-                DeprecationLogger.log("The 'action-command' attribute is 
deprecated and replaced by 'command', at " +
+                Deprecation.logger.warn("The 'action-command' attribute is 
deprecated and replaced by 'command', at " +
                     DomHelper.getLocation(widgetElement));
             }
         }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinitionBuilder.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinitionBuilder.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinitionBuilder.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinitionBuilder.java
 Sat Mar 12 14:42:07 2005
@@ -20,7 +20,7 @@
 import org.apache.cocoon.forms.Constants;
 import org.apache.cocoon.forms.event.ActionListener;
 import org.apache.cocoon.forms.util.DomHelper;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 import org.w3c.dom.Element;
 
 /**
@@ -62,7 +62,7 @@
         if (actionCommand == null) {
             actionCommand = DomHelper.getAttribute(widgetElement, 
"action-command", null);
             if (actionCommand != null) {
-                DeprecationLogger.log("The 'action-command' attribute is 
deprecated and replaced by 'command', at " +
+                Deprecation.logger.warn("The 'action-command' attribute is 
deprecated and replaced by 'command', at " +
                     DomHelper.getLocation(widgetElement));
             }
         }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinitionBuilder.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinitionBuilder.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinitionBuilder.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RowActionDefinitionBuilder.java
 Sat Mar 12 14:42:07 2005
@@ -20,7 +20,7 @@
 import org.apache.cocoon.forms.Constants;
 import org.apache.cocoon.forms.event.ActionListener;
 import org.apache.cocoon.forms.util.DomHelper;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 import org.w3c.dom.Element;
 
 /**
@@ -39,7 +39,7 @@
         if (actionCommand == null) {
             actionCommand = DomHelper.getAttribute(widgetElement, 
"action-command", null);
             if (actionCommand != null) {
-                DeprecationLogger.log("The 'action-command' attribute is 
deprecated and replaced by 'command', at " +
+                Deprecation.logger.warn("The 'action-command' attribute is 
deprecated and replaced by 'command', at " +
                     DomHelper.getLocation(widgetElement));
             }
         }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/StructDefinitionBuilder.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/StructDefinitionBuilder.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/StructDefinitionBuilder.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/StructDefinitionBuilder.java
 Sat Mar 12 14:42:07 2005
@@ -18,7 +18,7 @@
 import org.w3c.dom.Element;
 import org.apache.cocoon.forms.Constants;
 import org.apache.cocoon.forms.util.DomHelper;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 
 /**
  * Builds {StructDefinition}s.
@@ -43,7 +43,7 @@
         }
 
         definition.makeImmutable();
-        DeprecationLogger.log("Use of 'fd:struct' is deprecated. Use 
'fd:group' instead, at " + definition.getLocation());
+        Deprecation.logger.info("Use of 'fd:struct' is deprecated. Use 
'fd:group' instead, at " + definition.getLocation());
         return definition;
     }
 }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/FormsPipelineConfig.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/FormsPipelineConfig.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/FormsPipelineConfig.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/FormsPipelineConfig.java
 Sat Mar 12 14:42:07 2005
@@ -31,7 +31,7 @@
 import org.apache.cocoon.environment.Session;
 import org.apache.cocoon.forms.formmodel.Form;
 import org.apache.cocoon.i18n.I18nUtils;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 import org.apache.cocoon.xml.AttributesImpl;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.JXPathException;
@@ -353,7 +353,7 @@
         public Object getVariable(String name) {
             Object value = this.vars.get(name);
             if ( deprecatedNames.contains(name) ) {
-                DeprecationLogger.log("CForms: usage of the variable '" + name 
+ "' is deprecated."+ 
+                Deprecation.logger.warn("CForms: usage of the variable '" + 
name + "' is deprecated."+ 
                                       "Please use 'cocoon/" + name + "' 
instead. The usage of just '"+
                                       name+"' will be removed in Cocoon 2.2.");
             }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailCommandSelector.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailCommandSelector.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailCommandSelector.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailCommandSelector.java
 Sat Mar 12 14:42:07 2005
@@ -17,7 +17,7 @@
 
 import java.util.Map;
 import org.apache.cocoon.selection.AbstractSwitchSelector;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.ObjectModelHelper;
@@ -91,7 +91,7 @@
     }
 
     public boolean select(String expression, Object selectorContext) {
-        DeprecationLogger.log("The MailCommandSelector is deprecated."
+        Deprecation.logger.warn("The MailCommandSelector is deprecated."
                  + " Use RequestAttributeSelector, RequestParameterSelector, 
or ParameterSelector instead.");
         if (selectorContext == null) {
             return false;

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
 Sat Mar 12 14:42:07 2005
@@ -25,7 +25,7 @@
 import org.apache.cocoon.ResourceNotFoundException;
 import org.apache.cocoon.caching.CacheableProcessingComponent;
 import org.apache.cocoon.environment.SourceResolver;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 
 import org.apache.excalibur.source.SourceValidity;
 import org.xml.sax.SAXException;
@@ -136,7 +136,7 @@
                       String src,
                       Parameters par)
     throws ProcessingException, SAXException,IOException {
-        DeprecationLogger.log("The XMLDBCollectionGenerator is deprecated. Use 
the XML:DB pseudo protocol instead");
+        Deprecation.logger.warn("The XMLDBCollectionGenerator is deprecated. 
Use the XML:DB pseudo protocol instead");
         super.setup(resolver, objectModel, src, par);
     }
 

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/generation/XMLDBGenerator.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/generation/XMLDBGenerator.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/generation/XMLDBGenerator.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/generation/XMLDBGenerator.java
 Sat Mar 12 14:42:07 2005
@@ -25,7 +25,7 @@
 import org.apache.cocoon.ResourceNotFoundException;
 import org.apache.cocoon.caching.CacheableProcessingComponent;
 import org.apache.cocoon.environment.SourceResolver;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 
 import org.apache.excalibur.source.SourceValidity;
 import org.xml.sax.SAXException;
@@ -129,7 +129,7 @@
                       String src,
                       Parameters par)
     throws ProcessingException, SAXException,IOException {
-        DeprecationLogger.log("The XMLDBGenerator is deprecated. Use the 
XML:DB pseudo protocol instead");
+        Deprecation.logger.warn("The XMLDBGenerator is deprecated. Use the 
XML:DB pseudo protocol instead");
         super.setup(resolver, objectModel, src, par);
     }
 

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/Cocoon.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/Cocoon.java?view=diff&r1=157287&r2=157288
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/Cocoon.java 
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/Cocoon.java Sat Mar 
12 14:42:07 2005
@@ -57,7 +57,7 @@
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.Session;
 import org.apache.cocoon.util.ClassUtils;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 import org.apache.commons.lang.SystemUtils;
 
 import org.apache.excalibur.instrument.InstrumentManageable;
@@ -195,7 +195,7 @@
      */
     public void setLoggerManager(LoggerManager loggerManager) {
         this.loggerManager = loggerManager;
-        DeprecationLogger.logger = 
this.loggerManager.getLoggerForCategory("deprecation");
+        
Deprecation.setLogger(this.loggerManager.getLoggerForCategory("deprecation"));
     }
 
     /**

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
 Sat Mar 12 14:42:07 2005
@@ -46,7 +46,7 @@
 import org.apache.cocoon.environment.Response;
 import org.apache.cocoon.environment.Session;
 import org.apache.cocoon.util.ClassUtils;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 import org.mozilla.javascript.JavaScriptException;
 import org.mozilla.javascript.NativeJavaClass;
 import org.mozilla.javascript.NativeJavaObject;

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
 Sat Mar 12 14:42:07 2005
@@ -34,7 +34,7 @@
 import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.cocoon.util.BufferedOutputStream;
 import org.apache.cocoon.util.ClassUtils;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 import org.apache.commons.collections.iterators.IteratorEnumeration;
 import org.apache.excalibur.source.SourceException;
 import org.xml.sax.SAXException;
@@ -370,7 +370,7 @@
      */
     public Source resolve(String systemId)
     throws ProcessingException, SAXException, IOException {
-        DeprecationLogger.log("The resolve(String) method of the 
SourceResolver is "
+        Deprecation.logger.warn("The method SourceResolver.resolve(String) is "
                               + "deprecated. Use resolveURI(String) instead.");
         if (!this.initializedComponents) {
             initComponents();
@@ -468,7 +468,7 @@
      * @deprecated Use [EMAIL PROTECTED] #getOutputStream(int)} instead.
      */
     public OutputStream getOutputStream() throws IOException {
-        DeprecationLogger.log("The getOutputStream() method of the Environment 
" +
+        Deprecation.logger.warn("The method Environment.getOutputStream() " +
                               "is deprecated. Use getOutputStream(-1) 
instead.");
         // by default we use the complete buffering output stream
         return this.getOutputStream(-1);

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
 Sat Mar 12 14:42:07 2005
@@ -31,7 +31,7 @@
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.Response;
 import org.apache.cocoon.util.BufferedOutputStream;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 
 
 /**
@@ -298,7 +298,7 @@
      */
     public OutputStream getOutputStream()
     throws IOException {
-        DeprecationLogger.log("The getOutputStream() method of the Environment 
" +
+        Deprecation.logger.warn("The method Environment.getOutputStream() " +
         "is deprecated. Use getOutputStream(-1) instead.");
         return this.outputStream == null
             ? this.environment.getOutputStream()

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java
 Sat Mar 12 14:42:07 2005
@@ -44,6 +44,7 @@
 import org.apache.cocoon.servlet.multipart.MultipartHttpServletRequest;
 import org.apache.cocoon.servlet.multipart.RequestFactory;
 import org.apache.cocoon.util.ClassUtils;
+import org.apache.cocoon.util.Deprecation;
 import org.apache.cocoon.util.IOUtils;
 import org.apache.cocoon.util.StringUtils;
 import org.apache.cocoon.util.log.CocoonLogFormatter;
@@ -848,6 +849,9 @@
         }
 
         this.log = this.loggerManager.getLoggerForCategory(accesslogger);
+        
+        final String deprecationLevel = 
getInitParameter("forbidden-deprecation-level", "ERROR");
+        
Deprecation.setForbiddenLevel(Deprecation.LogLevel.getLevel(deprecationLevel));
     }
 
     private LoggerManager newLoggerManager(String loggerManagerClass, 
Hierarchy hierarchy) {

Copied: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/Deprecation.java 
(from r157059, 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/DeprecationLogger.java)
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/Deprecation.java?view=diff&rev=157288&p1=cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/DeprecationLogger.java&r1=157059&p2=cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/Deprecation.java&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/DeprecationLogger.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/Deprecation.java 
Sat Mar 12 14:42:07 2005
@@ -13,26 +13,164 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.cocoon.util.log;
+package org.apache.cocoon.util;
 
+import org.apache.avalon.framework.logger.ConsoleLogger;
 import org.apache.avalon.framework.logger.Logger;
+import org.apache.commons.lang.enums.ValuedEnum;
 
 /**
- * This class provides static accessors for a special "deprecation" logger.
- * All deprecated code should use this logger to log warnings into the 
- * deprecation log. This makes it easier for users to find out if they're 
+ * This class provides a special static "deprecation" logger.
+ * All deprecated code should use this logger to log messages into the 
+ * deprecation logger. This makes it easier for users to find out if they're 
  * using deprecated stuff.
+ * <p>
+ * Additionally, it is possible to set the forbidden level of deprecation 
messages (default
+ * is to forbid ERROR, i.e. allow up to WARN). Messages equal to or above the 
forbidden level
+ * will lead to throwing a [EMAIL PROTECTED] DeprecationException}. Setting 
the forbidden level to
+ * FATAL_ERROR allows running legacy applications using deprecated features 
(tolerant mode), and
+ * setting the forbidden level to DEBUG will run in strict mode, forbidding 
all deprecations.
+ * <p>
+ * Note that according to the above, issuing a fatalError log always raises an 
exception, and
+ * can therefore be used when detecting old features that have been totally 
removed.
  *
  * @version $Id$
  */
-public class DeprecationLogger {
-
-    /** This is the logger used to log the warn messages.
-     *  THIS IS AN INTERNAL FIELD, DON'T USE IT DIRECTLY.
+public class Deprecation {
+    
+    /**
+     * The deprecation logger.
      */
-    public static Logger logger;
+    public static final Logger logger = new LoggerWrapper(new ConsoleLogger());
+    
+    private static final int DEBUG_VALUE = 0;
+    private static final int INFO_VALUE = 1;
+    private static final int WARN_VALUE = 2;
+    private static final int ERROR_VALUE = 3;
+    private static final int FATAL_VALUE = 3;
+    private static final int FATAL_ERROR_VALUE = 4;
+    
+    public static final LogLevel DEBUG = new LogLevel("DEBUG", DEBUG_VALUE);
+    public static final LogLevel INFO = new LogLevel("INFO", INFO_VALUE);
+    public static final LogLevel WARN = new LogLevel("WARN", WARN_VALUE);
+    public static final LogLevel ERROR = new LogLevel("ERROR", ERROR_VALUE);
+    public static final LogLevel FATAL_ERROR = new LogLevel("FATAL_ERROR", 
FATAL_ERROR_VALUE);
     
-    public static void log(String message) {
-        logger.warn(message);
+    public static final class LogLevel extends ValuedEnum {
+        private LogLevel(String text, int value) {
+            super(text, value);
+        }
+        
+        public static LogLevel getLevel(String level) {
+            return (LogLevel)ValuedEnum.getEnum(LogLevel.class, level);
+        }
+    }
+
+    public static void setLogger(Logger newLogger) {
+        // Note: the "logger" attribute is not of type LoggerWrapper so that 
it appears
+        // as a standard Logger in the javadocs.
+        ((LoggerWrapper)logger).setLogger(newLogger);
+    }
+    
+    public static void setForbiddenLevel(LogLevel level) {
+        ((LoggerWrapper)logger).setForbiddenLevel(level);
+    }
+    
+    /**
+     * Wraps a logger, and throws an DeprecatedException if the message level 
is
+     * higher than the allowed one.
+     */
+    private static class LoggerWrapper implements Logger {
+        
+        private Logger realLogger;
+        // up to warn is allowed
+        private int forbiddenLevel = ERROR_VALUE;
+        
+        public LoggerWrapper(Logger logger) {
+            this.realLogger = logger;
+        }
+        
+        public void setLogger(Logger logger) {
+            // Unwrap a wrapped logger
+            while(logger instanceof LoggerWrapper) {
+                logger = ((LoggerWrapper)logger).realLogger;
+            }
+            this.realLogger = logger;
+        }
+        
+        public void setForbiddenLevel(LogLevel level) {
+            this.forbiddenLevel = level.getValue();
+        }
+        
+        private void throwException(int level, String message) {
+            if (level >= this.forbiddenLevel) {
+                throw new DeprecationException(message);
+            }
+        }
+        
+        private boolean isThrowingException(int level) {
+            return level >= this.forbiddenLevel;
+        }
+        
+        public void debug(String message) {
+            realLogger.debug(message);
+            throwException(DEBUG_VALUE, message);
+        }
+        public void debug(String message, Throwable thr) {
+            realLogger.debug(message, thr);
+            throwException(DEBUG_VALUE, message);
+        }
+        public void info(String message) {
+            realLogger.info(message);
+            throwException(INFO_VALUE, message);
+        }
+        public void info(String message, Throwable thr) {
+            realLogger.info(message, thr);
+            throwException(INFO_VALUE, message);
+        }
+        public void warn(String message) {
+            realLogger.warn(message);
+            throwException(WARN_VALUE, message);
+        }
+        public void warn(String message, Throwable thr) {
+            realLogger.warn(message, thr);
+            throwException(WARN_VALUE, message);
+        }
+        public void error(String message) {
+            realLogger.error(message);
+            throwException(ERROR_VALUE, message);
+        }
+        public void error(String message, Throwable thr) {
+            realLogger.error(message, thr);
+            throwException(ERROR_VALUE, message);
+        }
+        public void fatalError(String message) {
+            realLogger.fatalError(message);
+            throwException(FATAL_VALUE, message);
+        }
+        public void fatalError(String message, Throwable thr) {
+            realLogger.fatalError(message, thr);
+            throwException(FATAL_VALUE, message);
+        }
+        public boolean isDebugEnabled() {
+            // Enable level also if it is set to throw an exception, so that
+            // logging the message occurs, and then throws it.
+            return isThrowingException(DEBUG_VALUE) || 
realLogger.isDebugEnabled();
+        }
+        public boolean isInfoEnabled() {
+            return isThrowingException(INFO_VALUE) || 
realLogger.isInfoEnabled();
+        }
+        public boolean isWarnEnabled() {
+            return isThrowingException(WARN_VALUE) || 
realLogger.isWarnEnabled();
+        }
+        public boolean isErrorEnabled() {
+            return isThrowingException(ERROR_VALUE) || 
realLogger.isErrorEnabled();
+        }
+        public boolean isFatalErrorEnabled() {
+            return true;
+        }
+        public Logger getChildLogger(String message) {
+            return realLogger.getChildLogger(message);
+        }
     }
 }

Added: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/DeprecationException.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/DeprecationException.java?view=auto&rev=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/DeprecationException.java
 (added)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/DeprecationException.java
 Sat Mar 12 14:42:07 2005
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2005 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.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.util;
+
+
+/**
+ * An exception that indicates unauthorized use of a deprecated feature, or an
+ * attempt to use a old feature that has been removed.
+ * 
+ * @version $Id$
+ */
+public class DeprecationException extends RuntimeException {
+    public DeprecationException(String message) {
+        super(message);
+    }
+}

Propchange: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/DeprecationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/DeprecationException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: 
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/core/container/ContainerTestCase.java?view=diff&r1=157287&r2=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
 Sat Mar 12 14:42:07 2005
@@ -34,7 +34,7 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.WrapperServiceManager;
-import org.apache.cocoon.util.log.DeprecationLogger;
+import org.apache.cocoon.util.Deprecation;
 
 /**
  * JUnit TestCase for Cocoon Components.
@@ -142,7 +142,7 @@
 
         String level = System.getProperty("junit.test.loglevel", "" + 
ConsoleLogger.LEVEL_WARN);
         this.logger = new ConsoleLogger(Integer.parseInt(level));
-        DeprecationLogger.logger = this.logger;
+        Deprecation.setLogger(this.logger);
         prepare();
     }
 

Added: 
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/test/DeprecationTestCase.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/test/DeprecationTestCase.java?view=auto&rev=157288
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/test/DeprecationTestCase.java
 (added)
+++ 
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/test/DeprecationTestCase.java
 Sat Mar 12 14:42:07 2005
@@ -0,0 +1,108 @@
+/*
+ * Copyright 1999-2004 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.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.util.test;
+
+import junit.framework.TestCase;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.util.Deprecation;
+import org.apache.cocoon.util.DeprecationException;
+
+/**
+ * Test Cases for the Deprecation class.
+ * @see org.apache.cocoon.util.Deprecation
+ *
+ * @version $Id$
+ */
+public class DeprecationTestCase extends TestCase {
+    public DeprecationTestCase(String name) {
+        super(name);
+    }
+    
+    private Logger originalLogger;
+    private Logger consoleLogger;
+    
+    public void setUp() throws Exception {
+        super.setUp();
+        originalLogger = Deprecation.logger;
+        // Setup a disabled logger: avoids polluting the test output, and also 
test
+        // that isXXXEnabled also matches the forbidden deprecation level
+        consoleLogger = new ConsoleLogger(ConsoleLogger.LEVEL_DISABLED);
+        Deprecation.setLogger(consoleLogger);
+        Deprecation.setForbiddenLevel(Deprecation.ERROR);
+    }
+    
+    public void tearDown() throws Exception {
+        Deprecation.setLogger(originalLogger);
+        super.tearDown();
+    }
+    
+    public void testPrecond() {
+        // Double check that our logger won't let anything go through, and that
+        // enabled levels are because of the allowed level we've set.
+        assertFalse(consoleLogger.isInfoEnabled());
+        assertFalse(consoleLogger.isWarnEnabled());
+        assertFalse(consoleLogger.isErrorEnabled());
+    }
+    
+    public void testInfoOk() {
+        try {
+            Deprecation.logger.info("testing deprecation logs");
+        } catch(DeprecationException de) {
+            fail("Should not throw an exception");
+        }
+    }
+
+    public void testWarnOk() {        
+        try {
+            Deprecation.logger.warn("testing deprecation logs");
+        } catch(DeprecationException de) {
+            fail("Should not throw an exception");
+        }
+    }
+    
+    public void testErrorFails() {
+        try {
+            Deprecation.logger.error("testing deprecation logs");
+        } catch(DeprecationException de) {
+            return; // success
+        }
+        fail("Should throw an exception");
+    }
+    
+    public void testDebugFails() {
+        Deprecation.setForbiddenLevel(Deprecation.DEBUG);
+        try {
+            Deprecation.logger.debug("testing deprecation logs");
+        } catch(DeprecationException de) {
+            return; // success
+        }
+        fail("Should throw an exception");
+    }
+
+    public void testInfoDisabled() {
+        assertFalse(Deprecation.logger.isInfoEnabled());
+    }
+
+    public void testWarnDisabled() {
+        assertFalse(Deprecation.logger.isWarnEnabled());
+    }
+
+    public void testErrorEnabled() {
+        assertTrue(Deprecation.logger.isErrorEnabled());
+    }
+}

Propchange: 
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/test/DeprecationTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/test/DeprecationTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/branches/BRANCH_2_1_X/src/webapp/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/WEB-INF/web.xml?view=diff&r1=157287&r2=157288
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/webapp/WEB-INF/web.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/webapp/WEB-INF/web.xml Sat Mar 12 14:42:07 
2005
@@ -131,6 +131,16 @@
     </init-param>
 
     <!--
+      The forbidden level for deprectation messages. DEBUG forbids all 
deprecations (strict mode)
+      and FATAL_ERROR allows all (tolerant mode). Default is ERROR, allowing 
up to WARN.
+      See org.apache.util.Deprecation for more details.
+    -->
+    <init-param>
+      <param-name>forbidden-deprecation-level</param-name>
+      <param-value>ERROR</param-value>
+    </init-param>
+
+    <!--
       This parameter switches the logging system from LogKit to Log4J for 
Cocoon.
       Log4J has to be configured already.
       <init-param>

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&r1=157287&r2=157288
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Sat Mar 12 14:42:07 2005
@@ -202,6 +202,12 @@
 
   <changes>
   <release version="@version@" date="@date@">
+   <action dev="SW" type="update">
+     Refactored the Deprecation class: the "forbidden-deprecation-level" 
parameter in web.xml
+     allows to raise deprecation exceptions depending on the log level. For 
example, DEBUG
+     allows no deprecations (strict mode), and FATAL_ERROR allows all 
(tolerant mode).
+     Default is ERROR, allowing messages up to WARN.
+   </action>
    <action dev="SW" type="add">
      A flowscript's file encoding can now be specified by a comment on the 
script's
      very first line, in the form "<code>// encoding = xxxx</code>". 
Otherwise, the


Reply via email to