directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r278921 - in /directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy: gui/MainFrame.java impl/LdapMessageWithPDU.java impl/LdapProxy.java impl/ProxyConnection.java
Date Tue, 06 Sep 2005 06:01:27 GMT
Author: elecharny
Date: Mon Sep  5 23:01:18 2005
New Revision: 278921

URL: http://svn.apache.org/viewcvs?rev=278921&view=rev
Log:
- formating the code
- added the Apache header
- added some javadoco
- used DEFAULT_TIMEOUT instead of 30000
- splitted the PDU in pieces
- renamed some members

Modified:
    directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/gui/MainFrame.java
    directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/LdapMessageWithPDU.java
    directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/LdapProxy.java
    directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/ProxyConnection.java

Modified: directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/gui/MainFrame.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/gui/MainFrame.java?rev=278921&r1=278920&r2=278921&view=diff
==============================================================================
--- directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/gui/MainFrame.java (original)
+++ directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/gui/MainFrame.java Mon Sep  5 23:01:18 2005
@@ -30,7 +30,6 @@
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
 
-
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -65,514 +64,567 @@
 import javax.swing.tree.TreeSelectionModel;
 
 /**
- * DOCUMENT ME!
+ * A Ldap Proxy GUI
  * 
- * @author $author$
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class MainFrame extends JFrame implements TreeSelectionListener, TreeExpansionListener {
-	// ~ Static fields/initializers
-	// -----------------------------------------------------------------
-
-	/** frame itSelf */
-	private MainFrame itSelf;
-
-	/** Frame and Application name */
-	public static final String FRAME_NAME = "LDAP Proxy GUI";
-
-	/** NOT USED */
-	// public static final long serialVersionUID = 0;
-	/** Frame default Size */
-	public static final Rectangle FRAME_SIZE = new Rectangle(100, 100, 1000, 500);
-
-	// ~ Instance fields
-	// ----------------------------------------------------------------------------
-
-	// ALL Panel
-	/** DOCUMENT ME! */
-	private JSplitPane principalPanel;
-
-	/** DOCUMENT ME! */
-	private JScrollPane jspIn;
-
-	/** DOCUMENT ME! */
-	private JScrollPane jspOut;
-
-	/** DOCUMENT ME! */
-	private JTree messageTree;
-
-	/** DOCUMENT ME! */
-	private JTextPane textOut;
-
-	// List of Menu
-	/** DOCUMENT ME! */
-	private JMenuBar menuBar = new JMenuBar();
-
-	/** DOCUMENT ME! */
-	private JMenu file = new JMenu("File");
-
-	/** DOCUMENT ME! */
-	private JMenu edit = new JMenu("edit");
-	
-	/** DOCUMENT ME! */
-	private JMenuItem newMenu = new JMenuItem("New...");
-
-	/** DOCUMENT ME! */
-	private JMenuItem load = new JMenuItem("load");
-
-	/** DOCUMENT ME! */
-	private JMenuItem save = new JMenuItem("Save");
-
-	/** DOCUMENT ME! */
-	private JMenuItem quit = new JMenuItem("Quit");
-
-	/** DOCUMENT ME! */
-	private JCheckBoxMenuItem pduView = new JCheckBoxMenuItem("View PDU");
-
-	/** DOCUMENT ME! */
-	private LdapProxy ldapProxy;
-
-	/** DOCUMENT ME! */
-	private DefaultStyledDocument docOut;
-
-	private String[] args;
-
-	private DefaultMutableTreeNode top;
-
-	private DefaultMutableTreeNode ldapMessageTree;
-
-	private DefaultTreeModel treeModel;
-
-	// STYLE
-	private SimpleAttributeSet boldItalicRedText;
-
-	private SimpleAttributeSet boldText;
-
-	private SimpleAttributeSet boldItalicBlueText;
-	
-	private SimpleAttributeSet pduStyle;
-	
-	final static String SEPARATOR = "\n====================================\n";
-
-
-	// ~ Constructors
-	// -------------------------------------------------------------------------------
-
-	/**
-	 * Creates a new MainFrame object.
-	 * 
-	 * @throws HeadlessException
-	 *             DOCUMENT ME!
-	 * @throws UnknownHostException
-	 *             DOCUMENT ME!
-	 * @throws IOException
-	 *             DOCUMENT ME!
-	 */
-	public MainFrame() throws HeadlessException, UnknownHostException, IOException {
-		super();
-		initFrame();
-		
-	}
-	
-	// ~ Methods
-	// ------------------------------------------------------------------------------------
-	
-	public void initFrame(){
-		setItSelf(this);
-		setTitle(FRAME_NAME);
-		setBounds(FRAME_SIZE);
-		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		setJMenuBar(initMenuBar());
-		top = new DefaultMutableTreeNode("Start");
-		treeModel = new DefaultTreeModel(top);
-		messageTree = new JTree(treeModel);		
-		ldapMessageTree = new DefaultMutableTreeNode("Start Ldap message");
-		
-		messageTree.addTreeExpansionListener(this);
-		messageTree.addTreeSelectionListener(this);
-
-		messageTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
-		initRenderTree();
-		messageTree.setBackground(Color.lightGray);
-		messageTree.putClientProperty("JTree.lineStyle", "None");
-
-		initStyleForEditing();
-
-		messageTree.setEditable(false);
-		// messageTree.setRootVisible(false);
-
-		textOut = new JTextPane(docOut);
-		textOut.setEditable(false);
-
-		jspIn = new JScrollPane();
-		jspIn.getViewport().add(messageTree);
-
-		jspOut = new JScrollPane();
-		jspOut.getViewport().add(textOut);
-
-		principalPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jspIn, jspOut);
-		principalPanel.setOneTouchExpandable(true);
-		principalPanel.setDividerLocation(500);
-
-		getContentPane().add(principalPanel);
-	}
-	
-	public void initStyleForEditing(){
-//		 DEFAULT STYLE
-		Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
-		docOut = new DefaultStyledDocument();
-		// other style could be define later // COMMENT TO BE DELETED AFTER DEV
-
-		boldItalicRedText = new SimpleAttributeSet();
-		StyleConstants.setForeground(boldItalicRedText, Color.red);
-		StyleConstants.setBold(boldItalicRedText, true);
-		StyleConstants.setItalic(boldItalicRedText, true);
-		StyleConstants.setFontSize(boldItalicRedText, 12);
-
-		boldItalicBlueText = new SimpleAttributeSet();
-		StyleConstants.setForeground(boldItalicBlueText, Color.blue);
-		StyleConstants.setBold(boldItalicBlueText, true);
-		StyleConstants.setItalic(boldItalicBlueText, true);
-		StyleConstants.setFontSize(boldItalicBlueText, 12);
-
-		boldText = new SimpleAttributeSet();
-		StyleConstants.setFontSize(boldText, 14);
-		StyleConstants.setBold(boldText, true);
-		
-		pduStyle = new SimpleAttributeSet();
-		StyleConstants.setFontSize(pduStyle, 12);
-		StyleConstants.setBold(pduStyle, true);
-		StyleConstants.setForeground(pduStyle, Color.DARK_GRAY);
-		
-		
-	}
-	
-	
-	/**
-	 * DOCUMENT ME!
-	 */
-	public void launchLdapProxy(String[] args) {
-		ldapProxy = new LdapProxy();
-		ldapProxy.setMainFrame(this);
-		// ldapProxy.setTextIn( messageTree );
-		// ldapProxy.setTextOut( textOut );
-
-		ldapProxy.likeMain(args);
-
-	}
-
-	/** Returns an ImageIcon, or null if the path was invalid. */
-	protected static ImageIcon createImageIcon(String path) {
-		// java.net.URL imgURL = MainFrame.class.getResource(path);
-		try {
-			return new ImageIcon(path);
-		} catch (Exception e) {
-			return null;
-		}
-		/*
-		 * if (imgURL != null) { return new ImageIcon(imgURL); } else {
-		 * System.err.println("Couldn't find file: " + path); return null; }
-		 */
-	}
-
-	/**
-	 * DOCUMENT ME!
-	 */
-	public void initRenderTree() {
-		ImageIcon leafIcon = createImageIcon("./images/gnome-icone-001.gif");
-		ImageIcon icon = createImageIcon("./images/gnome-icone-002.gif");
-		if ((leafIcon != null) && (icon != null)) {
-			DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
-			renderer.setLeafIcon(leafIcon);
-			messageTree.setCellRenderer(renderer);
-			renderer.setFont(new Font("treeFont", Font.BOLD, 12));
-			renderer.setBackgroundNonSelectionColor(Color.lightGray);
-			renderer.setBackgroundSelectionColor(Color.white);
-			renderer.setOpenIcon(icon);
-			renderer.setClosedIcon(icon);
-		}
-
-	}
-
-	/**
-	 * DOCUMENT ME!
-	 * 
-	 * @return DOCUMENT ME!
-	 */
-	private JMenuBar initMenuBar() {
-		file.add(newMenu);
-		file.add(load);
-		file.add(save);
-		file.addSeparator();
-		file.add(quit);
-		newMenu.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent action) {
-				//top.removeAllChildren();
-				// TO DO BETTER !!!!!
-				top = new DefaultMutableTreeNode("Start");
-				treeModel.setRoot(top);			
-			}
-		});
-		save.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent action) {
-				try {
-					FileWriter fw = new FileWriter(new File("./dest/testsauv.xml"));
-					for (int i = 0; i < ldapMessageTree.getChildCount(); i++) {
-						DefaultMutableTreeNode tmpNode = (DefaultMutableTreeNode) ldapMessageTree
-								.getChildAt(i);
-						String st = toXML(tmpNode.getUserObject(), fw) + "\n";
-						try {
-							docOut.insertString(docOut.getLength(), st, boldText);
-						} catch (BadLocationException ble) {
-						}
-						for (int j = 0; j < tmpNode.getChildCount(); j++) {
-							st = toXML(((DefaultMutableTreeNode) tmpNode.getChildAt(j))
-									.getUserObject(), fw)
-									+ "\n";
-							try {
-								docOut.insertString(docOut.getLength(), st, boldItalicBlueText);
-							} catch (BadLocationException ble) {
-							}
-						}
-					}
-
-				} catch (IOException e) {
-				}
-			}
-		});
-		quit.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent action) {
-				System.out.println("EXIT");
-				try {
-					if (ldapProxy != null)
-						ldapProxy.stop();
-				} catch (Exception e) {
-					e.printStackTrace();
-				}
-
-				System.exit(0);
-			}
-		});
-
-		quit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
-		save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
-		
-		edit.add(pduView);	
-		
-		menuBar.add(file);
-		menuBar.add(edit);
-		return menuBar;
-	}
-
-	/**
-	 * DOCUMENT ME!
-	 */
-	public void run() {
-		this.setVisible(true);
-		this.launchLdapProxy(args);
-	}
-
-	/**
-	 * DOCUMENT ME!
-	 * 
-	 * @param args
-	 */
-	public static void main(String[] args) throws Exception {
-		MainFrame mf = new MainFrame();
-		mf.args = args;
-		mf.run();
-	}
-
-	public JTree getMessageTree() {
-		return messageTree;
-	}
-
-	public DefaultMutableTreeNode getTop() {
-		return top;
-	}
-
-	public DefaultMutableTreeNode getLdapMessageTree() {
-		return ldapMessageTree;
-	}
-
-	public void setLdapMessageTree(DefaultMutableTreeNode ldapMessageTree) {
-		this.ldapMessageTree = ldapMessageTree;
-	}
-
-	public SimpleAttributeSet getStyleByMessageType(int type) {
-		SimpleAttributeSet styledType;
-
-		switch (type) {
-		case 0:
-			styledType = boldItalicBlueText;
-			break;
-		case 1:
-			styledType = boldItalicBlueText;
-			break;
-		case 2:
-			styledType = boldItalicBlueText;
-			break;
-		case 3:
-			styledType = boldItalicRedText;
-			break;
-		case 4:
-			styledType = boldItalicBlueText;
-			break;
-		case 5:
-			styledType = boldItalicBlueText;
-			break;
-		case 6:
-			styledType = boldItalicBlueText;
-			break;
-		case 7:
-			styledType = boldItalicBlueText;
-			break;
-		case 8:
-			styledType = boldItalicBlueText;
-			break;
-		case 9:
-			styledType = boldItalicBlueText;
-			break;
-		case 10:
-			styledType = boldItalicBlueText;
-			break;
-		case 11:
-			styledType = boldItalicBlueText;
-			break;
-		case 12:
-			styledType = boldItalicBlueText;
-			break;
-		case 13:
-			styledType = boldItalicBlueText;
-			break;
-		case 14:
-			styledType = boldItalicBlueText;
-			break;
-		case 15:
-			styledType = boldItalicBlueText;
-			break;
-		case 16:
-			styledType = boldItalicBlueText;
-			break;
-		case 17:
-			styledType = boldItalicRedText;
-			break;
-		case 18:
-			styledType = boldItalicBlueText;
-			break;
-		case 19:
-			styledType = boldItalicBlueText;
-			break;
-		case -1:
-			styledType = boldItalicBlueText;
-			break;
-
-		default:
-			styledType = boldItalicBlueText;
-			break;
-		}
-		return styledType;
-	}
-
-	public String toXML(Object ob, FileWriter fw) {
-		try {
-			XStream xs = new XStream();
-			xs.toXML(ob, fw);
-			String st = xs.toXML(ob);
-			System.out.println(st);
-			return st;
-		} catch (Exception e) {
-			return "NOTHING";
-		}
-	}
-
-	public MainFrame getItSelf() {
-		return itSelf;
-	}
-
-	public void setItSelf(MainFrame itSelf) {
-		this.itSelf = itSelf;
-	}
-
-	public void treeCollapsed(TreeExpansionEvent tee) {
-		messageTree.setSelectionPath(tee.getPath());
-		// messageTree.setSelectionRow(0);
-
-	}
-
-	public void treeExpanded(TreeExpansionEvent tee) {
-		// messageTree.setSelectionRow(0);
-		messageTree.setSelectionPath(tee.getPath());
-	}
-
-	public void valueChanged(TreeSelectionEvent tse) {
-		textOut.setText("");
-		// there is only 2 depth level in thoses Tree.
-		DefaultMutableTreeNode node = (DefaultMutableTreeNode) messageTree
-				.getLastSelectedPathComponent();
-		if (node.equals(top)) {
-			System.out.println("First Element Selected!!");
-			return;
-		}
-		if (node == null) {
-			System.out.println("Can't Find Node !!! NULL");
-			return;
-
-		}
-		int index = top.getIndex(node);
-		int count = 0;
-		int childrenCount = top.getChildCount();
-		while ((index == -1) && (count < childrenCount)) {
-			index = top.getChildAt(count).getIndex(node);
-			count++;
-		}
-		count--;
-		if (index == -1) {
-			System.out.println("Can't Find Node !!! index -1");
-			return;
-		}
-		Object nodeInfo = node.getUserObject();
-		System.out.println("============================================");
-		System.out.println("NODE selected " + index + " :::: " + nodeInfo.toString());
-		TreeNode ldapNode;
-		if (!node.isLeaf()) {
-			// First Level
-			ldapNode = ldapMessageTree.getChildAt(index);
-		} else {
-			// second Level we take before the good sub tree to get the
-			// good leaf by its own index
-			ldapNode = ldapMessageTree.getChildAt(count).getChildAt(index);
-		}
-		
-		System.out.println("LDAP message associate ::: "
-				+ ((LdapMessageWithPDU) ((DefaultMutableTreeNode) ldapNode).getUserObject())
-						.getLdapMessage().toString());
-		System.out.println("============================================");
-
-		// textOut.setLogicalStyle(textOut.getStyle("regular"));
-		// textOut.setText(textOut.getText() + ldapNode.toString());
-		try {
-			LdapMessage ldapmess = ((LdapMessageWithPDU) ((DefaultMutableTreeNode) ldapNode)
-					.getUserObject()).getLdapMessage();
-			int type = ldapmess.getMessageType();
-			SimpleAttributeSet currentStyle = getStyleByMessageType(type);
-			docOut.insertString(docOut.getLength(), node.toString() + "\n", boldText);
-			if (node.isLeaf()) {
-				docOut.insertString(docOut.getLength(), ldapmess.toString(), currentStyle);
-				if(pduView.getState()){				
-					docOut.insertString(docOut.getLength(),SEPARATOR + " PDU  :: \n " +((LdapMessageWithPDU) ((DefaultMutableTreeNode) ldapNode)
-							.getUserObject()).getDumpBytes() + SEPARATOR, pduStyle);
-				}
-			}
-			
-			
-		} catch (Exception e) {// BadLocationException ble) {
-			System.err.println("Can not write data in Editor!!");
-		}
-
-	}
-
-	public DefaultTreeModel getTreeModel() {
-		return treeModel;
-	}
+public class MainFrame extends JFrame implements TreeSelectionListener, TreeExpansionListener
+{
+    // ~ Static fields/initializers
+    // -----------------------------------------------------------------
+    // Shut down the Serialization warning ...
+    public static final long       serialVersionUID = 1L;
+
+    /** frame itSelf */
+    private MainFrame              itSelf;
+
+    /** Frame and Application name */
+    public static final String     FRAME_NAME       = "LDAP Proxy GUI";
+
+    /** Default Frame default Size */
+    public static final Rectangle  FRAME_SIZE       = new Rectangle( 100, 100, 1000, 500 );
+
+    // ~ Instance fields
+    // ----------------------------------------------------------------------------
+
+    // ALL Panel
+    /** The splitted panel */
+    private JSplitPane             principalPanel;
+
+    /** DOCUMENT ME! */
+    private JScrollPane            jspIn;
+
+    /** DOCUMENT ME! */
+    private JScrollPane            jspOut;
+
+    /** DOCUMENT ME! */
+    private JTree                  messageTree;
+
+    /** DOCUMENT ME! */
+    private JTextPane              textOut;
+
+    // List of Menu
+    /** The menu bar */
+    private JMenuBar               menuBar          = new JMenuBar();
+
+    /** The file menu */
+    private JMenu                  fileMenu         = new JMenu( "File" );
+
+    /** The edit menu */
+    private JMenu                  editMenu         = new JMenu( "edit" );
+
+    /** The "New" menu item */
+    private JMenuItem              newMenuItem      = new JMenuItem( "New..." );
+
+    /** The "Load" menu item */
+    private JMenuItem              loadMenuItem     = new JMenuItem( "load" );
+
+    /** The "Save" menu item */
+    private JMenuItem              saveMenuItem     = new JMenuItem( "Save" );
+
+    /** The "Quit" menu item */
+    private JMenuItem              quitMenuItem     = new JMenuItem( "Quit" );
+
+    /** DOCUMENT ME! */
+    private JCheckBoxMenuItem      pduView          = new JCheckBoxMenuItem( "View PDU" );
+
+    /** DOCUMENT ME! */
+    private LdapProxy              ldapProxy;
+
+    /** DOCUMENT ME! */
+    private DefaultStyledDocument  docOut;
+
+    private String[]               args;
+
+    private DefaultMutableTreeNode top;
+
+    private DefaultMutableTreeNode ldapMessageTree;
+
+    private DefaultTreeModel       treeModel;
+
+    // STYLE
+    private SimpleAttributeSet     boldItalicRedText;
+
+    private SimpleAttributeSet     boldText;
+
+    private SimpleAttributeSet     boldItalicBlueText;
+
+    private SimpleAttributeSet     pduStyle;
+
+    final static String            SEPARATOR        = "\n====================================\n";
+
+    // ~ Constructors
+    // -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new MainFrame object.
+     * 
+     * @throws HeadlessException
+     *             DOCUMENT ME!
+     * @throws UnknownHostException
+     *             DOCUMENT ME!
+     * @throws IOException
+     *             DOCUMENT ME!
+     */
+    public MainFrame() throws HeadlessException, UnknownHostException, IOException
+    {
+        super();
+        initFrame();
+
+    }
+
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+
+    public void initFrame()
+    {
+        setItSelf( this );
+        setTitle( FRAME_NAME );
+        setBounds( FRAME_SIZE );
+        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
+        setJMenuBar( initMenuBar() );
+        top = new DefaultMutableTreeNode( "Start" );
+        treeModel = new DefaultTreeModel( top );
+        messageTree = new JTree( treeModel );
+        ldapMessageTree = new DefaultMutableTreeNode( "Start Ldap message" );
+
+        messageTree.addTreeExpansionListener( this );
+        messageTree.addTreeSelectionListener( this );
+
+        messageTree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
+        initRenderTree();
+        messageTree.setBackground( Color.lightGray );
+        messageTree.putClientProperty( "JTree.lineStyle", "None" );
+
+        initStyleForEditing();
+
+        messageTree.setEditable( false );
+        // messageTree.setRootVisible(false);
+
+        textOut = new JTextPane( docOut );
+        textOut.setEditable( false );
+
+        jspIn = new JScrollPane();
+        jspIn.getViewport().add( messageTree );
+
+        jspOut = new JScrollPane();
+        jspOut.getViewport().add( textOut );
+
+        principalPanel = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, jspIn, jspOut );
+        principalPanel.setOneTouchExpandable( true );
+        principalPanel.setDividerLocation( 500 );
+
+        getContentPane().add( principalPanel );
+    }
+
+    public void initStyleForEditing()
+    {
+        // DEFAULT STYLE
+        Style def = StyleContext.getDefaultStyleContext().getStyle( StyleContext.DEFAULT_STYLE );
+        docOut = new DefaultStyledDocument();
+        // other style could be define later // COMMENT TO BE DELETED AFTER DEV
+
+        boldItalicRedText = new SimpleAttributeSet();
+        StyleConstants.setForeground( boldItalicRedText, Color.red );
+        StyleConstants.setBold( boldItalicRedText, true );
+        StyleConstants.setItalic( boldItalicRedText, true );
+        StyleConstants.setFontSize( boldItalicRedText, 12 );
+
+        boldItalicBlueText = new SimpleAttributeSet();
+        StyleConstants.setForeground( boldItalicBlueText, Color.blue );
+        StyleConstants.setBold( boldItalicBlueText, true );
+        StyleConstants.setItalic( boldItalicBlueText, true );
+        StyleConstants.setFontSize( boldItalicBlueText, 12 );
+
+        boldText = new SimpleAttributeSet();
+        StyleConstants.setFontSize( boldText, 14 );
+        StyleConstants.setBold( boldText, true );
+
+        pduStyle = new SimpleAttributeSet();
+        StyleConstants.setFontSize( pduStyle, 12 );
+        StyleConstants.setBold( pduStyle, true );
+        StyleConstants.setForeground( pduStyle, Color.DARK_GRAY );
+
+    }
+
+    /**
+     * DOCUMENT ME!
+     */
+    public void launchLdapProxy( String[] args )
+    {
+        ldapProxy = new LdapProxy();
+        ldapProxy.setMainFrame( this );
+        // ldapProxy.setTextIn( messageTree );
+        // ldapProxy.setTextOut( textOut );
+
+        ldapProxy.likeMain( args );
+
+    }
+
+    /** Returns an ImageIcon, or null if the path was invalid. */
+    protected static ImageIcon createImageIcon( String path )
+    {
+        // java.net.URL imgURL = MainFrame.class.getResource(path);
+        try
+        {
+            return new ImageIcon( path );
+        }
+        catch ( Exception e )
+        {
+            return null;
+        }
+    }
+
+    /**
+     * DOCUMENT ME!
+     */
+    public void initRenderTree()
+    {
+        ImageIcon leafIcon = createImageIcon( "./images/gnome-icone-001.gif" );
+        ImageIcon icon = createImageIcon( "./images/gnome-icone-002.gif" );
+        if ( ( leafIcon != null ) && ( icon != null ) )
+        {
+            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
+            renderer.setLeafIcon( leafIcon );
+            messageTree.setCellRenderer( renderer );
+            renderer.setFont( new Font( "treeFont", Font.BOLD, 12 ) );
+            renderer.setBackgroundNonSelectionColor( Color.lightGray );
+            renderer.setBackgroundSelectionColor( Color.white );
+            renderer.setOpenIcon( icon );
+            renderer.setClosedIcon( icon );
+        }
+
+    }
+
+    /**
+     * DOCUMENT ME!
+     * 
+     * @return DOCUMENT ME!
+     */
+    private JMenuBar initMenuBar()
+    {
+        fileMenu.add( newMenuItem );
+        fileMenu.add( loadMenuItem );
+        fileMenu.add( saveMenuItem );
+        fileMenu.addSeparator();
+        fileMenu.add( quitMenuItem );
+        newMenuItem.addActionListener( new ActionListener()
+        {
+            public void actionPerformed( ActionEvent action )
+            {
+                // top.removeAllChildren();
+                // TO DO BETTER !!!!!
+                top = new DefaultMutableTreeNode( "Start" );
+                treeModel.setRoot( top );
+            }
+        } );
+        saveMenuItem.addActionListener( new ActionListener()
+        {
+            public void actionPerformed( ActionEvent action )
+            {
+                try
+                {
+                    FileWriter fw = new FileWriter( new File( "./dest/testsauv.xml" ) );
+                    for ( int i = 0; i < ldapMessageTree.getChildCount(); i++ )
+                    {
+                        DefaultMutableTreeNode tmpNode = (DefaultMutableTreeNode) ldapMessageTree.getChildAt( i );
+                        String st = toXML( tmpNode.getUserObject(), fw ) + "\n";
+                        try
+                        {
+                            docOut.insertString( docOut.getLength(), st, boldText );
+                        }
+                        catch ( BadLocationException ble )
+                        {
+                        }
+                        for ( int j = 0; j < tmpNode.getChildCount(); j++ )
+                        {
+                            st = toXML( ( (DefaultMutableTreeNode) tmpNode.getChildAt( j ) ).getUserObject(), fw )
+                                    + "\n";
+                            try
+                            {
+                                docOut.insertString( docOut.getLength(), st, boldItalicBlueText );
+                            }
+                            catch ( BadLocationException ble )
+                            {
+                            }
+                        }
+                    }
+
+                }
+                catch ( IOException e )
+                {
+                }
+            }
+        } );
+        quitMenuItem.addActionListener( new ActionListener()
+        {
+            public void actionPerformed( ActionEvent action )
+            {
+                System.out.println( "EXIT" );
+                try
+                {
+                    if ( ldapProxy != null )
+                        ldapProxy.stop();
+                }
+                catch ( Exception e )
+                {
+                    e.printStackTrace();
+                }
+
+                System.exit( 0 );
+            }
+        } );
+
+        quitMenuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK ) );
+        saveMenuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK ) );
+
+        editMenu.add( pduView );
+
+        menuBar.add( fileMenu );
+        menuBar.add( editMenu );
+        return menuBar;
+    }
+
+    /**
+     * DOCUMENT ME!
+     */
+    public void run()
+    {
+        this.setVisible( true );
+        this.launchLdapProxy( args );
+    }
+
+    /**
+     * DOCUMENT ME!
+     * 
+     * @param args
+     */
+    public static void main( String[] args ) throws Exception
+    {
+        MainFrame mf = new MainFrame();
+        mf.args = args;
+        mf.run();
+    }
+
+    public JTree getMessageTree()
+    {
+        return messageTree;
+    }
+
+    public DefaultMutableTreeNode getTop()
+    {
+        return top;
+    }
+
+    public DefaultMutableTreeNode getLdapMessageTree()
+    {
+        return ldapMessageTree;
+    }
+
+    public void setLdapMessageTree( DefaultMutableTreeNode ldapMessageTree )
+    {
+        this.ldapMessageTree = ldapMessageTree;
+    }
+
+    public SimpleAttributeSet getStyleByMessageType( int type )
+    {
+        SimpleAttributeSet styledType;
+
+        switch ( type )
+        {
+            case 0 :
+                styledType = boldItalicBlueText;
+                break;
+            case 1 :
+                styledType = boldItalicBlueText;
+                break;
+            case 2 :
+                styledType = boldItalicBlueText;
+                break;
+            case 3 :
+                styledType = boldItalicRedText;
+                break;
+            case 4 :
+                styledType = boldItalicBlueText;
+                break;
+            case 5 :
+                styledType = boldItalicBlueText;
+                break;
+            case 6 :
+                styledType = boldItalicBlueText;
+                break;
+            case 7 :
+                styledType = boldItalicBlueText;
+                break;
+            case 8 :
+                styledType = boldItalicBlueText;
+                break;
+            case 9 :
+                styledType = boldItalicBlueText;
+                break;
+            case 10 :
+                styledType = boldItalicBlueText;
+                break;
+            case 11 :
+                styledType = boldItalicBlueText;
+                break;
+            case 12 :
+                styledType = boldItalicBlueText;
+                break;
+            case 13 :
+                styledType = boldItalicBlueText;
+                break;
+            case 14 :
+                styledType = boldItalicBlueText;
+                break;
+            case 15 :
+                styledType = boldItalicBlueText;
+                break;
+            case 16 :
+                styledType = boldItalicBlueText;
+                break;
+            case 17 :
+                styledType = boldItalicRedText;
+                break;
+            case 18 :
+                styledType = boldItalicBlueText;
+                break;
+            case 19 :
+                styledType = boldItalicBlueText;
+                break;
+            case -1 :
+                styledType = boldItalicBlueText;
+                break;
+
+            default :
+                styledType = boldItalicBlueText;
+                break;
+        }
+        return styledType;
+    }
+
+    public String toXML( Object ob, FileWriter fw )
+    {
+        try
+        {
+            XStream xs = new XStream();
+            xs.toXML( ob, fw );
+            String st = xs.toXML( ob );
+            System.out.println( st );
+            return st;
+        }
+        catch ( Exception e )
+        {
+            return "NOTHING";
+        }
+    }
+
+    public MainFrame getItSelf()
+    {
+        return itSelf;
+    }
+
+    public void setItSelf( MainFrame itSelf )
+    {
+        this.itSelf = itSelf;
+    }
+
+    public void treeCollapsed( TreeExpansionEvent tee )
+    {
+        messageTree.setSelectionPath( tee.getPath() );
+        // messageTree.setSelectionRow(0);
+
+    }
+
+    public void treeExpanded( TreeExpansionEvent tee )
+    {
+        // messageTree.setSelectionRow(0);
+        messageTree.setSelectionPath( tee.getPath() );
+    }
+
+    public void valueChanged( TreeSelectionEvent tse )
+    {
+        textOut.setText( "" );
+        // there is only 2 depth level in thoses Tree.
+        DefaultMutableTreeNode node = (DefaultMutableTreeNode) messageTree.getLastSelectedPathComponent();
+        if ( node.equals( top ) )
+        {
+            System.out.println( "First Element Selected!!" );
+            return;
+        }
+        if ( node == null )
+        {
+            System.out.println( "Can't Find Node !!! NULL" );
+            return;
+
+        }
+        int index = top.getIndex( node );
+        int count = 0;
+        int childrenCount = top.getChildCount();
+        while ( ( index == -1 ) && ( count < childrenCount ) )
+        {
+            index = top.getChildAt( count ).getIndex( node );
+            count++;
+        }
+        count--;
+        if ( index == -1 )
+        {
+            System.out.println( "Can't Find Node !!! index -1" );
+            return;
+        }
+        Object nodeInfo = node.getUserObject();
+        System.out.println( "============================================" );
+        System.out.println( "NODE selected " + index + " :::: " + nodeInfo.toString() );
+        TreeNode ldapNode;
+        if ( !node.isLeaf() )
+        {
+            // First Level
+            ldapNode = ldapMessageTree.getChildAt( index );
+        }
+        else
+        {
+            // second Level we take before the good sub tree to get the
+            // good leaf by its own index
+            ldapNode = ldapMessageTree.getChildAt( count ).getChildAt( index );
+        }
+
+        System.out.println( "LDAP message associate ::: "
+                + ( (LdapMessageWithPDU) ( (DefaultMutableTreeNode) ldapNode ).getUserObject() ).getLdapMessage()
+                        .toString() );
+        System.out.println( "============================================" );
+
+        // textOut.setLogicalStyle(textOut.getStyle("regular"));
+        // textOut.setText(textOut.getText() + ldapNode.toString());
+        try
+        {
+            LdapMessage ldapmess = ( (LdapMessageWithPDU) ( (DefaultMutableTreeNode) ldapNode ).getUserObject() )
+                    .getLdapMessage();
+            int type = ldapmess.getMessageType();
+            SimpleAttributeSet currentStyle = getStyleByMessageType( type );
+            docOut.insertString( docOut.getLength(), node.toString() + "\n", boldText );
+            if ( node.isLeaf() )
+            {
+                docOut.insertString( docOut.getLength(), ldapmess.toString(), currentStyle );
+                if ( pduView.getState() )
+                {
+                    docOut.insertString( docOut.getLength(), SEPARATOR
+                            + " PDU  :: \n "
+                            + ( (LdapMessageWithPDU) ( (DefaultMutableTreeNode) ldapNode ).getUserObject() )
+                                    .getDumpBytes() + SEPARATOR, pduStyle );
+                }
+            }
+
+        }
+        catch ( Exception e )
+        {// BadLocationException ble) {
+            System.err.println( "Can not write data in Editor!!" );
+        }
+
+    }
+
+    public DefaultTreeModel getTreeModel()
+    {
+        return treeModel;
+    }
 
 }

