1 16 package org.apache.cocoon.components.modules.input; 17 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.configuration.ConfigurationException; 20 import org.apache.avalon.framework.thread.ThreadSafe; 21 22 import java.util.Iterator ; 23 import java.util.Map ; 24 25 37 public class MapMetaModule extends AbstractMetaModule implements ThreadSafe { 38 39 protected String objectName = null; 40 protected String parameter = null; 41 42 43 public void configure(Configuration config) throws ConfigurationException { 44 45 this.inputConf = config.getChild("input-module"); 46 this.defaultInput = this.inputConf.getAttribute("name", this.defaultInput); 47 this.objectName = this.inputConf.getAttribute("object",this.objectName); 48 this.parameter = this.inputConf.getAttribute("parameter",this.parameter); 49 50 this.objectName = config.getChild("object").getValue(this.objectName); 52 this.parameter = config.getChild("parameter").getValue(this.parameter); 53 } 54 55 56 public Object getAttribute( String name, Configuration modeConf, Map objectModel ) 57 throws ConfigurationException { 58 59 if (!this.initialized) { 60 this.lazy_initialize(); 61 } 62 if (this.defaultInput == null) { 63 if (getLogger().isWarnEnabled()) 64 getLogger().warn("No input module given. FAILING"); 65 return null; 66 } 67 68 String inputName=null; 71 String objectName = this.objectName; 72 String parameter = this.parameter; 73 if (modeConf != null) { 74 inputName = modeConf.getChild("input-module").getAttribute("name",null); 75 objectName = modeConf.getAttribute("object",objectName); 76 parameter = modeConf.getAttribute("parameter",parameter); 77 78 objectName = modeConf.getChild("object").getValue(objectName); 80 parameter = modeConf.getChild("parameter").getValue(parameter); 81 } 82 parameter = (parameter != null? parameter : name); 83 84 Object value = getValue(objectName, objectModel, 85 this.input, this.defaultInput, this.inputConf, 86 null, inputName, modeConf); 87 88 value = (value!=null? ((Map ) value).get(parameter) : null); 89 90 return value; 91 } 92 93 94 95 96 public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) 97 throws ConfigurationException { 98 99 if (!this.initialized) { 100 this.lazy_initialize(); 101 } 102 if (this.defaultInput == null) { 103 if (getLogger().isWarnEnabled()) 104 getLogger().warn("No input module given. FAILING"); 105 return null; 106 } 107 108 Configuration inputConfig = null; 111 String inputName=null; 112 String objectName = this.objectName; 113 if (modeConf!=null) { 114 inputName = modeConf.getChild("input-module").getAttribute("name",null); 115 objectName = modeConf.getAttribute("object",this.objectName); 116 117 objectName = modeConf.getChild("object").getValue(objectName); 119 if (inputName != null) { 120 inputConfig = modeConf.getChild("input-module"); 121 } 122 } 123 124 Iterator keys = ((Map ) getValue(objectName, objectModel, 125 this.input, this.defaultInput, this.inputConf, 126 null, inputName, inputConfig)).keySet().iterator(); 127 128 return keys; 129 } 130 131 132 133 134 public Object [] getAttributeValues( String name, Configuration modeConf, Map objectModel ) 135 throws ConfigurationException { 136 137 Object [] values = new Object [1]; 138 values[0] = this.getAttribute(name, modeConf, objectModel); 139 return (values[0]!=null?values:null); 140 } 141 142 } 143 | Popular Tags |