package at.knowcenter.wag.egov.egiz.ldap.client; import iaik.asn1.structures.Name; import iaik.utils.RFC2253NameParser; import iaik.utils.RFC2253NameParserException; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import org.apache.log4j.Logger; /** * @author Thomas Knall */ public class LDAPMappingStore { // private Hashtable storedMappings; private Hashtable storedMappings; private LDAPIssuerNameFilter issuerNameFilter; private Logger log = Logger.getLogger(getClass()); public LDAPMappingStore(LDAPIssuerNameFilter issuerNameFilter) { this.storedMappings = new Hashtable(); this.issuerNameFilter = issuerNameFilter; } public LDAPMappingStore() { this(null); } public void clearStore() { this.storedMappings = new Hashtable(); } public boolean isEmpty() { return this.storedMappings.isEmpty(); } public boolean isLDAPIssuerNameFilter() { return this.issuerNameFilter != null; } public void addMapping(LDAPMapping mapping) { Name name = mapping.getIssuerName(); if (issuerNameFilter != null) { name = this.issuerNameFilter.applyFilter(name); } List mappingList = (List) this.storedMappings.get(name); if (mappingList == null) { mappingList = new ArrayList(); this.storedMappings.put(name, mappingList); } log.debug("Adding mapping \"" + mapping + "\" for \"" + name.getName() + "\"."); mappingList.add(mapping); } public List getMappings(Name name) { if (issuerNameFilter != null) { name = this.issuerNameFilter.applyFilter(name); } return (List) this.storedMappings.get(name); } public List getMappings(String nameString) throws LDAPException { RFC2253NameParser parser = new RFC2253NameParser(nameString); Name name; try { name = parser.parse(); } catch (RFC2253NameParserException e) { throw new LDAPException(e); } if (issuerNameFilter != null) { name = this.issuerNameFilter.applyFilter(name); } return this.getMappings(name); } }