Modified: directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/LdapMessageWithPDU.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/LdapMessageWithPDU.java?rev=278921&r1=278920&r2=278921&view=diff
==============================================================================
--- directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/LdapMessageWithPDU.java (original)
+++ directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/LdapMessageWithPDU.java Mon Sep  5 23:01:18 2005
@@ -1,37 +1,67 @@
+/*
+ *   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.ldap.proxy.impl;
 
 import org.apache.asn1new.ldap.pojo.LdapMessage;
 
-public class LdapMessageWithPDU {
-
-	private String dumpBytes;
-
-	private LdapMessage ldapMessage;
-
-	private int messageId;
-
-	public String getDumpBytes() {
-		return dumpBytes;
-	}
-
-	public void setDumpBytes(String dumpBytes) {
-		this.dumpBytes = dumpBytes;
-	}
-
-	public LdapMessage getLdapMessage() {
-		return ldapMessage;
-	}
-
-	public void setLdapMessage(LdapMessage ldapMessage) {
-		this.ldapMessage = ldapMessage;
-	}
-
-	public int getMessageId() {
-		return messageId;
-	}
-
-	public void setMessageId(int messageId) {
-		this.messageId = messageId;
-	}
-
+/**
+ * A LdapMessage container
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapMessageWithPDU
+{
+    /** The PDU */
+    private String      dumpBytes;
+
+    /** The ldapMessage */
+    private LdapMessage ldapMessage;
+
+    /** The ldap MessaheId */
+    private int         messageId;
+
+    public String getDumpBytes()
+    {
+        return dumpBytes;
+    }
+
+    public void setDumpBytes( String dumpBytes )
+    {
+        this.dumpBytes = dumpBytes;
+    }
+
+    public LdapMessage getLdapMessage()
+    {
+        return ldapMessage;
+    }
+
+    public void setLdapMessage( LdapMessage ldapMessage )
+    {
+        this.ldapMessage = ldapMessage;
+    }
+
+    public int getMessageId()
+    {
+        return messageId;
+    }
+
+    public void setMessageId( int messageId )
+    {
+        this.messageId = messageId;
+    }
 }

