View Javadoc
1 package org.jellyfish.implementation; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.apache.avalon.framework.configuration.Configurable; 7 import org.apache.avalon.framework.configuration.Configuration; 8 import org.apache.avalon.framework.configuration.ConfigurationException; 9 import org.apache.avalon.framework.logger.LogEnabled; 10 import org.apache.avalon.framework.logger.Logger; 11 import org.jellyfish.ConfigurationManager; 12 import org.jellyfish.config.AttributeMapping; 13 import org.jellyfish.config.Config; 14 import org.jellyfish.config.ObjectMapping; 15 16 public class ConfigurationManagerDefault implements ConfigurationManager, Configurable, LogEnabled { 17 private static ConfigurationManagerDefault instance; 18 private Config jellyfishConfiguration; 19 private Logger logger; 20 21 private List buildAttributeMappings(Configuration[] attributeMappingElements) 22 throws ConfigurationException { 23 List attributeMappings = new ArrayList(); 24 for (int index = 0; index < attributeMappingElements.length; index++) { 25 attributeMappings.add( 26 new AttributeMapping( 27 filterNull(attributeMappingElements[index].getChild("java-name").getValue("")), 28 filterNull(attributeMappingElements[index].getChild("ldap-name").getValue("")), 29 filterNull(attributeMappingElements[index].getChild("type").getValue("")))); 30 } 31 return attributeMappings; 32 } 33 34 private Config buildConfig(Configuration avalonConfiguration) throws ConfigurationException { 35 Config config = new Config(); 36 config.setBaseDn(filterNull(avalonConfiguration.getChild("base-dn").getValue(""))); 37 config.setConnectionDn( 38 filterNull(avalonConfiguration.getChild("connection-dn").getValue(""))); 39 config.setConnectionPassword( 40 filterNull(avalonConfiguration.getChild("connection-password").getValue(""))); 41 config.setConnectionUrl( 42 filterNull(avalonConfiguration.getChild("connection-url").getValue(""))); 43 config.setContextFactory( 44 filterNull(avalonConfiguration.getChild("context-factory").getValue(""))); 45 config.setUserDn(filterNull(avalonConfiguration.getChild("user-dn").getValue(""))); 46 config.setObjectMappings( 47 buildObjectMappings(avalonConfiguration.getChildren("object-mapping"))); 48 return config; 49 } 50 51 private List buildObjectMappings(Configuration[] objectMappingElements) 52 throws ConfigurationException { 53 List objectMappings = new ArrayList(); 54 for (int index = 0; index < objectMappingElements.length; index++) { 55 objectMappings.add( 56 new ObjectMapping( 57 filterNull(objectMappingElements[index].getChild("java-name").getValue("")), 58 filterNull(objectMappingElements[index].getChild("ldap-name").getValue("")), 59 filterNull(objectMappingElements[index].getChild("dn").getValue("")), 60 buildAttributeMappings( 61 objectMappingElements[index].getChildren("attribute-mapping")))); 62 } 63 return objectMappings; 64 } 65 66 protected Config createConfiguration() { 67 return jellyfishConfiguration; 68 } 69 70 public Config getConfiguration() { 71 return createConfiguration(); 72 } 73 74 private String filterNull(String string) { 75 return string == null ? "" : string; 76 } 77 78 public void configure(Configuration configuration) throws ConfigurationException { 79 try { 80 jellyfishConfiguration = buildConfig(configuration); 81 } catch (ConfigurationException e) { 82 logger.fatalError("error getting configuration", e); 83 jellyfishConfiguration = new Config(); 84 } 85 } 86 87 public void enableLogging(org.apache.avalon.framework.logger.Logger logger) { 88 this.logger = logger; 89 } 90 91 }

This page was automatically generated by Maven