comparison artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java @ 105:265f150f4f7f

Added an abstract implementation of a State. artifacts/trunk@1290 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 04 Feb 2011 08:55:17 +0000
parents
children ece0fdb07975
comparison
equal deleted inserted replaced
104:26bfff409dd3 105:265f150f4f7f
1 /*
2 * Copyright (c) 2011 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8 package de.intevation.artifactdatabase.state;
9
10 import java.util.HashMap;
11 import java.util.Map;
12
13 import org.w3c.dom.Document;
14 import org.w3c.dom.Node;
15
16 import de.intevation.artifacts.CallContext;
17
18 import de.intevation.artifactdatabase.data.StateData;
19
20
21 /**
22 * An abstract implementation of a {@link State}. It implements some basic
23 * methods that return the id, description and data. The methods
24 * <code>describe()</code> and <code>setup()</code> depend on the concrete class
25 * and need to be implemented by those.
26 */
27 public abstract class AbstractState implements State {
28
29 /** The ID of the state. */
30 protected String id;
31
32 /** The description of the state. */
33 protected String description;
34
35 /** The data provided by this state. */
36 protected Map<String, StateData> data;
37
38
39 /**
40 * The default constructor.
41 *
42 * @param id The ID of the state.
43 * @param description The description of the state.
44 */
45 public AbstractState(String id, String description) {
46 this.id = id;
47 this.description = description;
48 }
49
50
51 /**
52 * Returns the ID of the state.
53 *
54 * @return the ID of the state.
55 */
56 public String getID() {
57 return id;
58 }
59
60
61 /**
62 * Set the ID of the state.
63 *
64 * @param id The ID of the state.
65 */
66 public void setID(String id) {
67 this.id = id;
68 }
69
70
71 /**
72 * Returns the description of the state.
73 *
74 * @return the description of the state.
75 */
76 public String getDescription() {
77 return description;
78 }
79
80
81 /**
82 * Set the description of the state.
83 *
84 * @param description The description of the state.
85 */
86 public void setDescription(String description) {
87 this.description = description;
88 }
89
90
91 /**
92 * Returns the data of the state.
93 *
94 * @return the data of the state.
95 */
96 public Map<String, StateData> getData() {
97 return data;
98 }
99
100
101 /**
102 * Add new data to the state. NOTE: If there is already an object existing
103 * with the key <i>name</i>, this object is overwritten by the new value.
104 *
105 * @param name The name of the data object.
106 * @param StateData The data object.
107 */
108 public void addData(String name, StateData data) {
109 if (this.data == null) {
110 this.data = new HashMap<String, StateData>();
111 }
112
113 this.data.put(name, data);
114 }
115
116
117 /**
118 * Initialize the state based on the state node in the configuration. This
119 * method needs to be implemented by concrete subclasses.
120 *
121 * @param config The state configuration node.
122 */
123 public abstract void setup(Node config);
124
125
126 /**
127 * Describes the UI of the state. This method needs to be implemented by
128 * concrete subclasses.
129 *
130 * @param document Describe doucment.
131 * @param rootNode Parent node for all new elements.
132 * @param context The CallContext.
133 * @param uuid The uuid of an artifact.
134 */
135 public abstract void describe(
136 Document document,
137 Node rootNode,
138 CallContext context,
139 String uuid
140 );
141 }
142 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org