Example usage for javax.naming.directory SearchResult getClassName

List of usage examples for javax.naming.directory SearchResult getClassName

Introduction

In this page you can find the example usage for javax.naming.directory SearchResult getClassName.

Prototype

public String getClassName() 

Source Link

Document

Retrieves the class name of the object bound to the name of this binding.

Usage

From source file:org.jkcsoft.java.util.JndiHelper.java

public static void logLdap(Log plog, int level, int nth, Object dirEntry) throws NamingException {
    try {//from   w  ww  .  ja  v  a2  s . co m
        if (dirEntry instanceof NamingEnumeration) {
            NamingEnumeration nameEnum = (NamingEnumeration) dirEntry;
            JndiHelper.logLevel(plog, level, nth, "Naming Enumeration: " + nameEnum);
            try {
                int nthThis = 0;
                List nameList = new Vector(Collections.list(nameEnum));
                Collections.sort(nameList, new Comparator() {
                    public int compare(Object o1, Object o2) {
                        if (o1 instanceof Attribute) {
                            return String.CASE_INSENSITIVE_ORDER.compare(((Attribute) o1).getID(),
                                    ((Attribute) o2).getID());
                        }
                        return 0;
                    }
                });
                Iterator nameIter = nameList.iterator();
                while (nameIter.hasNext()) {
                    logLdap(plog, level + 1, nthThis++, nameIter.next());
                }
            } catch (NamingException ex) {
                plog.error("Exception iterating thru NamingEnumeration: " + ex.getMessage());
            }
        } else if (dirEntry instanceof Attribute) {
            Attribute dirAttr = (Attribute) dirEntry;
            JndiHelper.logLevel(plog, level, nth, "Attribute: [" + dirAttr + "]");
        } else if (dirEntry instanceof DirContext) {
            DirContext lctx = (DirContext) dirEntry;
            JndiHelper.logLevel(plog, level, nth,
                    "LDAP Context: DN [" + lctx.getNameInNamespace() + "]" + " Attributes ==>");
            logLdap(plog, level, nth, lctx.getAttributes("").getAll());
        } else if (dirEntry instanceof SearchResult) {
            SearchResult sr = (SearchResult) dirEntry;
            JndiHelper.logLevel(plog, level, nth, "SearchResult: ClassName of Bound Object ["
                    + sr.getClassName() + "]" + " Name: [" + sr.getName() + "]" + " Bound Object ==>");
            //                sr.s
            logLdap(plog, level, nth, sr.getObject());
            logLdap(plog, level, nth, sr.getAttributes().getAll());
        } else {
            JndiHelper.logLevel(plog, level, nth, "(?) class of entry: [" + dirEntry + "]");
        }
        nth++;
    } catch (NamingException e1) {
        plog.error("Naming Exception (will try to continue): " + e1.getMessage());
    }
}