KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > panoptes > controller > digester > ConfiguratorFactory


1 /*
2  * Created on 22.mar.2003
3  *
4  */

5 package net.sf.panoptes.controller.digester;
6
7 import java.util.HashMap JavaDoc;
8
9 import javax.management.ObjectName JavaDoc;
10
11 import org.apache.commons.digester.Digester;
12 import org.apache.commons.digester.ObjectCreationFactory;
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.xml.sax.Attributes JavaDoc;
16
17 import net.sf.panoptes.registry.ConfiguratorRegistry;
18
19 /**
20  *
21  *
22  * @author Dag Liodden
23  * @version 0.1
24  */

25 public class ConfiguratorFactory implements ObjectCreationFactory {
26
27     private Digester digester;
28     private Log log = LogFactory.getLog(getClass());
29     ConfiguratorRegistry configRegistry;
30
31     public ConfiguratorFactory(ConfiguratorRegistry configRegistry) {
32         this.configRegistry = configRegistry;
33     }
34
35     /* (non-Javadoc)
36      * @see org.apache.commons.digester.ObjectCreationFactory#createObject(org.xml.sax.Attributes)
37      */

38     public Object JavaDoc createObject(Attributes JavaDoc attributes) throws Exception JavaDoc {
39         String JavaDoc name = attributes.getValue("name");
40         String JavaDoc configuratorClassName = attributes.getValue("configuratorClass");
41         String JavaDoc className = attributes.getValue("pojoClass");
42         String JavaDoc mbeanClassName = attributes.getValue("mbeanClass");
43         String JavaDoc guiType = attributes.getValue("gui");
44         if (guiType == null) log.warn("Configurator " + name + " does not define the gui-attribtue and will not be displayed");
45         ObjectName JavaDoc objectName = null;
46         if (attributes.getValue("objectName") != null) {
47             objectName = new ObjectName JavaDoc(attributes.getValue("objectName"));
48         }
49         String JavaDoc iconName = attributes.getValue("iconName");
50         
51         HashMap JavaDoc atts = new HashMap JavaDoc();
52         for (int i = 0; i < attributes.getLength(); i++) {
53             atts.put(attributes.getQName(i), attributes.getValue(i));
54         }
55         
56         return configRegistry.addConfigurator(name, guiType, configuratorClassName, objectName, mbeanClassName, className, iconName, atts);
57         
58     }
59
60     /* (non-Javadoc)
61      * @see org.apache.commons.digester.ObjectCreationFactory#getDigester()
62      */

63     public Digester getDigester() {
64         return digester;
65     }
66
67     /* (non-Javadoc)
68      * @see org.apache.commons.digester.ObjectCreationFactory#setDigester(org.apache.commons.digester.Digester)
69      */

70     public void setDigester(Digester digester) {
71         this.digester = digester;
72     }
73 }
74
Popular Tags