String nameValue = dn.substring(dn.indexOf("=") + 1, dn.indexOf(","));
BasicAttributes attrs = new BasicAttributes();
if (dn.toLowerCase().startsWith("ou="))
{
attrs.put(new ObjectClassAttribute(new String[]{"top", "organizationalUnit"}));
attrs.put("ou", nameValue);
}
else if (dn.toLowerCase().startsWith("cn="))
{
attrs.put(new ObjectClassAttribute(new String[]{"top", "organizationalRole"}));
attrs.put("cn", nameValue);
}
else if (dn.toLowerCase().startsWith("c="))
{
attrs.put(new ObjectClassAttribute(new String[]{"country"}));
attrs.put("c", nameValue);
}
else if (dn.toLowerCase().startsWith("o="))
{
attrs.put(new ObjectClassAttribute(new String[]{"organization"}));
attrs.put("o", nameValue);
}
else if (dn.toLowerCase().startsWith("dc="))
{
attrs.put(new ObjectClassAttribute(new String[]{"top", "dcObject", "organization"}));
attrs.put("dc", nameValue);
attrs.put("o", nameValue);
}
attrs.put("description", nameValue);
context.createSubcontext(dn, attrs);