KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > formview > displayer > DisplayersConfigResources


1 package net.sourceforge.formview.displayer;
2
3 import java.io.IOException JavaDoc;
4 import java.io.InputStream JavaDoc;
5 import java.io.Serializable JavaDoc;
6 import java.net.URL JavaDoc;
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
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 JavaDoc;
16
17 /**
18  * Description : Displayers Config Resources
19  * wich load file displayers-config.xml
20  *
21  * @version 1.0.0
22  * @author <a HREF="mailto:angelo.zerr@gmail.com">Angelo ZERR</a>
23  *
24  */

25 public class DisplayersConfigResources implements Serializable JavaDoc {
26
27     private static final long serialVersionUID = 1L;
28     
29     protected static Log log = LogFactory.getLog(DisplayersConfigResources.class);
30
31     /**
32      * <code>FastHashMap</code> of <code>DisplayerConfig</code>s stored under
33      * a <code>name</code> key.
34      */

35     protected FastHashMap hDisplayerConfigs = new FastHashMap();
36     
37     protected List JavaDoc lDisplayerConfigs = new ArrayList JavaDoc();
38  
39     /**
40      * Create a DisplayersConfigResources object from an InputStream.
41      * @param in InputStream to a displayer-config.xml configuration file.
42      * It's the client's
43      * responsibility to close this stream.
44      * @throws IOException
45      * @throws SAXException if the displayer-config. XML files are not valid or well
46      * formed.
47      */

48     public DisplayersConfigResources(InputStream JavaDoc in) throws IOException JavaDoc, SAXException JavaDoc {
49         this(new InputStream JavaDoc[]{in});
50     }
51     
52     /**
53      * Create a DisplayersConfigResources object from an InputStream.
54      *
55      * @param stream displayers-config.xml
56      * configuration files that will be read in order and merged into this object.
57      * It's the client's responsibility to close these streams.
58      * @throws IOException
59      * @throws SAXException if the displayers-config.xml XML file are not valid or well
60      * formed.
61      */

62     public DisplayersConfigResources(InputStream JavaDoc[] streams)
63         throws IOException JavaDoc, SAXException JavaDoc {
64         super();
65         
66         URL JavaDoc rulesUrl = this.getClass().getResource("digester-rules-displayers.xml");
67         Digester digester = DigesterLoader.createDigester(rulesUrl);
68         digester.setNamespaceAware(true);
69         //digester.setValidating(true);
70
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 JavaDoc 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 JavaDoc displayerName) {
98         return (DisplayerConfig)hDisplayerConfigs.get(displayerName);
99     }
100     
101     public List JavaDoc getDisplayerConfigs() {
102         return lDisplayerConfigs;
103     }
104
105 }
106
Popular Tags