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