1 16 package org.apache.cocoon.components.modules.input; 17 18 import org.apache.avalon.framework.activity.Initializable; 19 import org.apache.avalon.framework.configuration.Configuration; 20 import org.apache.avalon.framework.configuration.ConfigurationException; 21 import org.apache.avalon.framework.thread.ThreadSafe; 22 23 import javax.naming.InitialContext ; 24 import javax.naming.NamingException ; 25 import java.util.Collections ; 26 import java.util.Iterator ; 27 import java.util.Map ; 28 import java.util.Properties ; 29 30 60 public class NamingInputModule extends AbstractInputModule implements ThreadSafe, Initializable { 61 62 65 private Properties properties; 66 67 70 private InitialContext context; 71 72 75 public void configure(Configuration conf) throws ConfigurationException { 76 Configuration[] parameters = conf.getChildren(); 77 this.properties = new Properties (); 78 for (int i = 0; i < parameters.length; i++) { 79 String key = parameters[i].getName(); 80 String val = parameters[i].getValue(""); 81 this.properties.put(key, val); 82 } 83 } 84 85 88 public void initialize() throws Exception { 89 this.context = new InitialContext (this.properties); 90 } 91 92 95 public void dispose() { 96 super.dispose(); 97 if (this.context != null) { 98 try { 99 this.context.close(); 100 } catch (NamingException ignored) { 101 } 102 } 103 } 104 105 108 public Object getAttribute(String name, Configuration modeConf, Map objectModel) 109 throws ConfigurationException { 110 111 String pname = (String ) this.properties.get("path"); 113 if (pname == null) { 114 pname = name; 115 } 116 117 if (modeConf != null) { 118 pname = modeConf.getAttribute("path", pname); 119 pname = modeConf.getChild("path").getValue(pname); 121 } 122 123 try { 124 return this.context.lookup(pname); 125 } catch (NamingException e) { 126 if (getLogger().isDebugEnabled()) { 127 getLogger().debug("Can't get parameter " + pname, e); 128 } 129 return null; 130 } 131 } 132 133 136 public Iterator getAttributeNames(Configuration modeConf, Map objectModel) 137 throws ConfigurationException { 138 139 return Collections.EMPTY_LIST.iterator(); 140 } 141 } 142 | Popular Tags |