1 16 package org.apache.cocoon.components.modules.input; 17 18 19 import org.apache.avalon.framework.configuration.Configurable; 20 import org.apache.avalon.framework.configuration.Configuration; 21 import org.apache.avalon.framework.configuration.ConfigurationException; 22 import org.apache.avalon.framework.logger.AbstractLogEnabled; 23 import org.apache.avalon.framework.thread.ThreadSafe; 24 25 import java.util.HashMap ; 26 import java.util.Iterator ; 27 import java.util.Map ; 28 import java.util.SortedSet ; 29 import java.util.TreeSet ; 30 31 45 public class DefaultsModule extends AbstractLogEnabled 46 implements InputModule, Configurable, ThreadSafe { 47 48 private Map constants = null; 49 50 public void configure(Configuration config) throws ConfigurationException { 51 52 this.constants = new HashMap (); 53 Configuration[] consts = config.getChild("values").getChildren(); 54 for (int i=0; i<consts.length; i++) { 55 this.constants.put(consts[i].getName(), consts[i].getValue("")); 56 } 57 } 58 59 60 public Object [] getAttributeValues( String name, Configuration modeConf, Map objectModel ) 61 throws ConfigurationException { 62 63 String parameter=name; 64 Configuration mConf = null; 65 if (modeConf!=null) { 66 mConf = modeConf.getChild("values"); 67 } 68 69 Object [] values = new Object [1]; 70 values[0] = (mConf!=null? mConf.getChild(parameter).getValue((String ) this.constants.get(parameter)) 71 : this.constants.get(parameter)); 72 return values; 73 } 74 75 76 public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) 77 throws ConfigurationException { 78 79 SortedSet matchset = new TreeSet (this.constants.keySet()); 80 if (modeConf!=null) { 81 Configuration[] consts = modeConf.getChild("values").getChildren(); 82 for (int i=0; i<consts.length; i++) 83 matchset.add(consts[i].getName()); 84 } 85 return matchset.iterator(); 86 } 87 88 89 public Object getAttribute( String name, Configuration modeConf, Map objectModel ) 90 throws ConfigurationException { 91 92 Object [] values = this.getAttributeValues(name,modeConf,objectModel); 93 return values[0]; 94 } 95 96 } 97 | Popular Tags |