comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java @ 126:b18aebd1342f

Added an abstract base class DefaultState for States. flys-artifacts/trunk@1466 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 14 Mar 2011 15:43:12 +0000
parents
children 206312c2aa76
comparison
equal deleted inserted replaced
125:25593857b8f8 126:b18aebd1342f
1 package de.intevation.flys.artifacts.states;
2
3 import java.util.Collection;
4 import java.util.Map;
5
6 import org.apache.log4j.Logger;
7
8 import org.w3c.dom.Document;
9 import org.w3c.dom.Element;
10 import org.w3c.dom.Node;
11
12 import de.intevation.artifacts.CallContext;
13 import de.intevation.artifacts.ArtifactNamespaceContext;
14
15 import de.intevation.artifacts.common.utils.XMLUtils;
16
17 import de.intevation.artifactdatabase.ProtocolUtils;
18 import de.intevation.artifactdatabase.data.StateData;
19 import de.intevation.artifactdatabase.state.AbstractState;
20
21 import de.intevation.flys.artifacts.resources.Resources;
22
23
24 /**
25 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
26 */
27 public abstract class DefaultState extends AbstractState {
28
29 /** The logger that is used in this class.*/
30 private static Logger logger = Logger.getLogger(DefaultState.class);
31
32
33 public Element describe(
34 Document document,
35 Node root,
36 CallContext context,
37 String uuid)
38 {
39 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
40 document,
41 ArtifactNamespaceContext.NAMESPACE_URI,
42 ArtifactNamespaceContext.NAMESPACE_PREFIX);
43
44 Element ui = ProtocolUtils.createArtNode(
45 creator, "dynamic", null, null);
46
47 Map<String, StateData> theData = getData();
48 if (theData == null) {
49 return ui;
50 }
51
52 Collection<StateData> dataItems = theData.values();
53
54 for (StateData data: dataItems) {
55 String name = data.getName();
56 Element select = createData(creator, data, context);
57
58 Element choices = ProtocolUtils.createArtNode(
59 creator, "choices", null, null);
60
61 select.appendChild(choices);
62 ui.appendChild(select);
63
64 Element[] items = createItems(creator, name, context);
65 for (Element item: items) {
66 choices.appendChild(item);
67 }
68 }
69
70 return ui;
71 }
72
73
74 /**
75 * This method creates the root node that contains the list of selectable
76 * items.
77 *
78 * @param cr The ElementCreator.
79 * @param name The name of the amount of data.
80 *
81 * @return the root node of the item list.
82 */
83 protected Element createData(
84 XMLUtils.ElementCreator cr,
85 StateData data,
86 CallContext context)
87 {
88 Element select = ProtocolUtils.createArtNode(
89 cr, "select", null, null);
90 cr.addAttr(select, "name", data.getName());
91
92 Element label = ProtocolUtils.createArtNode(
93 cr, "label", null, null);
94
95 label.setTextContent(Resources.getMsg(
96 context.getMeta(),
97 getID(),
98 getID()));
99
100 return select;
101 }
102
103
104 /**
105 * This method creates a list of items. These items represent the amount of
106 * input data that is possible for this state.
107 *
108 * @param cr The ElementCreator.
109 * @param name The name of the amount of data.
110 *
111 * @return a list of items.
112 */
113 protected abstract Element[] createItems(
114 XMLUtils.ElementCreator cr,
115 String name,
116 CallContext context);
117 }
118 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org