Modified: directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/LdapProxy.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/LdapProxy.java?rev=278921&r1=278920&r2=278921&view=diff
==============================================================================
--- directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/LdapProxy.java (original)
+++ directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/LdapProxy.java Mon Sep  5 23:01:18 2005
@@ -1,108 +1,192 @@
+/*
+ *   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.ldap.proxy.impl;
 
 import java.net.ServerSocket;
 import java.net.Socket;
 
 import org.apache.ldap.proxy.gui.MainFrame;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-public class LdapProxy {
-
-	public static final String usageArgs = " <localport> <host> <port> <timeout_ms>";
-
-	static int clientCount;
-
-	private ProxyConnection proxyConnection;
-
-	MainFrame mainFrame;
-
-	public static synchronized void quit(long t) {
-		System.out.println("...quit after waiting " + t + " ms");
-		clientCount--;
-	}
-
-	public void run(int localport, String host, int port, long timeout) {
-		try {
-			ServerSocket sSocket = new ServerSocket(localport);
-
-			while (true) {
-				Socket cSocket = null;
-				try {
-					System.out.println("listening...");
-					cSocket = sSocket.accept();
-
-					if (cSocket != null) {
-						clientCount++;
-						System.out.println("accepted as #" + clientCount + ":" + cSocket);
-						proxyConnection = new ProxyConnection(cSocket, host, port, timeout);
-						proxyConnection.setMainFrame(mainFrame);
-						proxyConnection.run();
-					}
-				} catch (Exception e) {
-					e.printStackTrace(System.err);
-				}
-				try {
-					cSocket.close();
-				} catch (Exception e) {
-					// fall thru
-				}
-			}
-		} catch (Throwable t) {
-			t.printStackTrace(System.err);
-		}
-	}
-
-	public void stop() {
-		proxyConnection.interrupt();
-	}
-
-	public static void main(String[] argv) {
-		LdapProxy self = new LdapProxy();
-
-		if (argv.length >= 3) {
-			int localport = Integer.parseInt(argv[0]);
-			String url = argv[1];
-			int port = Integer.parseInt(argv[2]);
-			int timeout = 300000;
-			if (argv.length >= 4) {
-				try {
-					timeout = Integer.parseInt(argv[3]);
-				} catch (Exception e) {
-					System.err.println("Time Out incorrect in lanched command line!! TIMEOUT = "
-							+ argv[3]);
-				}
-			}
-			if (timeout == 0)
-				timeout = 300000;
-			self.run(localport, url, port, timeout);
-		} else {
-			System.err.println("usage: java " + self.getClass().getName() + usageArgs);
-		}
-	}
-
-	/*
-	 * public void setTextIn(JTextPane textIn) { LdapProxy.textIn = textIn; }
-	 * public void setTextOut(JTextPane textOut) { LdapProxy.textOut = textOut; }
-	 */
-	public void likeMain(String[] argv) {
-		if (argv.length >= 3) {
-			int localport = Integer.parseInt(argv[0]);
-			String url = argv[1];
-			int port = Integer.parseInt(argv[2]);
-			int timeout = 30000;
-
-			try {
-				timeout = Integer.parseInt(argv[3]);
-			} catch (Exception e) {
-			}
-
-			run(localport, url, port, timeout);
-		} else {
-			System.err.println("usage: java " + this.getClass().getName() + usageArgs);
-		}
-	}
-
-	public void setMainFrame(MainFrame mainframe) {
-		this.mainFrame = mainframe;
-	}
-
+/**
+ * 
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapProxy
+{
+    /** The logger */
+    private static final Logger log             = LoggerFactory.getLogger( LdapProxy.class );
+
+    /** The usage string */
+    public static final String  USAGE_ARGS      = " <localport> <host> <port> <timeout>";
+
+    /** Default timeout in milli seconds */
+    public static final int     DEFAULT_TIMEOUT = 30000;
+
+    static int                  clientCount;
+
+    private ProxyConnection     proxyConnection;
+
+    MainFrame                   mainFrame;
+
+    /**
+     * Quit the current connection.
+     * 
+     * @param t
+     *            The timeout
+     */
+    public static synchronized void quit( long t )
+    {
+        log.info( "...quit after waiting " + ( t / 1000 ) + " s" );
+        clientCount--;
+    }
+
+    /**
+     * The main loop.
+     * 
+     * @param localport
+     * @param host
+     * @param port
+     * @param timeout
+     */
+    public void run( int localport, String host, int port, long timeout )
+    {
+        try
+        {
+            ServerSocket sSocket = new ServerSocket( localport );
+
+            while ( true )
+            {
+                Socket cSocket = null;
+                
+                try
+                {
+                    log.debug( "listening..." );
+                    cSocket = sSocket.accept();
+
+                    if ( cSocket != null )
+                    {
+                        clientCount++;
+
+                        if ( log.isDebugEnabled() )
+                        {
+                            log.debug( "accepted as #" + clientCount + ":" + cSocket );
+                        }
+
+                        proxyConnection = new ProxyConnection( cSocket, host, port, timeout );
+                        proxyConnection.setMainFrame( mainFrame );
+                        proxyConnection.run();
+                    }
+                }
+                catch ( Exception e )
+                {
+                    e.printStackTrace( System.err );
+                }
+                try
+                {
+                    cSocket.close();
+                }
+                catch ( Exception e )
+                {
+                    // fall thru
+                }
+            }
+        }
+        catch ( Throwable t )
+        {
+            t.printStackTrace( System.err );
+        }
+    }
+
+    public void stop()
+    {
+        proxyConnection.interrupt();
+    }
+
+    public void likeMain( String[] argv )
+    {
+        if ( argv.length >= 3 )
+        {
+            int localport = Integer.parseInt( argv[0] );
+            String url = argv[1];
+            int port = Integer.parseInt( argv[2] );
+            int timeout = DEFAULT_TIMEOUT;
+
+            try
+            {
+                timeout = Integer.parseInt( argv[3] );
+            }
+            catch ( Exception e )
+            {
+            }
+
+            run( localport, url, port, timeout );
+        }
+        else
+        {
+            System.err.println( "usage: java " + this.getClass().getName() + USAGE_ARGS );
+        }
+    }
+    
+    public void setMainFrame( MainFrame mainframe )
+    {
+        this.mainFrame = mainframe;
+    }
+
+    /**
+     * Main method
+     * @param argv The parameters
+     */
+    public static void main( String[] argv )
+    {
+        LdapProxy self = new LdapProxy();
+
+        if ( argv.length >= 3 )
+        {
+            int localport = Integer.parseInt( argv[0] );
+            String url = argv[1];
+            int port = Integer.parseInt( argv[2] );
+            int timeout = DEFAULT_TIMEOUT;
+            
+            if ( argv.length >= 4 )
+            {
+                try
+                {
+                    timeout = Integer.parseInt( argv[3] );
+                }
+                catch ( Exception e )
+                {
+                    System.err.println( "Time Out incorrect in lanched command line!! TIMEOUT = " + argv[3] );
+                }
+            }
+            
+            if ( timeout == 0 )
+            {
+                timeout = DEFAULT_TIMEOUT;
+            }
+            
+            self.run( localport, url, port, timeout );
+        }
+        else
+        {
+            System.err.println( "usage: java " + self.getClass().getName() + USAGE_ARGS );
+        }
+    }
 }// class

