Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 109:9891d133f08d
Improved the init process of the WINFOArtifact - there are two new states to select the river and the gauge.
flys-artifacts/trunk@1294 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 04 Feb 2011 11:18:59 +0000 |
parents | beb991dc4827 |
children | ff3335057f11 |
comparison
equal
deleted
inserted
replaced
108:50273a391e53 | 109:9891d133f08d |
---|---|
1 package de.intevation.flys.artifacts; | 1 package de.intevation.flys.artifacts; |
2 | 2 |
3 import java.io.IOException; | 3 import java.io.IOException; |
4 import java.io.OutputStream; | 4 import java.io.OutputStream; |
5 import java.util.List; | |
6 | |
7 import javax.xml.xpath.XPathConstants; | |
5 | 8 |
6 import org.w3c.dom.Document; | 9 import org.w3c.dom.Document; |
7 | 10 |
8 import org.apache.log4j.Logger; | 11 import org.apache.log4j.Logger; |
9 | 12 |
10 import de.intevation.artifacts.ArtifactFactory; | 13 import de.intevation.artifacts.ArtifactFactory; |
11 import de.intevation.artifacts.CallContext; | 14 import de.intevation.artifacts.CallContext; |
12 | 15 |
16 import de.intevation.artifacts.common.utils.XMLUtils; | |
17 | |
13 import de.intevation.artifactdatabase.DefaultArtifact; | 18 import de.intevation.artifactdatabase.DefaultArtifact; |
19 import de.intevation.artifactdatabase.state.State; | |
20 import de.intevation.artifactdatabase.state.StateEngine; | |
21 | |
22 import de.intevation.flys.artifacts.context.FLYSContext; | |
14 | 23 |
15 | 24 |
16 /** | 25 /** |
17 * The default WINFO artifact. | 26 * The default WINFO artifact. |
18 * | 27 * |
21 public class WINFOArtifact extends DefaultArtifact { | 30 public class WINFOArtifact extends DefaultArtifact { |
22 | 31 |
23 /** The logger for this class */ | 32 /** The logger for this class */ |
24 private static Logger logger = Logger.getLogger(WINFOArtifact.class); | 33 private static Logger logger = Logger.getLogger(WINFOArtifact.class); |
25 | 34 |
35 /** The name of the artifact. */ | |
36 public static final String ARTIFACT_NAME = "winfo"; | |
37 | |
38 /** The XPath to the name of the artifact in its configuration. */ | |
39 public static final String XPATH_ARTIFACT_NAME = "@name"; | |
40 | |
41 /** The current state. */ | |
42 protected State currentState; | |
43 | |
26 | 44 |
27 /** | 45 /** |
28 * The default constructor. | 46 * The default constructor. |
29 */ | 47 */ |
30 public WINFOArtifact() { | 48 public WINFOArtifact() { |
31 super(); | 49 super(); |
50 } | |
51 | |
52 | |
53 /** | |
54 * Set the current state of this artifact. | |
55 * | |
56 * @param state The new current state. | |
57 */ | |
58 protected void setCurrentState(State state) { | |
59 currentState = state; | |
32 } | 60 } |
33 | 61 |
34 | 62 |
35 /** | 63 /** |
36 * Initialize the artifact and insert new data if <code>data</code> contains | 64 * Initialize the artifact and insert new data if <code>data</code> contains |
49 Document data) | 77 Document data) |
50 { | 78 { |
51 logger.debug("Setup this artifact with the uuid: " + identifier); | 79 logger.debug("Setup this artifact with the uuid: " + identifier); |
52 | 80 |
53 super.setup(identifier, factory, context, data); | 81 super.setup(identifier, factory, context, data); |
54 } | |
55 | 82 |
83 FLYSContext flysContext = (FLYSContext) context; | |
84 StateEngine engine = (StateEngine) flysContext.get( | |
85 FLYSContext.STATE_ENGINE_KEY); | |
56 | 86 |
57 /** | 87 List<State> states = engine.getStates(ARTIFACT_NAME); |
58 * This method handles requests for changing the current state of an | |
59 * artifact. | |
60 * | |
61 * @param target The target of the advance action. | |
62 * @param context The CallContext. | |
63 * | |
64 * @return the result of the advance action. | |
65 */ | |
66 @Override | |
67 public Document advance(Document target, CallContext context) { | |
68 logger.debug("Advance to another state."); | |
69 | 88 |
70 return super.advance(target, context); | 89 setCurrentState(states.get(0)); |
71 } | |
72 | |
73 | |
74 /** | |
75 * This methods introduces new data to the current artifact. | |
76 * | |
77 * @param data A document containing the new data. | |
78 * @param context The CallContext. | |
79 * | |
80 * @return the result of the feed action. | |
81 */ | |
82 @Override | |
83 public Document feed(Document data, CallContext context) { | |
84 logger.debug("Feed the artifact with new data."); | |
85 | |
86 return super.feed(data, context); | |
87 } | 90 } |
88 | 91 |
89 | 92 |
90 /** | 93 /** |
91 * This method returns a description of this artifact. | 94 * This method returns a description of this artifact. |
95 * | 98 * |
96 * @return the description of this artifact. | 99 * @return the description of this artifact. |
97 */ | 100 */ |
98 public Document describe(Document data, CallContext context) { | 101 public Document describe(Document data, CallContext context) { |
99 logger.debug("Describe the artifact."); | 102 logger.debug("Describe the artifact."); |
103 logger.debug("The current state is: " + currentState.getID()); | |
100 | 104 |
101 return super.describe(data, context); | 105 return super.describe(data, context); |
102 } | 106 } |
103 | |
104 | |
105 /** | |
106 * Call an output target. | |
107 * | |
108 * @param format The format for the output. | |
109 * @param outStream The output stream. | |
110 * @param context The CallContext. | |
111 * @throws IOException if an error occured while writing the result to the | |
112 * output stream. | |
113 */ | |
114 public void out( | |
115 Document format, OutputStream outStream, CallContext context) | |
116 throws IOException | |
117 { | |
118 logger.debug("Call an out target."); | |
119 | |
120 super.out(format, outStream, context); | |
121 } | |
122 } | 107 } |
123 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 108 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |