} else if (v instanceof Map) { throw ServiceException.FAILURE("Map is not a supported value type", null); } else { String s = (v == null ? null : v.toString()); if (doAdd) addAttr(modlist, key, s, currentAttrs); else if (doRemove) removeAttr(modlist, key, s, currentAttrs); else modifyAttr(modlist, key, s, currentAttrs);
    public static void modifyAttrs(DirContext ctxt, String dn, Map attrs, Attributes currentAttrs) throws NamingException, ServiceException {        ArrayList<ModificationItem> modlist = new ArrayList<ModificationItem>();        for (Iterator mit=attrs.entrySet().iterator(); mit.hasNext(); ) {            Map.Entry me = (Entry) mit.next();            Object v= me.getValue();            String key = (String) me.getKey();            boolean doAdd = key.charAt(0) == '+';            boolean doRemove = key.charAt(0) == '-';                        if (doAdd || doRemove) {                // make sure there aren't other changes without +/- going on at the same time                 key = key.substring(1);                if (attrs.containsKey(key))                     throw ServiceException.INVALID_REQUEST("can't mix +attrName/-attrName with attrName", null);            }            if (v == null || v instanceof String) {                if (doAdd) addAttr(modlist, key, (String)v, currentAttrs);                else if (doRemove) removeAttr(modlist, key, (String)v, currentAttrs);                else modifyAttr(modlist, key, (String)v, currentAttrs);            } else if (v instanceof String[]) {                String[] sa = (String[]) v;                if (sa.length == 0) {                    // make sure it exists                    if (currentAttrs.get(key) != null) {                        BasicAttribute ba = new BasicAttribute(key);                        modlist.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE, ba));                    }                } else {                    if (doAdd) addAttr(modlist, key, sa, currentAttrs);                    else if (doRemove) removeAttr(modlist, key, sa, currentAttrs);                    else {                        BasicAttribute ba = new BasicAttribute(key);                        for (int i=0; i < sa.length; i++)                                ba.add(sa[i]);                        modlist.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, ba));                    }                }            }        }        ModificationItem[] mods = new ModificationItem[modlist.size()];        modlist.toArray(mods);        ctxt.modifyAttributes(dn, mods);    }