public Object getObjectAttribute(String name) { Attribute oneAttr = attrs.get(name); if (oneAttr == null) { return null; } try { return oneAttr.get(); } catch (NamingException e) { throw getExceptionTranslator().translate(e); } }
public SortedSet getAttributeSortedStringSet(String name) { TreeSet attrSet = new TreeSet(); Attribute attribute = attrs.get(name); if (attribute != null) { for (int i = 0; i < attribute.size(); i++) { try { attrSet.add(attribute.get(i)); } catch (NamingException e) { throw getExceptionTranslator().translate(e); } } } else { return null; } return attrSet; }
public Object getObjectFromNameClassPair(NameClassPair nameClassPair) { try { return mapper.mapFromNameClassPair(nameClassPair); } catch (NamingException e) { throw getExceptionTranslator().translate(e); } } }
/** * Cast the NameClassPair to a SearchResult and pass its attributes to * the AttributesMapper. * * @param nameClassPair * a SearchResult instance. * @return the Object returned from the Mapper. */ public Object getObjectFromNameClassPair(NameClassPair nameClassPair) { SearchResult searchResult = (SearchResult) nameClassPair; Attributes attributes = searchResult.getAttributes(); try { return mapper.mapFromAttributes(attributes); } catch (NamingException e) { throw getExceptionTranslator().translate(e); } } }
public ModificationItem[] getModificationItems() { if (!updateMode) { return new ModificationItem[0]; } List tmpList = new LinkedList(); NamingEnumeration attributesEnumeration = null; try { attributesEnumeration = updatedAttrs.getAll(); // find attributes that have been changed, removed or added while (attributesEnumeration.hasMore()) { Attribute oneAttr = (Attribute) attributesEnumeration.next(); collectModifications(oneAttr, tmpList); } } catch (NamingException e) { throw getExceptionTranslator().translate(e); } finally { closeNamingEnumeration(attributesEnumeration); } if (log.isDebugEnabled()) { log.debug("Number of modifications:" + tmpList.size()); } return (ModificationItem[]) tmpList .toArray(new ModificationItem[tmpList.size()]); }
public String[] getStringAttributes(String name) { String[] attributes; Attribute attribute = attrs.get(name); if (attribute != null && attribute.size() > 0) { attributes = new String[attribute.size()]; for (int i = 0; i < attribute.size(); i++) { try { attributes[i] = (String) attribute.get(i); } catch (NamingException e) { throw getExceptionTranslator().translate(e); } } } else { return null; } return attributes; }
private Object executeWithContext(ContextExecutor ce, DirContext ctx) { try { return ce.executeWithContext(ctx); } catch (NamingException e) { throw getExceptionTranslator().translate(e); } finally { closeContext(ctx); } }
public String[] getNamesOfModifiedAttributes() { List tmpList = new ArrayList(); NamingEnumeration attributesEnumeration; if (isUpdateMode()) { attributesEnumeration = updatedAttrs.getAll(); } else { attributesEnumeration = attrs.getAll(); } try { while (attributesEnumeration.hasMore()) { Attribute oneAttribute = (Attribute) attributesEnumeration .next(); tmpList.add(oneAttribute.getID()); } } catch (NamingException e) { throw getExceptionTranslator().translate(e); } finally { closeNamingEnumeration(attributesEnumeration); } return (String[]) tmpList.toArray(new String[0]); }
/** * Create a DirContext using the supplied environment. * * @param environment * the Ldap environment to use when creating the DirContext. * @return a new DirContext implpementation initialized with the supplied * environment. */ DirContext createContext(Hashtable environment) { DirContext ctx = null; try { ctx = getDirContextInstance(environment); if (log.isInfoEnabled()) { Hashtable ctxEnv = ctx.getEnvironment(); String ldapUrl = (String) ctxEnv.get(Context.PROVIDER_URL); log.debug("Got Ldap context on server '" + ldapUrl + "'"); } return ctx; } catch (NamingException e) { closeContext(ctx); throw getExceptionTranslator().translate(e); } }
throw getExceptionTranslator().translate(e); } finally { try {
public void update() { NamingEnumeration attributesEnumeration = null; try { attributesEnumeration = updatedAttrs.getAll(); // find what to update while (attributesEnumeration.hasMore()) { Attribute a = (Attribute) attributesEnumeration.next(); // if it does not exist it should be added if (isEmptyAttribute(a)) { attrs.remove(a.getID()); } else { // Otherwise it should be set. attrs.put(a); } } } catch (NamingException e) { throw getExceptionTranslator().translate(e); } finally { closeNamingEnumeration(attributesEnumeration); } // Reset the attributes to be updated updatedAttrs = new BasicAttributes(true); }