directory-commits mailing list archives

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

Added:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleAnalyzer.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java
Modified:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java
Log:
added tuple tree related tools

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
Fri Mar 12 22:38:16 2004
@@ -339,7 +339,8 @@
          * zero length and a type class of UNIVERSAL which is reserved
          * for use by encoding rules.
          */
-        if ( tlv.typeClass == TypeClass.UNIVERSAL && tlv.length == 0 )
+        if ( tlv.id == 0 && tlv.length == 0 && 
+                tlv.typeClass == TypeClass.UNIVERSAL )
         {
             String msg = "expected indefinate length TLV on the stack" ;
 

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
Fri Mar 12 22:38:16 2004
@@ -19,9 +19,14 @@
 
 import java.util.Iterator ;
 import java.util.ArrayList ;
+import java.util.Enumeration ;
 import java.util.Collections ;
 
-import org.apache.commons.lang.NotImplementedException;
+import javax.swing.tree.TreeNode ;
+import javax.swing.tree.MutableTreeNode ;
+
+import org.apache.commons.lang.StringUtils ;
+import org.apache.commons.lang.NotImplementedException ;
 
 
 /**
@@ -31,11 +36,31 @@
  * Apache Directory Project</a>
  * @version $Rev$
  */
-public class DefaultMutableTupleNode implements MutableTupleNode
+public class DefaultMutableTupleNode 
+    implements MutableTupleNode, MutableTreeNode
 {
     private Tuple tuple ;
-    private ArrayList children ;
-    private MutableTupleNode parent ;
+    private ArrayList children = new ArrayList();
+    private DefaultMutableTupleNode parent ;
+    
+    
+    /**
+     * Creates a node without a parent and without a tuple.
+     */
+    public DefaultMutableTupleNode()
+    {
+    }
+    
+
+    /**
+     * Creates a node without a parent.
+     * 
+     * @param tuple the tuple to set for this node
+     */
+    public DefaultMutableTupleNode( Tuple tuple )
+    {
+        this.tuple = tuple ;
+    }
     
 
     /* (non-Javadoc)
@@ -72,7 +97,7 @@
      */
     public void removeFromParent()
     {
-        parent.remove( this ) ;
+        parent.remove( ( MutableTupleNode ) this ) ;
         parent = null ;
     }
 
@@ -83,9 +108,12 @@
      */
     public void setParent( MutableTupleNode newParent )
     {
-        parent.remove( this ) ;
-        newParent.insert( this, 0 ) ;
-        parent = newParent ;
+        if ( parent != null )
+        {    
+            parent.remove( ( MutableTupleNode ) this ) ;
+        }
+        
+        parent = ( DefaultMutableTupleNode ) newParent ;
     }
 
     
@@ -93,7 +121,7 @@
      * @see org.apache.snickers.ber.MutableTupleNode#setTuple(
      * org.apache.snickers.ber.Tuple)
      */
-    public void setTuple(Tuple t)
+    public void setTuple( Tuple t )
     {
         tuple = t ;
     }
@@ -102,7 +130,7 @@
     /* (non-Javadoc)
      * @see org.apache.snickers.ber.TupleNode#getParent()
      */
-    public TupleNode getParent()
+    public TupleNode getParentTupleNode()
     {
         return parent ;
     }
@@ -111,7 +139,7 @@
     /* (non-Javadoc)
      * @see org.apache.snickers.ber.TupleNode#children()
      */
-    public Iterator children()
+    public Iterator getChildren()
     {
         return Collections.unmodifiableList( children ).iterator() ;
     }
@@ -120,7 +148,7 @@
     /* (non-Javadoc)
      * @see org.apache.snickers.ber.TupleNode#getChildAt()
      */
-    public TupleNode getChildAt( int index )
+    public TupleNode getChildTupleNodeAt( int index )
     {
         return ( TupleNode ) children.get( index ) ;
     }
@@ -186,5 +214,155 @@
     public byte[] encode()
     {
         throw new NotImplementedException( "STUB" ) ;
+    }
+    
+    
+    public String toString()
+    {
+        /**
+        StringBuffer buf = new StringBuffer() ;
+        printDepthFirst( buf, 0 ) ;
+        return buf.toString() ;
+        **/
+
+        StringBuffer buf = new StringBuffer() ;
+        buf.append( tuple.getId() ) ;
+        buf.append( ' ' ).append( tuple.typeClass ) ;
+        buf.append( '[' ).append( tuple.length ).append( ']' ) ;
+        buf.append( '[' ).append( new String( (byte[]) tuple.getValue() ) ) ;
+        buf.append( ']' ) ;
+        
+        return buf.toString() ;
+    }
+    
+    
+    public void printDepthFirst( StringBuffer buf, int level )
+    {
+        DefaultMutableTupleNode child = null ;
+        String levelTab = StringUtils.repeat( "\t", level ) ;
+        
+        if ( level != 0 )
+        {
+            buf.append( "\n" ) ;
+        }
+        
+        buf.append( levelTab ).append( tuple.getId() ) ;
+        buf.append( ' ' ).append( tuple.typeClass ) ;
+        buf.append( '[' ).append( tuple.length ).append( ']' ) ;
+        buf.append( '[' ).append( new String( (byte[]) tuple.getValue() ) ) ;
+        buf.append( ']' ) ;
+        for ( int ii = 0; ii < children.size(); ii++ )
+        {
+            child = ( DefaultMutableTupleNode ) children.get( ii ) ;
+            child.printDepthFirst( buf, level + 1 ) ;
+        }
+    }
+    
+    
+    // ------------------------------------------------------------------------
+    // MutableTreeNode implementations
+    // ------------------------------------------------------------------------
+    
+    
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#children()
+     */
+    public Enumeration children()
+    {
+        return Collections.enumeration( children ) ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#getAllowsChildren()
+     */
+    public boolean getAllowsChildren()
+    {
+        return ! tuple.isPrimitive() ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#getChildAt(int)
+     */
+    public TreeNode getChildAt( int childIndex )
+    {
+        return ( TreeNode ) getChildTupleNodeAt( childIndex ) ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
+     */
+    public int getIndex( TreeNode node )
+    {
+        return getIndex( ( TupleNode ) node ) ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#getParent()
+     */
+    public TreeNode getParent()
+    {
+        return parent ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.swing.tree.MutableTreeNode#insert(
+     * javax.swing.tree.MutableTreeNode, int)
+     */
+    public void insert( MutableTreeNode child, int index )
+    {
+        insert( ( MutableTupleNode ) child, index ) ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#isLeaf()
+     */
+    public boolean isLeaf()
+    {
+        if ( tuple.isPrimitive() )
+        {    
+            return true ;
+        }
+        
+        if ( children.isEmpty() )
+        {
+            return true ;
+        }
+
+        return false ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.swing.tree.MutableTreeNode#remove(
+     * javax.swing.tree.MutableTreeNode)
+     */
+    public void remove( MutableTreeNode node )
+    {
+        remove( ( MutableTupleNode ) node ) ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.swing.tree.MutableTreeNode#setParent(
+     * javax.swing.tree.MutableTreeNode)
+     */
+    public void setParent( MutableTreeNode newParent )
+    {
+        parent = ( DefaultMutableTupleNode ) newParent ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.swing.tree.MutableTreeNode#setUserObject(java.lang.Object)
+     */
+    public void setUserObject( Object object )
+    {
+        tuple = ( Tuple ) object ;
     }
 }

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleAnalyzer.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleAnalyzer.java
Fri Mar 12 22:38:16 2004
@@ -0,0 +1,251 @@
+/*
+ *   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.ber ;
+
+
+import javax.swing.JFileChooser;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JTree ;
+import javax.swing.JFrame ;
+import javax.swing.JPanel ;
+import javax.swing.JLabel ;
+import javax.swing.JTextArea ;
+import javax.swing.JTextField ;
+import javax.swing.JSplitPane ;
+import javax.swing.JScrollPane ;
+import javax.swing.tree.DefaultTreeModel;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowEvent ;
+
+
+/**
+ * $todo$ doc me
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TupleAnalyzer extends JFrame 
+{
+    DefaultMutableTupleNode root = null ;
+    
+    /** Creates new form JFrame */
+    public TupleAnalyzer( DefaultMutableTupleNode root ) 
+    {
+        this.root = root ;
+        
+        initGUI() ;
+        pack() ;
+    }
+
+    /** This method is called from within the constructor to initialize the form. */
+    private void initGUI() {
+
+        getContentPane().setLayout(layout);
+        JPanel content = new JPanel();
+        content.setPreferredSize(new Dimension(300, 200));
+        getContentPane().add(content, BorderLayout.CENTER);
+        // set title
+        setTitle("");
+        // add status bar
+        getContentPane().add(statusBar, BorderLayout.SOUTH);
+        // add menu bar
+        JMenuBar menuBar = new JMenuBar();
+        JMenu menuFile = new JMenu("File");
+        menuFile.setMnemonic('F');
+        // create Exit menu item
+        JMenuItem fileExit = new JMenuItem("Exit");
+        fileExit.setMnemonic('E');
+        fileExit.addActionListener(
+            new ActionListener() {
+                public void actionPerformed(ActionEvent e) {
+                    System.exit(0);
+                }
+            });
+        // create About menu item
+        JMenu menuHelp = new JMenu("Help");
+        menuHelp.setMnemonic('H');
+        JMenuItem helpAbout = new JMenuItem("About");
+        helpAbout.setMnemonic('A');
+        helpAbout.addActionListener(
+            new ActionListener() {
+                public void actionPerformed(ActionEvent e) {
+                }
+            });
+        menuHelp.add(helpAbout);
+        // create Open menu item
+        final JFileChooser fc = new JFileChooser();
+        JMenuItem openFile = new JMenuItem("Open");
+        openFile.setMnemonic('O');
+        openFile.addActionListener(
+            new java.awt.event.ActionListener() {
+                public void actionPerformed(java.awt.event.ActionEvent e) {
+                    int returnVal = fc.showOpenDialog(TupleAnalyzer.this);
+                    if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
+                        java.io.File file = fc.getSelectedFile();
+                        // Write your code here what to do with selected file
+                    } else {
+                        // Write your code here what to do if user has canceled
+                    }
+                }
+            });
+        menuFile.add(openFile);
+        // create Save menu item
+        JMenuItem saveFile = new JMenuItem("Save");
+        saveFile.setMnemonic('S');
+        saveFile.addActionListener(
+            new java.awt.event.ActionListener() {
+                public void actionPerformed(java.awt.event.ActionEvent e) {
+                    int returnVal = fc.showSaveDialog(TupleAnalyzer.this);
+                    if (returnVal == JFileChooser.APPROVE_OPTION) {
+                        java.io.File file = fc.getSelectedFile();
+                        // Write your code here what to do with selected file
+                    } else {
+                        // Write your code here what to do if user has canceled Save dialog
+                    }
+                }
+            });
+        menuFile.add(saveFile);
+        // create Print menu item
+        JMenuItem print = new JMenuItem("Print");
+        print.setMnemonic('P');
+        print.addActionListener(
+            new java.awt.event.ActionListener() {
+                public void actionPerformed(java.awt.event.ActionEvent e) {
+                    // PrintDialog.print(getGraphics());
+                }
+            }); menuFile.add(print);
+        menuFile.add(fileExit);
+        menuBar.add(menuFile);
+        menuBar.add(menuHelp);
+        // sets menu bar
+        setJMenuBar(menuBar);
+        addWindowListener(
+            new java.awt.event.WindowAdapter() {
+                public void windowClosing(java.awt.event.WindowEvent evt) {
+                    exitForm(evt);
+                }
+            });
+        
+        
+        jLabel3.setText("Type Class:");
+        jPanel5.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
+        jPanel5.add(jLabel3);
+        jPanel5.add(jTextField3);
+        jTextField3.setText("");
+        jTextField3.setMinimumSize(new java.awt.Dimension(104, 25));
+        jTextField3.setPreferredSize(new java.awt.Dimension(104, 25));
+        jSplitPane1.setLastDividerLocation(50);
+        jSplitPane1.setDividerLocation(180);
+        jSplitPane1.add(jScrollPane1, javax.swing.JSplitPane.LEFT);
+        jSplitPane1.add(jPanel1, javax.swing.JSplitPane.RIGHT);
+        addWindowListener(
+            new java.awt.event.WindowAdapter() {
+                public void windowClosing(java.awt.event.WindowEvent evt) {
+                    exitForm(evt);
+                }
+            });
+        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);
+        jScrollPane1.getViewport().add(jTree1);
+        jTree1.setBounds(new java.awt.Rectangle(95,95,85,84));
+        jTree1.setShowsRootHandles(true);
+        jPanel1.setLayout(new java.awt.GridBagLayout());
+        jPanel1.add(jPanel2,
+        new java.awt.GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, java.awt.GridBagConstraints.WEST,
java.awt.GridBagConstraints.HORIZONTAL,
+        new java.awt.Insets(0, 9, 0, 9), 0, 0));
+        jPanel1.add(jPanel3,
+        new java.awt.GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, java.awt.GridBagConstraints.WEST,
java.awt.GridBagConstraints.HORIZONTAL,
+        new java.awt.Insets(0, 9, 0, 9), 0, 0));
+        jPanel1.add(jPanel4,
+        new java.awt.GridBagConstraints(0, 3, 1, 35, 1.0, 1.0, java.awt.GridBagConstraints.CENTER,
java.awt.GridBagConstraints.BOTH,
+        new java.awt.Insets(9, 12, 9, 12), 0, 0));
+        jPanel1.add(jPanel5,
+        new java.awt.GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, java.awt.GridBagConstraints.WEST,
java.awt.GridBagConstraints.HORIZONTAL,
+        new java.awt.Insets(0, 9, 0, 9), 0, 0));
+        jLabel1.setText("Tag Id:");
+        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
+        jPanel2.add(jLabel1);
+        jPanel2.add(jTextField1);
+        jLabel2.setText("Length:");
+        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
+        jPanel3.add(jLabel2);
+        jPanel3.add(jTextField2);
+        jPanel4.setLayout(new java.awt.BorderLayout());
+        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(
+        new java.awt.Color(153, 153, 153), 1), "Value", javax.swing.border.TitledBorder.LEADING,
javax.swing.border.TitledBorder.TOP,
+        new java.awt.Font("Comic Sans MS", 0, 14), new java.awt.Color(60, 60, 60)));
+        jPanel4.add(jScrollPane2, java.awt.BorderLayout.CENTER);
+        jTextArea1.setText("");
+        jScrollPane2.getViewport().add(jTextArea1);
+        jTextField1.setText("");
+        jTextField1.setMinimumSize(new java.awt.Dimension(104, 25));
+        jTextField1.setPreferredSize(new java.awt.Dimension(104, 25));
+        jTextField1.setEditable(true);
+        jTextField2.setText("");
+        jTextField2.setPreferredSize(new java.awt.Dimension(104,25));
+        jTextField2.setMinimumSize(new java.awt.Dimension(104,25));
+        jTextField2.setEditable(true);
+        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
+        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
+        jScrollPane2.setBorder(null);
+        
+        jTree1.setModel( new DefaultTreeModel( root ) ) ;
+    }
+
+    /** Exit the Application */
+    private void exitForm(WindowEvent evt) {
+        System.exit(0);
+    }
+
+    
+    public void startup()
+    {
+        setSize( 800, 640 ) ;
+        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+        Dimension frameSize = getSize();
+        frameSize.height = ((frameSize.height > screenSize.height) ? screenSize.height
: frameSize.height);
+        frameSize.width = ((frameSize.width > screenSize.width) ? screenSize.width : frameSize.width);
+        setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height)
/ 2);
+        setVisible(true);
+    }
+
+    private BorderLayout layout = new BorderLayout();
+    private JLabel statusBar = new JLabel("Ready");
+    private JSplitPane jSplitPane1 = new JSplitPane();
+    private JScrollPane jScrollPane1 = new JScrollPane();
+    private JPanel jPanel1 = new JPanel();
+    private JTree jTree1 = new JTree();
+    private JPanel jPanel2 = new JPanel();
+    private JPanel jPanel5 = new JPanel();
+    private JPanel jPanel3 = new JPanel();
+    private JPanel jPanel4 = new JPanel();
+    private JLabel jLabel1 = new JLabel();
+    private JLabel jLabel3 = new JLabel();
+    private JLabel jLabel2 = new JLabel();
+    private JScrollPane jScrollPane2 = new JScrollPane();
+    private JTextArea jTextArea1 = new JTextArea();
+    private JTextField jTextField1 = new JTextField();
+    private JTextField jTextField3 = new JTextField();
+    private JTextField jTextField2 = new JTextField();
+}

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java
Fri Mar 12 22:38:16 2004
@@ -29,9 +29,9 @@
  */
 public interface TupleNode
 {
-    TupleNode getParent() ;
-    Iterator children() ;
-    TupleNode getChildAt( int index ) ;
+    TupleNode getParentTupleNode() ;
+    Iterator getChildren() ;
+    TupleNode getChildTupleNodeAt( int index ) ;
     int getIndex( TupleNode node ) ;
     int getChildCount() ;
     int size() ;

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java
Fri Mar 12 22:38:16 2004
@@ -0,0 +1,141 @@
+/*
+ *   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.ber ;
+
+
+import java.util.Stack ;
+
+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 ;
+
+
+/**
+ * Builds a TLV tree from the TLV stream emitted from the decoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TupleTreeDecoder implements StatefulDecoder
+{
+    Stack stack = new Stack() ;
+    BERDecoder decoder = new BERDecoder() ;
+    DecoderCallback cb = null ;
+    DecoderMonitor monitor = new DecoderMonitorAdapter() ;
+
+    
+    public TupleTreeDecoder()
+    {
+        BERDecoderCallback berCallback = new BERDecoderCallback()
+        {
+            public void tagDecoded( Tuple tlv ) { }
+        
+            public void lengthDecoded( Tuple tlv )
+            {
+                if ( ! tlv.isPrimitive ) 
+                {
+                    MutableTupleNode child = null ;
+                    MutableTupleNode parent = null ;
+                    Tuple cloned = ( Tuple ) tlv.clone() ;
+                    
+                    if ( stack.isEmpty() )
+                    {
+                        stack.push( new DefaultMutableTupleNode( cloned ) ) ;
+                        return ;
+                    }
+                    
+                    parent = ( MutableTupleNode ) stack.peek() ;
+                    child = new DefaultMutableTupleNode( cloned ) ;
+                    child.setParent( parent ) ;
+                    parent.insert( child, 0 ) ;
+                    stack.push( child ) ;
+                }
+            }
+    
+            public void 
+                decodeOccurred( StatefulDecoder decoder, Object decoded )
+            {
+                handleTuple( ( Tuple ) decoded ) ;
+            }
+        } ;
+        
+        decoder.setCallback( berCallback ) ;
+        decoder.setDecoderMonitor( monitor ) ;
+    }
+    
+    
+    public void handleTuple( Tuple t )
+    {
+        System.out.println( t.id ) ;
+        MutableTupleNode node = null ;
+        
+        if ( t.isPrimitive )
+        {
+            node = new DefaultMutableTupleNode( ( Tuple ) t.clone() ) ;
+                
+            if ( ! stack.isEmpty() )
+            {    
+                MutableTupleNode parent = ( MutableTupleNode ) stack.peek() ;
+                node.setParent( parent ) ;
+                parent.insert( node, 0 ) ;
+            }
+            
+            return ;
+        }
+            
+        node = ( MutableTupleNode ) stack.pop() ;
+        
+        if ( cb != null && stack.isEmpty() )
+        {
+            cb.decodeOccurred( this, node ) ;
+        }
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.commons.codec.stateful.StatefulDecoder#decode(
+     * java.lang.Object)
+     */
+    public void decode( Object encoded ) throws DecoderException
+    {
+        decoder.decode( encoded ) ;
+    }
+    
+    
+    /* (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 ;
+        decoder.setDecoderMonitor( monitor ) ;
+    }
+}

Mime
View raw message