directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9473 - incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful
Date Mon, 15 Mar 2004 03:04:35 GMT
Author: akarasulu
Date: Sun Mar 14 19:04:34 2004
New Revision: 9473

Added:
   incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/AbstractStatefulDecoder.java
  (contents, props changed)
Modified:
   incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/DecoderMonitor.java
   incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/DecoderMonitorAdapter.java
Log:
added a utility abstract class for convenience

Added: incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/AbstractStatefulDecoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/AbstractStatefulDecoder.java
Sun Mar 14 19:04:34 2004
@@ -0,0 +1,149 @@
+/*
+ *   Copyright 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.commons.codec.stateful ;
+
+
+/**
+ * Convenience class to not have to reimplement the two setter methods everytime
+ * one starts a new decoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public abstract class AbstractStatefulDecoder implements StatefulDecoder
+{
+    /** this decoder's callback */
+    private DecoderCallback cb = null ;
+    /** this decoder's monitor */
+    private DecoderMonitor monitor = null ;
+    
+    
+    // ------------------------------------------------------------------------
+    // constructors
+    // ------------------------------------------------------------------------
+    
+    
+    /**
+     * Creates a stateful decoder where the callback and monitor must be set.
+     */
+    public AbstractStatefulDecoder() 
+    { 
+    }
+    
+    
+    /**
+     * Creates a stateful decoder with a callback.
+     * 
+     * @param cb the callback to use for this decoder
+     */
+    public AbstractStatefulDecoder( DecoderCallback cb )
+    {
+        setCallback( cb ) ;
+    }
+
+    
+    /**
+     * Creates a stateful decoder with a monitor but no callback.
+     * 
+     * @param monitor the monitor to use for this decoder
+     */
+    public AbstractStatefulDecoder( DecoderMonitor monitor )
+    {
+        this.monitor = monitor ;
+    }
+    
+    
+    /**
+     * Creates a stateful decoder.
+     * 
+     * @param cb the callback to use for this decoder
+     * @param monitor the monitor to use for this decoder
+     */
+    public AbstractStatefulDecoder( DecoderCallback cb, DecoderMonitor monitor )
+    {
+        this.monitor = monitor ;
+        setCallback( cb ) ;
+    }
+    
+    
+    // ------------------------------------------------------------------------
+    // StatefulDecoder methods
+    // ------------------------------------------------------------------------
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.commons.codec.stateful.StatefulDecoder#setCallback(
+     * org.apache.commons.codec.stateful.DecoderCallback)
+     */
+    public void setCallback( DecoderCallback cb )
+    {
+        DecoderCallback old = this.cb ;
+        this.cb = cb ;
+        
+        if ( monitor != null )
+        {
+            monitor.callbackSet( this, old, cb ) ;
+        }
+    }
+    
+
+    /* (non-Javadoc)
+     * @see org.apache.commons.codec.stateful.StatefulDecoder#setDecoderMonitor(
+     * org.apache.commons.codec.stateful.DecoderMonitor)
+     */
+    public void setDecoderMonitor( DecoderMonitor monitor )
+    {
+        this.monitor = monitor ;
+    }
+    
+    
+    // ------------------------------------------------------------------------
+    // protected methods
+    // ------------------------------------------------------------------------
+    
+    
+    /**
+     * Notifies via the callback if one has been set that this decoder has 
+     * decoded a unit of encoded data.
+     * 
+     * @param decoded the decoded byproduct.
+     */
+    protected void decodeOccurred( Object decoded ) 
+    {
+        if ( cb != null )
+        {    
+            cb.decodeOccurred( this, decoded ) ;
+        }
+        
+        if ( monitor != null )
+        {    
+            monitor.callbackOccured( this, cb, decoded ) ;
+        }
+    }
+    
+    
+    /**
+     * Gets the decoder's monitor.
+     * 
+     * @return the monitor for this StatefulDecoder
+     */
+    protected DecoderMonitor getDecoderMonitor()
+    {
+        return monitor ;
+    }
+}

Modified: incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/DecoderMonitor.java
==============================================================================
--- incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/DecoderMonitor.java
(original)
+++ incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/DecoderMonitor.java
Sun Mar 14 19:04:34 2004
@@ -18,8 +18,11 @@
 
 
 /**
- * Monitors decoder errors.  This class borrowed some from the <code>
- * org.xml.sax.ErrorHandler</code> interface and its documentation.
+ * Monitors decoder activity.  This class borrowed some from the <code>
+ * org.xml.sax.ErrorHandler</code> interface and its documentation.  A monitor
+ * is a generalized callback for any sort of activity used for tracking both 
+ * successes and failures.  So you'll realize similarities between monitors
+ * and callbacks especially where the callbackOccurred() method is concerned.
  *
  * @author <a href="mailto:directory-dev@incubator.apache.org">
  * Apache Directory Project</a>
@@ -78,13 +81,4 @@
      */
     void callbackSet( StatefulDecoder decoder, DecoderCallback oldcb, 
 					  DecoderCallback newcb ) ;
-
-    /**
-     * Monitors changes to the the monitor for the decoder.  Note that the
-     * object being called is the new monitor.
-     * 
-     * @param decoder the decoder whose monitor was set
-     * @param oldmon the old monitor or null if none was set
-     */
-    void monitorSet( StatefulDecoder decoder, DecoderMonitor oldmon ) ;
 }

Modified: incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/DecoderMonitorAdapter.java
==============================================================================
--- incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/DecoderMonitorAdapter.java
(original)
+++ incubator/directory/snickers/branches/refactoring/codec-stateful/src/java/org/apache/commons/codec/stateful/DecoderMonitorAdapter.java
Sun Mar 14 19:04:34 2004
@@ -74,14 +74,4 @@
 							 DecoderCallback newcb )
     {
     }
-
-    
-    /* (non-Javadoc)
-     * @see org.apache.commons.codec.stateful.DecoderMonitor#monitorSet(
-     * org.apache.commons.codec.stateful.StatefulDecoder, 
-     * org.apache.commons.codec.stateful.DecoderMonitor)
-     */
-    public void monitorSet( StatefulDecoder decoder, DecoderMonitor oldmon )
-    {
-    }
 }

Mime
View raw message