comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java @ 1072:80aecb01d79a

Let MainValuesArtifact have a state, outputmode and facet. flys-artifacts/trunk@2556 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 24 Aug 2011 12:07:33 +0000
parents 193c49b7f6a3
children 21b9eb24bd47
comparison
equal deleted inserted replaced
1071:470087bd39e2 1072:80aecb01d79a
12 import de.intevation.artifacts.Artifact; 12 import de.intevation.artifacts.Artifact;
13 import de.intevation.artifacts.ArtifactFactory; 13 import de.intevation.artifacts.ArtifactFactory;
14 import de.intevation.artifacts.ArtifactNamespaceContext; 14 import de.intevation.artifacts.ArtifactNamespaceContext;
15 import de.intevation.artifacts.CallContext; 15 import de.intevation.artifacts.CallContext;
16 import de.intevation.artifacts.CallMeta; 16 import de.intevation.artifacts.CallMeta;
17 17 import de.intevation.flys.artifacts.states.StaticState;
18 import de.intevation.flys.artifacts.context.FLYSContext; 18 import de.intevation.flys.artifacts.context.FLYSContext;
19 19
20 import de.intevation.flys.artifacts.states.DefaultState; 20 import de.intevation.flys.artifacts.states.DefaultState;
21 import de.intevation.artifactdatabase.ProtocolUtils; 21 import de.intevation.artifactdatabase.ProtocolUtils;
22 import de.intevation.artifactdatabase.state.DefaultFacet;
22 import de.intevation.artifactdatabase.state.Facet; 23 import de.intevation.artifactdatabase.state.Facet;
23 import de.intevation.artifactdatabase.state.DefaultOutput; 24 import de.intevation.artifactdatabase.state.DefaultOutput;
24 import de.intevation.artifactdatabase.state.Output; 25 import de.intevation.artifactdatabase.state.Output;
26 import de.intevation.artifactdatabase.state.State;
25 import de.intevation.artifacts.common.utils.XMLUtils; 27 import de.intevation.artifacts.common.utils.XMLUtils;
26 28
27 /** 29 /**
28 * Artifact to access names of Points Of Interest along a segment of a river. 30 * Artifact to access names of Points Of Interest along a segment of a river.
31 * This artifact neglects (Static)FLYSArtifacts capabilities of interaction
32 * with the StateEngine by overriding the getState*-methods.
29 */ 33 */
30 public class MainValuesArtifact 34 public class MainValuesArtifact
31 extends StaticFLYSArtifact 35 extends StaticFLYSArtifact
32 { 36 {
33 /** The logger for this class. */ 37 /** The logger for this class. */
34 private static Logger logger = Logger.getLogger(MainValuesArtifact.class); 38 private static Logger logger = Logger.getLogger(MainValuesArtifact.class);
35 39
36 /** The name of the artifact. */ 40 /** The name of the artifact. */
37 public static final String ARTIFACT_NAME = "mainvalue"; 41 public static final String ARTIFACT_NAME = "mainvalue";
38 42
43
44 /**
45 * Trivial Constructor.
46 */
39 public MainValuesArtifact() { 47 public MainValuesArtifact() {
40 logger.warn("MainValuesArtifact.MainValuesartifact()"); 48 logger.debug("MainValuesArtifact.MainValuesartifact()");
41 } 49 }
50
42 51
43 /** 52 /**
44 * Gets called from factory, to set things up. 53 * Gets called from factory, to set things up.
45 * Do nothing.
46 */ 54 */
47 @Override 55 @Override
48 public void setup( 56 public void setup(
49 String identifier, 57 String identifier,
50 ArtifactFactory factory, 58 ArtifactFactory factory,
51 Object context, 59 Object context,
52 CallMeta callMeta, 60 CallMeta callMeta,
53 Document data) 61 Document data)
54 { 62 {
55 logger.warn("MainValuesArtifact.setup"); 63 logger.debug("MainValuesArtifact.setup");
56 } 64 super.setup(identifier, factory, context, callMeta, data);
57
58 /**
59 * Create the description of this MainValuesArtiface-instance.
60 *
61 * @param data some data.
62 * @param context the CallContext.
63 *
64 * @return the description of this artifact.
65 */
66 @Override
67 public Document describe(Document data, CallContext context) {
68 logger.debug("MainValuesArtifact.describe");
69
70 if (logger.isDebugEnabled()) {
71 dumpArtifact();
72 }
73
74 FLYSContext flysContext = getFlysContext(context);
75
76 Document description = XMLUtils.newDocument();
77 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
78 description,
79 ArtifactNamespaceContext.NAMESPACE_URI,
80 ArtifactNamespaceContext.NAMESPACE_PREFIX);
81
82 Element root = ProtocolUtils.createRootNode(creator);
83 description.appendChild(root);
84
85 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
86
87 Element name = ProtocolUtils.createArtNode(
88 creator, "name",
89 new String[] { "value" },
90 new String[] { getName() });
91
92 Element outs = ProtocolUtils.createArtNode(
93 creator, "outputmodes", null, null);
94 appendOutputModes(description, outs, context);
95
96 root.appendChild(name);
97 root.appendChild(outs);
98
99 return description;
100 } 65 }
101 66
102 67
103 /** 68 /**
104 * Append outputmode elements to given document. 69 * Get a list containing the one and only State.
105 * 70 * @param context ignored.
106 * @param doc Document to add outputmodes to. 71 * @return list with one and only state.
107 * @param outs Element to add outputmode elements to.
108 * @param context The given CallContext (mostly for internationalization).
109 */ 72 */
110 protected void appendOutputModes( 73 @Override
111 Document doc, 74 protected List<State> getStates(Object context) {
112 Element outs, 75 ArrayList<State> states = new ArrayList<State>();
113 CallContext context) 76 states.add(getState(null,null));
114 { 77 return states;
115 // TODO outputmodes 78 }
116 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
117 doc,
118 ArtifactNamespaceContext.NAMESPACE_URI,
119 ArtifactNamespaceContext.NAMESPACE_PREFIX);
120 79
121 FLYSContext flysContext = getFlysContext(context);
122 80
123 for (int i = 0; i < 1; i++) { 81 /**
124 logger.debug("Append output mode."); 82 * Get the "current" state.
83 * @param cc ignored.
84 * @return the "current" state.
85 */
86 @Override
87 protected State getCurrentState(Object cc) {
88 return getState();
89 }
125 90
126 // TODO create outputs. 91
127 /* 92 /**
128 List<Output> list = state.getOutputs(); 93 * Get the only possible state.
129 if (list == null || list.size() == 0) { 94 * @return the state.
130 logger.debug("-> No output modes for this state."); 95 */
131 continue; 96 protected State getState() {
132 }*/ 97 return getState(null, null);
133 List<Facet> fs = new ArrayList<Facet>(); 98 }
134 DefaultOutput mainValuesOutput = new DefaultOutput( 99
100
101 /**
102 * Get the state.
103 * @param context ignored.
104 * @param stateID ignored.
105 * @return the state.
106 */
107 @Override
108 protected State getState(Object context, String stateID) {
109 // TODO Add other outputs, prevent this code from being executed
110 // multiple times (e.g. make state serializable and a field).
111 State state = new StaticState();
112 List<Facet> fs = new ArrayList<Facet>();
113 fs.add(new MainValuesFacet());
114 facets.put(state.getID(), fs);
115 DefaultOutput mainValuesOutput = new DefaultOutput(
135 "discharge_curve", "output.discharge_curve", "image/png", 116 "discharge_curve", "output.discharge_curve", "image/png",
136 fs, 117 fs,
137 "chart"); 118 "chart");
138 119
139 // Create facets. 120 state.getOutputs().add(mainValuesOutput);
140 if (fs == null || fs.size() == 0) { 121 return state;
141 logger.debug("No facets found.");
142 continue;
143 }
144 logger.debug("Built stateless facets.");
145 // TODO remember issues here.
146 //List<Output> generated = generateOutputs(list, fs);
147 //ProtocolUtils.appendOutputModes(doc, outs, generated);
148 }
149
150 try {
151 DefaultState cur = (DefaultState) getCurrentState(context);
152 if (cur.validate(this)) {
153 List<Output> list = cur.getOutputs();
154 if (list != null && list.size() > 0) {
155 logger.debug(
156 "Append output modes for state: " + cur.getID());
157
158 List<Facet> fs = facets.get(cur.getID());
159 if (fs != null && fs.size() > 0) {
160 List<Output> generated = generateOutputs(list, fs);
161
162 logger.debug("Found " + fs.size() + " current facets.");
163 if (!generated.isEmpty()) {
164 ProtocolUtils.appendOutputModes(
165 doc, outs, generated);
166 }
167 else{
168 logger.debug("Cannot append output to generated document.");
169 }
170 }
171 else {
172 logger.debug("No facets found for the current state.");
173 }
174 }
175 }
176 }
177 catch (IllegalArgumentException iae) {
178 // state is not valid, so we do not append its outputs.
179 }
180 } 122 }
181 123
182 124
183 /* FACET IMPLEMENTATION */ 125 /* FACET IMPLEMENTATION */
184 class MainValuesFacet implements Facet { 126 class MainValuesFacet extends DefaultFacet {
127
128 public MainValuesFacet()
129 {
130 description = "facet.mainvalues";
131 name = "facet.mainvalues";
132 index = 0;
133 }
185 134
186 // TODO implement; what is index used for? 135 // TODO implement; what is index used for?
187 /** 136 /**
188 * Returns the index of this facet. 137 * Returns the index of this facet.
189 * 138 *
199 * 148 *
200 * @return the name of this facet. 149 * @return the name of this facet.
201 */ 150 */
202 public String getName() { 151 public String getName() {
203 // TODO define, static 152 // TODO define, static
153 // TODO remove, is part of DefaultFacet.
204 return "facet.mainvalue"; 154 return "facet.mainvalue";
205 } 155 }
206 156
207 157
208 /** 158 /**
209 * Returns the description of this facet. 159 * Returns the description of this facet.
210 * 160 *
211 * @return the description of this facet. 161 * @return the description of this facet.
212 */ 162 */
213 public String getDescription() { 163 public String getDescription() {
214 return null; 164 // TODO remove, is part of DefaultFacet.
165 return "facet.mainvalues";
215 } 166 }
216 167
217 168
218 /** 169 /**
219 * Returns the data this facet requires. 170 * Returns the data this facet requires.
225 */ 176 */
226 public Object getData(Artifact artifact, CallContext context) { 177 public Object getData(Artifact artifact, CallContext context) {
227 return null; 178 return null;
228 } 179 }
229 180
230 181
231 /** 182 /**
232 * Write the internal representation of a facet to a node. 183 * Create a deep copy of this Facet.
233 * 184 * @return a deep copy.
234 * @param doc A Document. 185 */
235 *
236 * @return the representation as Node.
237 */
238 public Node toXML(Document doc) {
239 return null;
240 }
241
242 public MainValuesFacet deepCopy() { 186 public MainValuesFacet deepCopy() {
243 return null; 187 MainValuesFacet copy = new MainValuesFacet();
188 copy.set(this);
189 return copy;
244 } 190 }
245 } 191 }
246 192
247 } 193 }

http://dive4elements.wald.intevation.org