1 package net.sourceforge.formview.displayer; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.io.Serializable ; 6 import java.net.URL ; 7 import java.util.ArrayList ; 8 import java.util.List ; 9 10 import org.apache.commons.collections.FastHashMap; 11 import org.apache.commons.digester.Digester; 12 import org.apache.commons.digester.xmlrules.DigesterLoader; 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.xml.sax.SAXException ; 16 17 25 public class DisplayersConfigResources implements Serializable { 26 27 private static final long serialVersionUID = 1L; 28 29 protected static Log log = LogFactory.getLog(DisplayersConfigResources.class); 30 31 35 protected FastHashMap hDisplayerConfigs = new FastHashMap(); 36 37 protected List lDisplayerConfigs = new ArrayList (); 38 39 48 public DisplayersConfigResources(InputStream in) throws IOException , SAXException { 49 this(new InputStream []{in}); 50 } 51 52 62 public DisplayersConfigResources(InputStream [] streams) 63 throws IOException , SAXException { 64 super(); 65 66 URL rulesUrl = this.getClass().getResource("digester-rules-displayers.xml"); 67 Digester digester = DigesterLoader.createDigester(rulesUrl); 68 digester.setNamespaceAware(true); 69 digester.setUseContextClassLoader(true); 71 72 digester.push(this); 73 for (int i = 0; i < streams.length; i++) { 74 digester.push(this); 75 digester.parse(streams[i]); 76 } 77 78 this.process(); 79 } 80 81 public void process() { 82 hDisplayerConfigs.setFast(true); 83 } 84 85 public void addDisplayerConfig(DisplayerConfig displayerConfig) { 86 addDisplayerConfig(displayerConfig.getName(), displayerConfig); 87 } 88 89 public void addDisplayerConfig(String name, DisplayerConfig displayerConfig) { 90 if (log.isDebugEnabled()) { 91 log.debug("Adding Displayer Config => Name : " + name); 92 } 93 this.lDisplayerConfigs.add(displayerConfig); 94 this.hDisplayerConfigs.put(name, displayerConfig); 95 } 96 97 public DisplayerConfig getDisplayerConfig(String displayerName) { 98 return (DisplayerConfig)hDisplayerConfigs.get(displayerName); 99 } 100 101 public List getDisplayerConfigs() { 102 return lDisplayerConfigs; 103 } 104 105 } 106 | Popular Tags |