int index = cn.indexOf(' ');
int index = cn.lastIndexOf(' ');
    private LDAPAttributeSet getAttributeSet(String objectclass, String dn, boolean extra, boolean person) {        LDAPAttributeSet attributeSet = new LDAPAttributeSet();        LDAPAttribute attr = new LDAPAttribute("objectclass");        // The full LDAP object tree is divided with ; in the objectclass        StringTokenizer token = new StringTokenizer(objectclass,";");        while (token.hasMoreTokens()) {            String value = token.nextToken();            debug("Adding objectclass value: "+value);            attr.addValue(value);        }        attributeSet.add(attr);        /* To Add an entry to the directory,         *   -- Create the attributes of the entry and add them to an attribute set         *   -- Specify the DN of the entry to be created         *   -- Create an LDAPEntry object with the DN and the attribute set         *   -- Call the LDAPConnection add method to add it to the directory         */        if (extra) {            String cn = CertTools.getPartFromDN(dn, "CN");            if (cn != null) {                attributeSet.add(new LDAPAttribute("cn", cn));            }            // sn means surname in LDAP, and is required for persons            String sn = CertTools.getPartFromDN(dn, "SURNAME");            if (person) {                if ( (sn == null) && (cn != null) ) {                    // Take surname to be the last part of the cn                    int index = cn.indexOf(' ');                    if (index <=0) {                        // If there is no natural sn, use cn since sn is required                        sn = cn;                    } else {                        if (index < cn.length()) sn = cn.substring(index);                    }                }            }            if (sn != null) {                attributeSet.add(new LDAPAttribute("sn", sn));            }            // gn means givenname in LDAP, and is required for persons            String gn = CertTools.getPartFromDN(dn, "GIVENNAME");            if (person) {                if ( (gn == null) && (cn != null) ) {                    // Take givenname to be the first part of the cn                    int index = cn.indexOf(' ');                    if (index <=0) {                        // If there is no natural gn/sn, ignore gn if we are using sn                        if (sn == null) gn = cn;                    } else {                        gn = cn.substring(0, index);                    }                }            }            if (gn != null) {                attributeSet.add(new LDAPAttribute("gn", gn));            }            String l = CertTools.getPartFromDN(dn, "L");            if (l != null) {                attributeSet.add(new LDAPAttribute("l", l));            }            String st = CertTools.getPartFromDN(dn, "ST");            if (st != null) {                attributeSet.add(new LDAPAttribute("st", st));            }            String ou = CertTools.getPartFromDN(dn, "OU");            if (ou != null) {                attributeSet.add(new LDAPAttribute("ou", ou));            }        }        return attributeSet;    } // getAttributeSet