1 /*
2 * Created on 09.mar.2003
3 *
4 */
5 package net.sf.panoptes.controller.digester;
6
7 import net.sf.panoptes.model.component.Component;
8 import net.sf.panoptes.model.component.registry.ComponentName;
9 import net.sf.panoptes.model.component.registry.ComponentRegistry;
10 import net.sf.panoptes.model.node.Node;
11 import net.sf.panoptes.model.node.NodeDescriptor;
12
13 import org.apache.commons.digester.Digester;
14 import org.apache.commons.digester.ObjectCreationFactory;
15 import org.xml.sax.Attributes;
16
17 /***
18 * Digester factory to create ComponentNodes connected to Components
19 *
20 * @author Dag Liodden
21 *
22 */
23
24 public class ComponentFactory implements ObjectCreationFactory {
25
26 private Digester digester;
27 ComponentRegistry componentRegistry;
28
29 public ComponentFactory(ComponentRegistry componentRegistry) {
30 this.componentRegistry = componentRegistry;
31 }
32
33 /* (non-Javadoc)
34 * @see org.apache.commons.digester.ObjectCreationFactory#createObject(org.xml.sax.Attributes)
35 */
36 public Object createObject(Attributes attributes) throws Exception {
37 ComponentName componentName = new ComponentName(attributes.getValue("component-name"));
38 String className = attributes.getValue("class");
39
40 String name = attributes.getValue("name");
41 String description = attributes.getValue("description");
42
43 Component component = (Component) Class.forName(className).newInstance();
44
45 if (name != null) {
46 component.setConfigDescriptor(new NodeDescriptor(name, description));
47 }
48
49 String iconName = attributes.getValue("icon");
50 if (iconName != null) component.setIcon(Node.createImage(iconName));
51
52 componentRegistry.registerComponent(component, componentName);
53
54 return component;
55 }
56
57 /* (non-Javadoc)
58 * @see org.apache.commons.digester.ObjectCreationFactory#getDigester()
59 */
60 public Digester getDigester() {
61 return digester;
62 }
63
64 /* (non-Javadoc)
65 * @see org.apache.commons.digester.ObjectCreationFactory#setDigester(org.apache.commons.digester.Digester)
66 */
67 public void setDigester(Digester digester) {
68 this.digester = digester;
69 }
70 }
This page was automatically generated by Maven