package schema;
import com.novell.ldap.LDAPAttributeSchema;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPSchema;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Enumeration;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.List;
import java.awt.Panel;
import java.awt.TextArea;
public class ListAttributeSchema extends Panel implements ActionListener
{
private String attrName ;
private String attrNames[];
private ArrayList al = new ArrayList();
private Button exit, properties;
private List attrList;
private TextArea textarea;
private LDAPConnection connection;
private LDAPSchema schema;
private static final int USER_APPLICATIONS = 0x00;
private static final int DIRECTORY_OPERATION = 0x01;
private static final int DISTRIBUTED_OPERATION = 0x02;
private static final int DSA_OPERATION = 0x03;
public ListAttributeSchema( LDAPConnection conn ) {
connection = conn;
}
public void init() {
int i;
LDAPAttributeSchema nextItem;
try {
schema = connection.fetchSchema( connection.getSchemaDN() );
Enumeration AttributeSchema = schema.getAttributeSchemas();
while (AttributeSchema.hasMoreElements()) {
nextItem = (LDAPAttributeSchema)AttributeSchema.nextElement();
String[] names = nextItem.getNames();
for (i=0; i< names.length; i++)
al.add(names[i]);
}
}
catch(Exception e ) {
System.out.println( "\nError: " + e.toString() );
}
if ( al.isEmpty() ) {
System.out.println("\nError in ListAttributeSchema.java: "
+ "failed to get attribute schema.");
System.exit(1);
}
attrNames = new String[al.size()];
for ( i = 0; i < al.size(); i++ )
attrNames[i] = (String)al.get(i);
Arrays.sort(attrNames);
attrList = new List( 31, false );
for ( i = 0; i < attrNames.length; i++ )
attrList.add( attrNames[i] );
add( attrList, BorderLayout.WEST );
exit = new Button ( "Exit" );
exit.addActionListener( this );
add( exit );
properties = new Button ( "List>" );
properties.addActionListener( this );
add( properties );
textarea = new TextArea( 30, 68 );
textarea.setEditable( false );
add( textarea, BorderLayout.EAST );
}
public void actionPerformed( ActionEvent e ) {
int i;
if ( e.getSource() == exit )
System.exit( 0 );
if ( (attrName = attrList.getSelectedItem() ) == null)
attrName = attrNames[ 0 ];
LDAPAttributeSchema attrSchema = schema.getAttributeSchema( attrName );
if ( attrSchema == null ) {
System.err.println("There is no such attribute: " + attrName );
System.exit( 1 );
}
String[] names = attrSchema.getNames();
textarea.append("name: ");
if (names != null && names.length > 0){
textarea.append(names[0]);
}
for (i=1; i<names.length; i++){
textarea.append(", " + names[i]);
}
textarea.append("\n");
textarea.append("properties:\n");
textarea.append(" ID:\n");
textarea.append(" " + attrSchema.getID() + "\n");
textarea.append(" value:\n");
String value = attrSchema.toString();
int len = value.length();
for ( i = 0; i < len; i += 70) {
int lastIndex = ( i + 70 ) > len ? len : ( i + 70 );
textarea.append(" " + value.substring(i, lastIndex) + "\n");
}
textarea.append(" description:\n");
textarea.append(" " + attrSchema.getDescription() + "\n");
Enumeration qnames = attrSchema.getQualifierNames();
String qualifierName;
String qualifierValues[];
textarea.append(" qualifier names and values:\n" );
if (qnames.hasMoreElements()) {
while (qnames.hasMoreElements()) {
qualifierName = ( String )qnames.nextElement();
qualifierValues = attrSchema.getQualifier( qualifierName );
for ( i=0; i<qualifierValues.length; i++ ) {
textarea.append(" " + qualifierName + ": "
+ qualifierValues[i] + "\n");
}
}
}
else
textarea.append(" no\n");
textarea.append(" syntax string:\n");
textarea.append(" " + attrSchema.getSyntaxString() + "\n");
textarea.append(" usage: \n");
int usage = attrSchema.getUsage();
switch( usage ) {
case USER_APPLICATIONS:
textarea.append(" USER_APPLICATIONS\n");
break;
case DIRECTORY_OPERATION:
textarea.append(" DIRECTORY_OPERATION\n");
break;
case DISTRIBUTED_OPERATION:
textarea.append(" DISTRIBUTED_OPERATION\n");
break;
case DSA_OPERATION:
textarea.append(" DSA_OPERATION\n");
break;
default:
}
textarea.append(" has superior attribute?\n");
textarea.append( (attrSchema.getSuperior() != null)?
" yes\n": " no\n");
textarea.append(" has equality matching rule?\n");
textarea.append(
(attrSchema.getEqualityMatchingRule() != null)?
" yes\n": " no\n");
textarea.append(" has ordering matching rule?\n");
textarea.append( (attrSchema.getOrderingMatchingRule()
!= null)? " yes\n": " no\n");
textarea.append(" has substring matching rule?\n");
textarea.append( (attrSchema.getSubstringMatchingRule()
!= null)? " yes\n": " no\n");
textarea.append(" is a collective attribute?\n");
textarea.append(attrSchema.isCollective()?
" yes\n": " no\n");
textarea.append(" is a single valued attribute?\n");
textarea.append(attrSchema.isSingleValued()?
" yes\n": " no\n");
textarea.append(" is a modifiable attribute?\n");
textarea.append(attrSchema.isUserModifiable()?
" yes\n": " no\n");
textarea.append("\n");
}
}