Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 119:84c0b151203e
Added a FLYSArtifact that serves as the default artifact for the FLYS application.
flys-artifacts/trunk@1438 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 09 Mar 2011 11:29:07 +0000 |
parents | |
children | e0ded17a4846 |
comparison
equal
deleted
inserted
replaced
118:888e3b1dcdd9 | 119:84c0b151203e |
---|---|
1 package de.intevation.flys.artifacts; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.w3c.dom.Document; | |
8 | |
9 import de.intevation.artifacts.ArtifactFactory; | |
10 import de.intevation.artifacts.CallContext; | |
11 | |
12 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
13 import de.intevation.artifacts.common.utils.XMLUtils; | |
14 | |
15 import de.intevation.artifactdatabase.DefaultArtifact; | |
16 import de.intevation.artifactdatabase.data.StateData; | |
17 import de.intevation.artifactdatabase.state.State; | |
18 import de.intevation.artifactdatabase.state.StateEngine; | |
19 | |
20 import de.intevation.flys.artifacts.context.FLYSContext; | |
21 | |
22 | |
23 /** | |
24 * The defaul FLYS artifact. | |
25 * | |
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
27 */ | |
28 public abstract class FLYSArtifact extends DefaultArtifact { | |
29 | |
30 /** The logger that is used in this artifact.*/ | |
31 private static Logger logger = Logger.getLogger(FLYSArtifact.class); | |
32 | |
33 | |
34 /** The XPath to the name of the artifact in its configuration. */ | |
35 public static final String XPATH_ARTIFACT_NAME = "@name"; | |
36 | |
37 | |
38 /** The identifier of the current state. */ | |
39 protected String currentStateId; | |
40 | |
41 /** The name of the artifact.*/ | |
42 protected String name; | |
43 | |
44 | |
45 /** | |
46 * Initialize the artifact and insert new data if <code>data</code> contains | |
47 * information necessary for this artifact. | |
48 * | |
49 * @param identifier The UUID. | |
50 * @param factory The factory that is used to create this artifact. | |
51 * @param context The CallContext. | |
52 * @param data Some optional data. | |
53 */ | |
54 @Override | |
55 public void setup( | |
56 String identifier, | |
57 ArtifactFactory factory, | |
58 Object context, | |
59 Document data) | |
60 { | |
61 logger.debug("Setup this artifact with the uuid: " + identifier); | |
62 | |
63 super.setup(identifier, factory, context, data); | |
64 | |
65 String name = XMLUtils.xpathString( | |
66 data, XPATH_ARTIFACT_NAME, ArtifactNamespaceContext.INSTANCE); | |
67 setName(name); | |
68 | |
69 FLYSContext flysContext = (FLYSContext) context; | |
70 StateEngine engine = (StateEngine) flysContext.get( | |
71 FLYSContext.STATE_ENGINE_KEY); | |
72 | |
73 List<State> states = engine.getStates(name); | |
74 | |
75 setCurrentState(states.get(0)); | |
76 } | |
77 | |
78 | |
79 /** | |
80 * Insert new data included in <code>input</code> into the current state. | |
81 * | |
82 * @param target XML document that contains new data. | |
83 * @param context The CallContext. | |
84 * | |
85 * @return a document that contains a SUCCESS or FAILURE message. | |
86 */ | |
87 @Override | |
88 public Document feed(Document target, CallContext context) { | |
89 Document result = XMLUtils.newDocument(); | |
90 | |
91 // TODO IMPLEMENT ME | |
92 | |
93 return result; | |
94 } | |
95 | |
96 | |
97 /** | |
98 * This method returns the name of the concrete artifact. | |
99 * | |
100 * @return the name of the concrete artifact. | |
101 */ | |
102 public String getName() { | |
103 return name; | |
104 } | |
105 | |
106 | |
107 | |
108 /** | |
109 * This method sets the name of this artifact. | |
110 * | |
111 * @param name the name for this artifact. | |
112 */ | |
113 protected void setName(String name) { | |
114 this.name = name; | |
115 } | |
116 | |
117 | |
118 /** | |
119 * Returns the identifier of the current state. | |
120 * | |
121 * @return the identifier of the current state. | |
122 */ | |
123 protected String getCurrentStateId() { | |
124 return currentStateId; | |
125 } | |
126 | |
127 | |
128 /** | |
129 * Sets the identifier of the current state. | |
130 * | |
131 * @param id the identifier of a state. | |
132 */ | |
133 protected void setCurrentStateId(String id) { | |
134 currentStateId = id; | |
135 } | |
136 | |
137 | |
138 | |
139 /** | |
140 * Set the current state of this artifact. <b>NOTE</b>We don't store the | |
141 * State object itself - which is not necessary - but its identifier. So | |
142 * this method will just call the setCurrentStateId() method with the | |
143 * identifier of <i>state</i>. | |
144 * | |
145 * @param state The new current state. | |
146 */ | |
147 protected void setCurrentState(State state) { | |
148 setCurrentStateId(state.getID()); | |
149 } | |
150 | |
151 | |
152 /** | |
153 * Returns the current state of the artifact. | |
154 * | |
155 * @return the current State of the artifact. | |
156 */ | |
157 protected State getCurrentState(Object context) { | |
158 FLYSContext flysContext = (FLYSContext) context; | |
159 StateEngine engine = (StateEngine) flysContext.get( | |
160 FLYSContext.STATE_ENGINE_KEY); | |
161 | |
162 return engine.getState(getCurrentStateId()); | |
163 } | |
164 | |
165 | |
166 /** | |
167 * This method extracts the data that is contained in the FEED document. | |
168 * | |
169 * @param feed The FEED document. | |
170 * @param xpath The XPath that points to the data nodes. | |
171 * | |
172 * @return a StateData array. | |
173 */ | |
174 public StateData[] extractData(Document feed, String xpath) { | |
175 | |
176 // TODO IMPLEMENT ME | |
177 return null; | |
178 } | |
179 } | |
180 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |