directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9439 - incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers
Date Sat, 13 Mar 2004 21:44:17 GMT
Author: akarasulu
Date: Sat Mar 13 13:44:16 2004
New Revision: 9439

Added:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/SnickersDecoder.java
Log:
created message decoder that depends on a provider

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/SnickersDecoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/SnickersDecoder.java
Sat Mar 13 13:44:16 2004
@@ -0,0 +1,126 @@
+/*
+ *   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.snickers ;
+
+
+import java.io.ByteArrayInputStream ;
+
+import org.apache.commons.codec.DecoderException ;
+import org.apache.commons.codec.stateful.DecoderMonitor ;
+import org.apache.commons.codec.stateful.DecoderCallback ;
+import org.apache.commons.codec.stateful.StatefulDecoder ;
+import org.apache.commons.codec.stateful.DecoderMonitorAdapter ; 
+
+import org.apache.ldap.common.message.Message ;
+import org.apache.ldap.common.message.MessageDecoder ;
+
+import org.apache.snickers.ber.TupleNode ; 
+import org.apache.snickers.ber.TupleTreeDecoder ;
+
+
+/**
+ * Snickers decoder used to generate an LDAP Message PDU stream from a BER 
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SnickersDecoder implements StatefulDecoder
+{
+    /** nested tlv tree decoder */
+    TupleTreeDecoder berDecoder = new TupleTreeDecoder() ;
+    /** monitor for all decoders */
+    DecoderMonitor monitor = new DecoderMonitorAdapter() ;
+    /** the callback for this decoder */
+    DecoderCallback cb = null ;
+    /** a decoder from the message framework which is not a codec decoder */
+    MessageDecoder msgDecoder = new MessageDecoder() ;
+
+    
+    /**
+     * Creates a SnickersDecoder to be dedicated to a client.
+     */
+    public SnickersDecoder( DecoderCallback cb )
+    {
+        this.cb = cb ;
+        berDecoder.setDecoderMonitor( monitor ) ;
+        DecoderCallback dcb = new DecoderCallback()
+        {
+            public void decodeOccurred( StatefulDecoder decoder, Object arg )
+            {
+                if ( SnickersDecoder.this.berDecoder != decoder )
+                {
+                    return ;
+                }
+                
+                decode( ( TupleNode ) arg ) ;
+            }
+        } ;
+        
+        berDecoder.setCallback( dcb ) ;
+    }
+
+    
+    /**
+     * Synchronously decodes a tlv tuple tree into an LDAP message envelope.
+     * 
+     * @param root the root of the tlv tuple tree 
+     * @return the decoded message envelope
+     */
+    public synchronized Message decode( TupleNode root )
+    {
+        ByteArrayInputStream in = new ByteArrayInputStream( root.encode() ) ;
+        Message msg = msgDecoder.decode( null, in ) ;
+        
+        if ( cb != null )
+        {    
+            cb.decodeOccurred( this, msg ) ;
+        }
+        
+        return msg ;
+    }
+    
+
+    /* (non-Javadoc)
+     * @see org.apache.commons.codec.stateful.StatefulDecoder#decode(
+     * java.lang.Object)
+     */
+    public void decode( Object arg0 ) throws DecoderException
+    {
+        berDecoder.decode( arg0 ) ;
+    }
+
+    
+    /* (non-Javadoc)
+     * @see org.apache.commons.codec.stateful.StatefulDecoder#setCallback(
+     * org.apache.commons.codec.stateful.DecoderCallback)
+     */
+    public void setCallback( DecoderCallback cb )
+    {
+        this.cb = 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 ;
+    }
+}

Mime
View raw message