import java.io.IOException;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import com.novell.service.ndssdk.jndi.ldap.ext.PartitionEntryCountRequest;
import com.novell.service.ndssdk.jndi.ldap.ext.PartitionEntryCountResponse;
import com.novell.service.ndssdk.jndi.ldap.ext.LDAPExtendedResponse;
public class PartitionEntryCount {
public static void main(String[] args) {
if (args.length != 4) {
usage();
}
String hostURL = args[0];
String loginDN = args[1];
String passWord = args[2];
String PartitionDN = args[3];
try {
Hashtable env = new Hashtable(5, 0.75f);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, hostURL);
env.put(Context.SECURITY_AUTHENTICATION, "simple" );
env.put(Context.SECURITY_PRINCIPAL, loginDN );
env.put(Context.SECURITY_CREDENTIALS, passWord );
LdapContext ctx = new InitialLdapContext(env, null);
PartitionEntryCountRequest reqs =
new PartitionEntryCountRequest( PartitionDN );
PartitionEntryCountResponse resp =
(PartitionEntryCountResponse)ctx.extendedOperation(reqs);
int count = resp.getEntryCount();
System.out.println("\n\tEntry count: " + count );
System.out.println("\n\tPartitionEntryCount operation succeeded.");
}
catch (NamingException e) {
System.err.println("\n\tPartitionEntryCount operation failed.");
e.printStackTrace();
}
catch (IOException ioe) {
System.err.println("\n\tPartitionEntryCount operation failed.");
ioe.printStackTrace();
}
finally {
System.exit(0);
}
}
public static void usage() {
System.out.println("\n Usage : java PartitionEntryCount"
+"<host URL> <login dn> <password>\n <naming context dn>");
System.out.println("\n Example: java PartitionEntryCount"
+"ldap://Acme.com:389 cn=admin,o=Acme"
+"\n secret ou=Sales,o=Acme");
System.exit ( -1 );
}
}