Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java @ 8086:7ede7904c8a5
Be more tolerant with not existing artifact configurations.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Tue, 12 Aug 2014 10:57:53 +0200 |
parents | cd04a7389389 |
children | 2fcbcc9bb59a |
comparison
equal
deleted
inserted
replaced
8085:75e62ea0e307 | 8086:7ede7904c8a5 |
---|---|
204 * @param context the RiverContext. | 204 * @param context the RiverContext. |
205 */ | 205 */ |
206 protected void configureTransitions(Document config, RiverContext context) { | 206 protected void configureTransitions(Document config, RiverContext context) { |
207 TransitionEngine engine = new TransitionEngine(); | 207 TransitionEngine engine = new TransitionEngine(); |
208 | 208 |
209 Document[] artifacts = getArtifactConfigurations(config); | 209 List<Document> artifacts = getArtifactConfigurations(config); |
210 logger.info("Found " + artifacts.length + " artifacts in the config."); | 210 logger.info("Found " + artifacts.size() + " artifacts in the config."); |
211 | 211 |
212 for (Document doc: artifacts) { | 212 for (Document doc: artifacts) { |
213 | 213 |
214 String artName = (String) XMLUtils.xpath( | 214 String artName = (String) XMLUtils.xpath( |
215 doc, XPATH_ARTIFACT_NAME, XPathConstants.STRING); | 215 doc, XPATH_ARTIFACT_NAME, XPathConstants.STRING); |
246 * | 246 * |
247 * @param config The global configuration. | 247 * @param config The global configuration. |
248 * | 248 * |
249 * @return an array of Artifact configurations. | 249 * @return an array of Artifact configurations. |
250 */ | 250 */ |
251 protected Document[] getArtifactConfigurations(Document config) { | 251 protected List<Document> getArtifactConfigurations(Document config) { |
252 NodeList artifacts = (NodeList) XMLUtils.xpath( | 252 NodeList artifacts = (NodeList) XMLUtils.xpath( |
253 config, XPATH_ARTIFACTS, XPathConstants.NODESET); | 253 config, XPATH_ARTIFACTS, XPathConstants.NODESET); |
254 | 254 |
255 int count = artifacts.getLength(); | 255 int count = artifacts.getLength(); |
256 | 256 |
257 Document[] artifactDocs = new Document[count]; | 257 ArrayList<Document> docs = new ArrayList<Document>(count); |
258 | 258 |
259 for (int i = 0; i < count; i++) { | 259 for (int i = 0; i < count; i++) { |
260 Element tmp = (Element) artifacts.item(i); | 260 Element tmp = (Element) artifacts.item(i); |
261 | 261 |
262 String xlink = tmp.getAttribute(XPATH_XLINK); | 262 String xlink = tmp.getAttribute(XPATH_XLINK); |
263 xlink = Config.replaceConfigDir(xlink); | 263 xlink = Config.replaceConfigDir(xlink); |
264 | 264 |
265 File artifactFile = new File(xlink); | 265 File file = new File(xlink); |
266 artifactDocs[i] = XMLUtils.parseDocument(artifactFile); | 266 if (!file.isFile() || !file.canRead()) { |
267 } | 267 logger.warn("Artifact configuration '" + file + "' not found."); |
268 | 268 continue; |
269 return artifactDocs; | 269 } |
270 | |
271 Document doc = XMLUtils.parseDocument(file); | |
272 if (doc != null) { | |
273 docs.add(doc); | |
274 } | |
275 } | |
276 return docs; | |
270 } | 277 } |
271 | 278 |
272 | 279 |
273 /** | 280 /** |
274 * This method initializes the transition configuration. | 281 * This method initializes the transition configuration. |
277 * @param context the RiverContext. | 284 * @param context the RiverContext. |
278 */ | 285 */ |
279 protected void configureStates(Document config, RiverContext context) { | 286 protected void configureStates(Document config, RiverContext context) { |
280 StateEngine engine = new StateEngine(); | 287 StateEngine engine = new StateEngine(); |
281 | 288 |
282 Document[] artifacts = getArtifactConfigurations(config); | 289 List<Document> artifacts = getArtifactConfigurations(config); |
283 logger.info("Found " + artifacts.length + " artifacts in the config."); | 290 logger.info("Found " + artifacts.size() + " artifacts in the config."); |
284 | 291 |
285 for (Document doc: artifacts) { | 292 for (Document doc: artifacts) { |
286 List<State> states = new ArrayList<State>(); | 293 List<State> states = new ArrayList<State>(); |
287 | 294 |
288 String artName = (String) XMLUtils.xpath( | 295 String artName = (String) XMLUtils.xpath( |