Modified: directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/ProxyConnection.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/ProxyConnection.java?rev=278921&r1=278920&r2=278921&view=diff
==============================================================================
--- directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/ProxyConnection.java (original)
+++ directory/sandbox/trunk/proxy/src/java/main/org/apache/ldap/proxy/impl/ProxyConnection.java Mon Sep  5 23:01:18 2005
@@ -1,3 +1,20 @@
+/*
+ *   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.ldap.proxy.impl;
 
 import java.io.BufferedOutputStream;
@@ -9,7 +26,6 @@
 import java.util.Date;
 
 import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.TreePath;
 
 import org.apache.asn1.codec.DecoderException;
 import org.apache.asn1new.ber.Asn1Decoder;
@@ -20,334 +36,383 @@
 import org.apache.asn1new.util.StringUtils;
 import org.apache.ldap.proxy.gui.MainFrame;
 
-class ProxyConnection extends Thread {
-
-	Socket fromClient;
-
-	String host;
-
-	int port;
-
-	long timeout;
-
-	MainFrame mainFrame;
-
-	int lastMessageId = -1;
-
-	DefaultMutableTreeNode lastNode;
-
-	DefaultMutableTreeNode lastMessNode;
-
-	int currentCount = 0;
-
-	ProxyConnection(Socket s, String host, int port, long timeout) {
-		fromClient = s;
-		this.host = host;
-		this.port = port;
-		this.timeout = timeout;
-
-	}
-
-	private String decode(ByteBuffer buffer) throws DecoderException {
-
-		DefaultMutableTreeNode mess;
-
-		// DefaultMutableTreeNode messTrue;
-		DefaultMutableTreeNode messTrue;
-
-		Asn1Decoder ldapDecoder = new LdapDecoder();
-
-		// Allocate a LdapMessageContainer Container
-		IAsn1Container ldapMessageContainer = new LdapMessageContainer();
-
-		// Decode the PDU
-		ldapDecoder.decode(buffer, ldapMessageContainer);
-		// Check that everything is OK
-		LdapMessage ldapmessage = ((LdapMessageContainer) ldapMessageContainer).getLdapMessage();
-		LdapMessageWithPDU message = new LdapMessageWithPDU();
-
-		message.setDumpBytes(org.apache.asn1new.util.StringUtils.dumpBytes(buffer.array()));
-		message.setLdapMessage(ldapmessage);
-		message.setMessageId(ldapmessage.getMessageId());
-
-		// Ici on test pour ne pas créer 2 entré avec le meme messageID;
-		if (message.getMessageId() != lastMessageId) {
-			mess = new DefaultMutableTreeNode(transformToStringType(ldapmessage.getMessageType())
-					+ " [Id = " + ((LdapMessage) ldapmessage).getMessageId() + " ]");
-
-			messTrue = new DefaultMutableTreeNode(message);
-			lastNode = mess;
-			lastMessNode = messTrue;
-			lastMessageId = message.getMessageId();
-			// mainFrame.getTop().add(mess);
-			mainFrame.getTreeModel().insertNodeInto(mess, mainFrame.getTop(),
-					mainFrame.getTop().getChildCount());
-			mainFrame.getLdapMessageTree().add(messTrue);
-			currentCount = 1;
-
-		} else {
-			mess = lastNode;
-			messTrue = lastMessNode;
-			currentCount++;
-		}
-
-		// String type = message.getProtocolOp().getClass().getSimpleName();
-		String type = transformToStringType(ldapmessage.getMessageType());
-
-		// DefaultMutableTreeNode request = new DefaultMutableTreeNode(type +"
-		// ==>" + message.toString());
-		DefaultMutableTreeNode request = new DefaultMutableTreeNode(type + " N° " + currentCount);
-		// mess.add(request);
-		mainFrame.getTreeModel().insertNodeInto(request, mess, mess.getChildCount());
-
-		messTrue.add(new DefaultMutableTreeNode(message));
-
-		// mainFrame.repaint();
-		// mainFrame.getTreeModel().reload(mainFrame.getTop());
-		return message.getLdapMessage().toString();
-	}
-
-	public String transformToStringType(int type) {
-		String stringType;
-
-		switch (type) {
-		case 0:
-			stringType = "ABANDON REQUEST";
-			break;
-		case 1:
-			stringType = "ADD REQUEST";
-			break;
-		case 2:
-			stringType = "ADD RESPONSE";
-			break;
-		case 3:
-			stringType = "BIND REQUEST";
-			break;
-		case 4:
-			stringType = "BIND RESPONSE";
-			break;
-		case 5:
-			stringType = "COMPARE REQUEST";
-			break;
-		case 6:
-			stringType = "COMPARE RESPONSE";
-			break;
-		case 7:
-			stringType = "DEL REQUEST";
-			break;
-		case 8:
-			stringType = "DEL RESPONSE";
-			break;
-		case 9:
-			stringType = "EXTENDED REQUEST";
-			break;
-		case 10:
-			stringType = "EXTENDED RESPONSE";
-			break;
-		case 11:
-			stringType = "MODIFYDN REQUEST";
-			break;
-		case 12:
-			stringType = "MODIFYDN RESPONSE";
-			break;
-		case 13:
-			stringType = "MODIFY REQUEST";
-			break;
-		case 14:
-			stringType = "MODIFY RESPONSE";
-			break;
-		case 15:
-			stringType = "SEARCH REQUEST";
-			break;
-		case 16:
-			stringType = "SEARCH RESULT DONE";
-			break;
-		case 17:
-			stringType = "SEARCH RESULT ENTRY";
-			break;
-		case 18:
-			stringType = "SEARCH RESULT REFERENCE";
-			break;
-		case 19:
-			stringType = "UNBIND REQUEST";
-			break;
-		case -1:
-			stringType = "UNKNOWN";
-			break;
-
-		default:
-			stringType = "UNKNOWN";
-			break;
-		}
-		return stringType;
-	}
-
-	public void run() {
-		InputStream clientIn = null;
-		OutputStream clientOut = null;
-		InputStream serverIn = null;
-		OutputStream serverOut = null;
-		Socket toServer = null;
-		int r0 = -1;
-		int r1 = -1;
-		int ch = -1;
-		int i = -1;
-		long time0 = System.currentTimeMillis();
-		long time1 = time0 + timeout;
-
-		try {
-			toServer = new Socket(host, port);
-			System.out.println("open connection to:" + toServer + "(timeout=" + timeout + " ms)");
-			clientIn = fromClient.getInputStream();
-			clientOut = new BufferedOutputStream(fromClient.getOutputStream());
-			serverIn = toServer.getInputStream();
-			serverOut = new BufferedOutputStream(toServer.getOutputStream());
-
-			while (r0 != 0 || r1 != 0 || (time1 - time0) <= timeout) {
-				r0 = clientIn.available();
-
-				if (r0 != 0) {
-					System.out.println("");
-					// LdapProxy.setTextIn("<<<" + r0 + " bytes from client
-					// \n","red");
-					System.out.println("");
-					System.out.println("<<<" + r0 + " bytes from client");
-					System.out.println("<<<" + r1 + " bytes from server");
-				}
-
-				ByteBuffer bb = null;
-
-				while ((r0 = clientIn.available()) > 0) {
-					byte[] in = new byte[r0];
-					int k = 0;
-
-					for (i = 0; i < r0; i++) {
-						ch = clientIn.read();
-
-						if (ch != -1) {
-							in[k++] = (byte) ch;
-							serverOut.write(ch);
-						} else {
-							System.out.println("client stream closed");
-							// LdapProxy.setTextIn("client stream closed
-							// \n","redbold");
-						}
-					}
-
-					bb = ByteBuffer.allocate(r0);
-					bb.put(in);
-					bb.flip();
-					String result = decode(bb);
-					/*
-					 * LdapProxy.setTextIn("--->>>\n", "regular");
-					 * LdapProxy.setTextIn(result, "regular");
-					 * LdapProxy.setTextIn("----------------------------------\n",
-					 * "regular");
-					 */
-
-					time0 = System.currentTimeMillis();
-					serverOut.flush();
-				}
-
-				bb = null;
-
-				while ((r1 = serverIn.available()) > 0) {
-					System.out.println("");
-					System.out.println(">>>" + r1 + " bytes from server");
-					// LdapProxy.setTextOut(">>>" + r1 + " bytes from server
-					// \n","red");
-					System.out.println("");
-					System.out.println(">>>" + r1 + " bytes from server");
-
-					byte[] out = new byte[r1];
-					int k = 0;
-
-					for (i = 0; i < r1; i++) {
-						ch = serverIn.read();
-
-						if (ch != -1) {
-							out[k++] = (byte) ch;
-						} else {
-							System.out.println("server stream closed");
-							// LdapProxy.setTextOut("server stream closed
-							// \n","redbold");
-							break;
-						}
-
-						clientOut.write(ch);
-					}
-
-					bb = ByteBuffer.allocate(r1);
-					bb.put(out);
-					bb.flip();
-
-					while (true) {
-						try {
-							String result = decode(bb);
-							System.out.println(result);
-							/*
-							 * LdapProxy.setTextOut("<<<---\n", "blue");
-							 * LdapProxy.setTextOut(result, "blue");
-							 * LdapProxy.setTextOut("----------------------------------\n",
-							 * "regular");
-							 */
-							if (bb.hasRemaining() == false) {
-								break;
-							}
-						} catch (DecoderException de) {
-							StringBuffer result = new StringBuffer();
-							result.append(de.getMessage()).append('\n');
-
-							byte[] tmp = new byte[out.length - bb.position()];
-							System
-									.arraycopy(out, bb.position(), tmp, 0, out.length
-											- bb.position());
-							result.append(StringUtils.dumpBytes(tmp));
-
-							System.out.println(result);
-							/*
-							 * LdapProxy.setTextOut("<<<---\n", "regular");
-							 * LdapProxy.setTextOut(new String(tmp), "regular");
-							 * LdapProxy.setTextOut("----------------------------------\n",
-							 * "regular");
-							 */
-							break;
-						}
-					}
-
-					time0 = new Date().getTime();
-					clientOut.flush();
-				}
-				if (r0 == 0 && r1 == 0) {
-					time1 = new Date().getTime();
-					Thread.sleep(100);
-					// Proxy.display("waiting:"+(time1-time0)+" ms");
-				}
-			}
-		} catch (Throwable t) {
-			System.out.println("i=" + i + " ch=" + ch);
-			t.printStackTrace(System.err);
-		} finally {
-			try {
-				clientIn.close();
-				clientOut.close();
-				serverIn.close();
-				serverOut.close();
-				fromClient.close();
-				toServer.close();
-				LdapProxy.quit(time1 - time0);
-			} catch (Exception e) {
-				e.printStackTrace(System.err);
-			}
-		}
-	}
-
-	/*
-	 * public void setTextIn(JTextPane textIn) { this.textIn = textIn; } public
-	 * void setTextOut(JTextPane textOut) { this.textOut = textOut; }
-	 */
-
-	public void setMainFrame(MainFrame mainframe) {
-		this.mainFrame = mainframe;
-	}
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+class ProxyConnection extends Thread
+{
+
+    Socket                 fromClient;
+
+    String                 host;
+
+    int                    port;
+
+    long                   timeout;
+
+    MainFrame              mainFrame;
+
+    int                    lastMessageId = -1;
+
+    DefaultMutableTreeNode lastNode;
+
+    DefaultMutableTreeNode lastMessNode;
+
+    int                    currentCount  = 0;
+
+    ProxyConnection(Socket s, String host, int port, long timeout)
+    {
+        fromClient = s;
+        this.host = host;
+        this.port = port;
+        this.timeout = timeout;
+
+    }
+
+    private String decode( ByteBuffer buffer ) throws DecoderException
+    {
+        int position = buffer.position();
+
+        DefaultMutableTreeNode mess;
+
+        // DefaultMutableTreeNode messTrue;
+        DefaultMutableTreeNode messTrue;
+
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        // Allocate a LdapMessageContainer Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the PDU
+        ldapDecoder.decode( buffer, ldapMessageContainer );
+        // Check that everything is OK
+        LdapMessage ldapmessage = ( (LdapMessageContainer) ldapMessageContainer ).getLdapMessage();
+        LdapMessageWithPDU message = new LdapMessageWithPDU();
+        
+
+        message.setLdapMessage( ldapmessage );
+        message.setMessageId( ldapmessage.getMessageId() );
+
+        // Ici on test pour ne pas cr�er 2 entr� avec le meme messageID;
+        if ( message.getMessageId() != lastMessageId )
+        {
+            mess = new DefaultMutableTreeNode( transformToStringType( ldapmessage.getMessageType() ) + " [Id = "
+                    + ( (LdapMessage) ldapmessage ).getMessageId() + " ]" );
+
+            messTrue = new DefaultMutableTreeNode( message );
+            lastNode = mess;
+            lastMessNode = messTrue;
+            lastMessageId = message.getMessageId();
+            // mainFrame.getTop().add(mess);
+            mainFrame.getTreeModel().insertNodeInto( mess, mainFrame.getTop(), mainFrame.getTop().getChildCount() );
+            mainFrame.getLdapMessageTree().add( messTrue );
+            currentCount = 1;
+
+        }
+        else
+        {
+            mess = lastNode;
+            messTrue = lastMessNode;
+            currentCount++;
+        }
+
+        // String type = message.getProtocolOp().getClass().getSimpleName();
+        String type = transformToStringType( ldapmessage.getMessageType() );
+
+        // DefaultMutableTreeNode request = new DefaultMutableTreeNode(type +"
+        // ==>" + message.toString());
+        DefaultMutableTreeNode request = new DefaultMutableTreeNode( type + " N� " + currentCount );
+        // mess.add(request);
+        mainFrame.getTreeModel().insertNodeInto( request, mess, mess.getChildCount() );
+
+        messTrue.add( new DefaultMutableTreeNode( message ) );
+
+        int pduLength = buffer.position() - position;
+        byte[] bytes = buffer.array();
+        byte[] newBytes = new byte[pduLength];
+        System.arraycopy(bytes, position, newBytes, 0, pduLength );
+        
+        message.setDumpBytes( org.apache.asn1new.util.StringUtils.dumpBytes( newBytes ) );
+
+        // mainFrame.repaint();
+        // mainFrame.getTreeModel().reload(mainFrame.getTop());
+        return message.getLdapMessage().toString();
+    }
+
+    public String transformToStringType( int type )
+    {
+        String stringType;
+
+        switch ( type )
+        {
+            case 0 :
+                stringType = "ABANDON REQUEST";
+                break;
+            case 1 :
+                stringType = "ADD REQUEST";
+                break;
+            case 2 :
+                stringType = "ADD RESPONSE";
+                break;
+            case 3 :
+                stringType = "BIND REQUEST";
+                break;
+            case 4 :
+                stringType = "BIND RESPONSE";
+                break;
+            case 5 :
+                stringType = "COMPARE REQUEST";
+                break;
+            case 6 :
+                stringType = "COMPARE RESPONSE";
+                break;
+            case 7 :
+                stringType = "DEL REQUEST";
+                break;
+            case 8 :
+                stringType = "DEL RESPONSE";
+                break;
+            case 9 :
+                stringType = "EXTENDED REQUEST";
+                break;
+            case 10 :
+                stringType = "EXTENDED RESPONSE";
+                break;
+            case 11 :
+                stringType = "MODIFYDN REQUEST";
+                break;
+            case 12 :
+                stringType = "MODIFYDN RESPONSE";
+                break;
+            case 13 :
+                stringType = "MODIFY REQUEST";
+                break;
+            case 14 :
+                stringType = "MODIFY RESPONSE";
+                break;
+            case 15 :
+                stringType = "SEARCH REQUEST";
+                break;
+            case 16 :
+                stringType = "SEARCH RESULT DONE";
+                break;
+            case 17 :
+                stringType = "SEARCH RESULT ENTRY";
+                break;
+            case 18 :
+                stringType = "SEARCH RESULT REFERENCE";
+                break;
+            case 19 :
+                stringType = "UNBIND REQUEST";
+                break;
+            case -1 :
+                stringType = "UNKNOWN";
+                break;
+
+            default :
+                stringType = "UNKNOWN";
+                break;
+        }
+        return stringType;
+    }
+
+    public void run()
+    {
+        InputStream clientIn = null;
+        OutputStream clientOut = null;
+        InputStream serverIn = null;
+        OutputStream serverOut = null;
+        Socket toServer = null;
+        int r0 = -1;
+        int r1 = -1;
+        int ch = -1;
+        int i = -1;
+        long time0 = System.currentTimeMillis();
+        long time1 = time0 + timeout;
+
+        try
+        {
+            toServer = new Socket( host, port );
+            System.out.println( "open connection to:" + toServer + "(timeout=" + timeout + " ms)" );
+            clientIn = fromClient.getInputStream();
+            clientOut = new BufferedOutputStream( fromClient.getOutputStream() );
+            serverIn = toServer.getInputStream();
+            serverOut = new BufferedOutputStream( toServer.getOutputStream() );
+
+            while ( r0 != 0 || r1 != 0 || ( time1 - time0 ) <= timeout )
+            {
+                r0 = clientIn.available();
+
+                if ( r0 != 0 )
+                {
+                    System.out.println( "" );
+                    // LdapProxy.setTextIn("<<<" + r0 + " bytes from client
+                    // \n","red");
+                    System.out.println( "" );
+                    System.out.println( "<<<" + r0 + " bytes from client" );
+                    System.out.println( "<<<" + r1 + " bytes from server" );
+                }
+
+                ByteBuffer bb = null;
+
+                while ( ( r0 = clientIn.available() ) > 0 )
+                {
+                    byte[] in = new byte[r0];
+                    int k = 0;
+
+                    for ( i = 0; i < r0; i++ )
+                    {
+                        ch = clientIn.read();
+
+                        if ( ch != -1 )
+                        {
+                            in[k++] = (byte) ch;
+                            serverOut.write( ch );
+                        }
+                        else
+                        {
+                            System.out.println( "client stream closed" );
+                            // LdapProxy.setTextIn("client stream closed
+                            // \n","redbold");
+                        }
+                    }
+
+                    bb = ByteBuffer.allocate( r0 );
+                    bb.put( in );
+                    bb.flip();
+                    
+                    while ( bb.hasRemaining() )
+                    {
+                        decode( bb );
+                    }
+                    
+                    /*
+                     * LdapProxy.setTextIn("--->>>\n", "regular");
+                     * LdapProxy.setTextIn(result, "regular");
+                     * LdapProxy.setTextIn("----------------------------------\n",
+                     * "regular");
+                     */
+
+                    time0 = System.currentTimeMillis();
+                    serverOut.flush();
+                }
+
+                bb = null;
+
+                while ( ( r1 = serverIn.available() ) > 0 )
+                {
+                    System.out.println( "" );
+                    System.out.println( ">>>" + r1 + " bytes from server" );
+                    // LdapProxy.setTextOut(">>>" + r1 + " bytes from server
+                    // \n","red");
+                    System.out.println( "" );
+                    System.out.println( ">>>" + r1 + " bytes from server" );
+
+                    byte[] out = new byte[r1];
+                    int k = 0;
+
+                    for ( i = 0; i < r1; i++ )
+                    {
+                        ch = serverIn.read();
+
+                        if ( ch != -1 )
+                        {
+                            out[k++] = (byte) ch;
+                        }
+                        else
+                        {
+                            System.out.println( "server stream closed" );
+                            // LdapProxy.setTextOut("server stream closed
+                            // \n","redbold");
+                            break;
+                        }
+
+                        clientOut.write( ch );
+                    }
+
+                    bb = ByteBuffer.allocate( r1 );
+                    bb.put( out );
+                    bb.flip();
+
+                    while ( true )
+                    {
+                        try
+                        {
+                            String result = decode( bb );
+                            System.out.println( result );
+                            /*
+                             * LdapProxy.setTextOut("<<<---\n", "blue");
+                             * LdapProxy.setTextOut(result, "blue");
+                             * LdapProxy.setTextOut("----------------------------------\n",
+                             * "regular");
+                             */
+                            if ( bb.hasRemaining() == false )
+                            {
+                                break;
+                            }
+                        }
+                        catch ( DecoderException de )
+                        {
+                            StringBuffer result = new StringBuffer();
+                            result.append( de.getMessage() ).append( '\n' );
+
+                            byte[] tmp = new byte[out.length - bb.position()];
+                            System.arraycopy( out, bb.position(), tmp, 0, out.length - bb.position() );
+                            result.append( StringUtils.dumpBytes( tmp ) );
+
+                            System.out.println( result );
+                            /*
+                             * LdapProxy.setTextOut("<<<---\n", "regular");
+                             * LdapProxy.setTextOut(new String(tmp), "regular");
+                             * LdapProxy.setTextOut("----------------------------------\n",
+                             * "regular");
+                             */
+                            break;
+                        }
+                    }
+
+                    time0 = new Date().getTime();
+                    clientOut.flush();
+                }
+                if ( r0 == 0 && r1 == 0 )
+                {
+                    time1 = new Date().getTime();
+                    Thread.sleep( 100 );
+                    // Proxy.display("waiting:"+(time1-time0)+" ms");
+                }
+            }
+        }
+        catch ( Throwable t )
+        {
+            System.out.println( "i=" + i + " ch=" + ch );
+            t.printStackTrace( System.err );
+        }
+        finally
+        {
+            try
+            {
+                clientIn.close();
+                clientOut.close();
+                serverIn.close();
+                serverOut.close();
+                fromClient.close();
+                toServer.close();
+                LdapProxy.quit( time1 - time0 );
+            }
+            catch ( Exception e )
+            {
+                e.printStackTrace( System.err );
+            }
+        }
+    }
+
+    /*
+     * public void setTextIn(JTextPane textIn) { this.textIn = textIn; } public
+     * void setTextOut(JTextPane textOut) { this.textOut = textOut; }
+     */
+
+    public void setMainFrame( MainFrame mainframe )
+    {
+        this.mainFrame = mainframe;
+    }
 }



Mime
View raw message