Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 105   Methods: 7
NCLOC: 68   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LDAPHandler.java 0% 0% 0% 0%
coverage
 1    /*
 2    * LDAPHandler.java
 3    *
 4    * Created on 8. Dezember 2002, 23:44
 5    */
 6   
 7    package org.jconfig.handler;
 8   
 9    //import java.util.Vector;
 10    //import java.util.HashMap;
 11    import java.io.InputStream;
 12    import java.util.Hashtable;
 13    import java.util.Properties;
 14   
 15    import javax.naming.Context;
 16    import javax.naming.NamingEnumeration;
 17    import javax.naming.directory.InitialDirContext;
 18    import javax.naming.directory.SearchControls;
 19    import javax.naming.directory.SearchResult;
 20   
 21    import org.jconfig.Configuration;
 22    import org.jconfig.ConfigurationManagerException;
 23    import org.jconfig.DefaultConfiguration;
 24    /**
 25    *
 26    * @author Administrator
 27    */
 28    public class LDAPHandler implements ConfigurationHandler {
 29   
 30    private String baseDN;
 31   
 32  0 public LDAPHandler() {
 33    }
 34   
 35    /** This method should read the configuration and then
 36    * set the categories and properties.
 37    * @throws ConfigurationManagerException
 38    */
 39  0 public Configuration load(String configurationName) throws ConfigurationManagerException {
 40  0 InitialDirContext ctx = getContext();
 41  0 if ( ctx == null ) {
 42  0 throw new ConfigurationManagerException("There is no connection to the LDAP server");
 43    }
 44  0 Configuration config = new DefaultConfiguration(null);
 45  0 getCategories(ctx,config);
 46  0 getAllProperties(ctx,config);
 47  0 return config;
 48    }
 49   
 50  0 private void getCategories(InitialDirContext ctx,Configuration config) {
 51  0 try {
 52  0 SearchControls sctrl = new SearchControls();
 53  0 String filter = "(&(objectclass=organizationalUnit)(ou=*))";
 54  0 NamingEnumeration enm = ctx.search(baseDN, filter, sctrl);
 55  0 while (enm.hasMore()) {
 56  0 SearchResult sr = (SearchResult) enm.next();
 57  0 config.setCategory(sr.getName());
 58    }
 59   
 60    } catch (Exception e) {
 61    // TODO
 62  0 e.printStackTrace();
 63    }
 64    }
 65   
 66  0 private void getAllProperties(InitialDirContext ctx,Configuration config) {
 67    }
 68    /** This method should store all categories and properties.
 69    * @throws ConfigurationManagerException
 70    */
 71  0 public void store() throws ConfigurationManagerException {
 72    }
 73   
 74  0 private InitialDirContext getContext() {
 75  0 Properties props = new Properties();
 76  0 try {
 77  0 InputStream is = getClass().getClassLoader().getResourceAsStream("ldap.properties");
 78  0 if ( is == null ) {
 79  0 return null;
 80    }
 81  0 props.load(is);
 82  0 Hashtable env = new Hashtable();
 83    // alle nötigen Parameter in die Hashtable eintragen. Die Werte kommen aus der config.xml
 84  0 env.put(Context.INITIAL_CONTEXT_FACTORY, props.getProperty("Context", ""));
 85  0 env.put(Context.PROVIDER_URL, props.getProperty("Host", ""));
 86  0 env.put(Context.SECURITY_AUTHENTICATION, "simple");
 87  0 env.put(Context.SECURITY_PRINCIPAL, props.getProperty("RootDN", ""));
 88  0 env.put(Context.SECURITY_CREDENTIALS, props.getProperty("Password", ""));
 89  0 baseDN = props.getProperty("BaseDN","");
 90  0 return new InitialDirContext(env);
 91    }
 92    catch (Exception e) {
 93    // TODO
 94  0 e.printStackTrace();
 95  0 return null;
 96    }
 97    }
 98   
 99    /** This method should store all categories and properties.
 100    * @throws ConfigurationManagerException
 101    */
 102  0 public void store(Configuration configuration) throws ConfigurationManagerException {
 103    }
 104   
 105    }