import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.naming.*;
import javax.naming.directory.*;
public class NSIAttributeFrame extends Frame
implements WindowListener,
ActionListener
{
public static final int width = 420;
public static final int height = 400;
DirContext currDirCtx;
List attrList;
Vector attrVector;
public NSIAttributeFrame (
DirContext dirCtx)
{
super ("Attributes");
currDirCtx = dirCtx;
attrList = new List ();
attrVector = new Vector ();
add ("Center", attrList);
updateList ();
addWindowListener (this);
attrList.addActionListener (this);
pack ();
}
public void actionPerformed (
ActionEvent evt)
{
Object target = evt.getSource();
if (target == attrList)
{
}
}
public void windowClosed (
WindowEvent event)
{
}
public void windowDeiconified (
WindowEvent event)
{
}
public void windowIconified (
WindowEvent event)
{
}
public void windowActivated (
WindowEvent event)
{
}
public void windowDeactivated (
WindowEvent event)
{
}
public void windowOpened (
WindowEvent event)
{
}
public void windowClosing (
WindowEvent event)
{
dispose ();
}
void updateList ()
{
this.setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try
{
Attributes attrSet;
NamingEnumeration attrEnum = null;
Attribute attr;
SortableString sortStr;
int attrCount;
attrSet = currDirCtx.getAttributes ("");
if (null != attrSet)
attrEnum = attrSet.getAll ();
if (null == attrEnum)
attrCount = 0;
else
attrCount = attrSet.size ();
if (0 == attrCount)
{
attrVector.addElement (new SortableString ("No Attributes"));
attrCount++;
}
else
{
while (attrEnum.hasMoreElements ())
{
attr = (Attribute) attrEnum.next ();
sortStr = new SortableString (attr.toString ());
attrVector.addElement (sortStr);
}
QuickSort.sort (attrVector, 0, attrCount - 1);
}
for (int i = 0; i < attrCount; i++)
{
sortStr = (SortableString) attrVector.elementAt (i);
attrList.addItem (sortStr.toString ());
}
}
catch (NamingException e)
{
System.out.println ("Unable to list attributes");
System.out.println ("Unexpected naming exception " + e);
e.printStackTrace ();
}
this.setCursor (Cursor.getDefaultCursor());
}
}