1 package net.sf.jldapbeans.lang;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9
10 /***
11 * Default implementation of the @link net.sf.jldapbeans.lang.BeanRepository.
12 *
13 * @author <a href="mailto:alonsoft@users.sf.net">A. Alonso Domínguez</a>
14 * @version 1.0 $ Revision 12-nov-2005 :: alonso $
15 */
16 class BeanRepositoryImpl implements BeanRepository {
17 private static final Log log = LogFactory.getLog(BeanRepository.class);
18
19 private Map<String, String> m_objectClasses = new HashMap<String, String>();
20
21 public String getObjectClass(String className) {
22 return m_objectClasses.get(className);
23 }
24
25 /***
26 * Adds an <tt>objectClass</tt> definition to the ones store inside this repository
27 * instance.
28 * <p>
29 * This method will prevent for overring already loaded definitions.
30 *
31 * @param objectClass A LDAP <tt>objectClass</tt> name
32 * @param className A Java <tt>Class</tt> name.
33 */
34 public void setObjectClass(String objectClass, String className) {
35 if(!m_objectClasses.containsKey(objectClass) && !m_objectClasses.containsValue(className))
36 m_objectClasses.put(objectClass, className);
37 else
38 log.warn("Attempted to overwrite an existent objectClass!");
39 }
40
41 /***
42 * Includes a <tt>BeanRepositoryImpl</tt> inside this instance.
43 * <p>
44 * Used internally to suport loading of multiple repositories
45 *
46 * @param repository A <tt>BeanRepositoryImpl</tt> instance internally loaded.
47 */
48 public void include(BeanRepositoryImpl repository) {
49 for(String key : repository.m_objectClasses.keySet()) {
50 String value = repository.m_objectClasses.get(key);
51 setObjectClass(key, value);
52 }
53 }
54
55 }