Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java @ 8856:5e38e2924c07 3.2.x
Fix code style.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 20:12:01 +0100 |
parents | af415396d9ca |
children | 951a4af24a09 0a5239a1e46e |
comparison
equal
deleted
inserted
replaced
8855:d7c005e12af0 | 8856:5e38e2924c07 |
---|---|
77 /** The log that is used in this artifact. */ | 77 /** The log that is used in this artifact. */ |
78 private static Logger log = Logger.getLogger(D4EArtifact.class); | 78 private static Logger log = Logger.getLogger(D4EArtifact.class); |
79 | 79 |
80 public static final String COMPUTING_CACHE = "computed.values"; | 80 public static final String COMPUTING_CACHE = "computed.values"; |
81 | 81 |
82 /** The XPath that points to the input data elements of the FEED document. */ | 82 /** XPath that points to the input data elements of the FEED document. */ |
83 public static final String XPATH_FEED_INPUT = | 83 public static final String XPATH_FEED_INPUT = |
84 "/art:action/art:data/art:input"; | 84 "/art:action/art:data/art:input"; |
85 | 85 |
86 /** The XPath that points to the name of the target state of ADVANCE. */ | 86 /** The XPath that points to the name of the target state of ADVANCE. */ |
87 public static final String XPATH_ADVANCE_TARGET = | 87 public static final String XPATH_ADVANCE_TARGET = |
95 | 95 |
96 /** Path to 'ids' (data) in doc that comes from datacage. */ | 96 /** Path to 'ids' (data) in doc that comes from datacage. */ |
97 public static final String XPATH_IDS = "/art:action/art:ids/@value"; | 97 public static final String XPATH_IDS = "/art:action/art:ids/@value"; |
98 | 98 |
99 /** Path to 'target_out' (data) in doc that comes from datacage. */ | 99 /** Path to 'target_out' (data) in doc that comes from datacage. */ |
100 public static final String XPATH_TARGET_OUT = "/art:action/art:target_out/@value"; | 100 public static final String XPATH_TARGET_OUT = |
101 "/art:action/art:target_out/@value"; | |
101 | 102 |
102 /** The constant string that shows that an operation was successful. */ | 103 /** The constant string that shows that an operation was successful. */ |
103 public static final String OPERATION_SUCCESSFUL = "SUCCESS"; | 104 public static final String OPERATION_SUCCESSFUL = "SUCCESS"; |
104 | 105 |
105 /** The constant string that shows that an operation failed. */ | 106 /** The constant string that shows that an operation failed. */ |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
181 | 182 |
182 /** | 183 /** |
183 * Initialize the artifact and insert new data if <code>data</code> contains | 184 * Initialize the artifact and insert new data |
185 * if <code>data</code> contains | |
184 * information necessary for this artifact. | 186 * information necessary for this artifact. |
185 * | 187 * |
186 * @param identifier The UUID. | 188 * @param identifier The UUID. |
187 * @param factory The factory that is used to create this artifact. | 189 * @param factory The factory that is used to create this artifact. |
188 * @param context The CallContext. | 190 * @param context The CallContext. |
247 } | 249 } |
248 } | 250 } |
249 this.facets.put(currentState, staticFacets); | 251 this.facets.put(currentState, staticFacets); |
250 } | 252 } |
251 | 253 |
252 protected void handleInitModel(Document data, Object context, CallMeta callMeta) { | 254 protected void handleInitModel( |
255 Document data, | |
256 Object context, | |
257 CallMeta callMeta | |
258 ) { | |
253 RiverContext flysContext = RiverUtils.getFlysContext(context); | 259 RiverContext flysContext = RiverUtils.getFlysContext(context); |
254 | 260 |
255 String model = XMLUtils.xpathString( | 261 String model = XMLUtils.xpathString( |
256 data, | 262 data, |
257 XPATH_MODEL_ARTIFACT, | 263 XPATH_MODEL_ARTIFACT, |
355 } | 361 } |
356 | 362 |
357 | 363 |
358 /** | 364 /** |
359 * (called from setup). | 365 * (called from setup). |
360 * @param artifact master-artifact (if any, otherwise initialize is not called). | 366 * @param artifact master-artifact |
367 * (if any, otherwise initialize is not called). | |
361 */ | 368 */ |
362 protected void initialize( | 369 protected void initialize( |
363 Artifact artifact, | 370 Artifact artifact, |
364 Object context, | 371 Object context, |
365 CallMeta callMeta) | 372 CallMeta callMeta) |
375 name = flys.name; | 382 name = flys.name; |
376 data = flys.cloneData(); | 383 data = flys.cloneData(); |
377 facets = flys.cloneFacets(); | 384 facets = flys.cloneFacets(); |
378 // Do not clone filter facets! | 385 // Do not clone filter facets! |
379 | 386 |
380 ArrayList<String> stateIds = (ArrayList<String>) getPreviousStateIds(); | 387 ArrayList<String> stateIds = (ArrayList<String>) getPreviousStateIds(); |
381 ArrayList<String> toInitialize = (ArrayList<String>) stateIds.clone(); | 388 ArrayList<String> toInitialize = (ArrayList<String>) stateIds.clone(); |
382 | 389 |
383 toInitialize.add(getCurrentStateId()); | 390 toInitialize.add(getCurrentStateId()); |
384 | 391 |
385 for (String stateId: toInitialize) { | 392 for (String stateId: toInitialize) { |
431 | 438 |
432 String fName = facetElement.getAttribute("name"); | 439 String fName = facetElement.getAttribute("name"); |
433 | 440 |
434 int index; | 441 int index; |
435 try { | 442 try { |
436 index = Integer.parseInt(facetElement.getAttribute("index")); | 443 index = Integer.parseInt( |
444 facetElement.getAttribute("index")); | |
437 } | 445 } |
438 catch (NumberFormatException nfe) { | 446 catch (NumberFormatException nfe) { |
439 log.warn(nfe); | 447 log.warn(nfe); |
440 index = 0; | 448 index = 0; |
441 } | 449 } |
442 if (log.isDebugEnabled()) { | 450 if (log.isDebugEnabled()) { |
443 log.debug("Creating filter facet " + fName + " with index " + index + | 451 log.debug("Creating filter facet " + fName |
444 " for out " + oName); | 452 + " with index " + index |
453 + " for out " + oName); | |
445 } | 454 } |
446 facets.add(new DefaultFacet(index, fName, "")); | 455 facets.add(new DefaultFacet(index, fName, "")); |
447 } | 456 } |
448 | 457 |
449 if (!facets.isEmpty()) { | 458 if (!facets.isEmpty()) { |
533 Element root = ProtocolUtils.createRootNode(creator); | 542 Element root = ProtocolUtils.createRootNode(creator); |
534 description.appendChild(root); | 543 description.appendChild(root); |
535 | 544 |
536 State current = getCurrentState(context); | 545 State current = getCurrentState(context); |
537 | 546 |
538 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); | 547 ProtocolUtils.appendDescribeHeader( |
548 creator, root, identifier(), hash()); | |
539 ProtocolUtils.appendState(creator, root, current); | 549 ProtocolUtils.appendState(creator, root, current); |
540 ProtocolUtils.appendReachableStates(creator, root, reachable); | 550 ProtocolUtils.appendReachableStates(creator, root, reachable); |
541 | 551 |
542 appendBackgroundActivity(creator, root, context); | 552 appendBackgroundActivity(creator, root, context); |
543 | 553 |
938 * This method returns the value of a StateData object stored in the data | 948 * This method returns the value of a StateData object stored in the data |
939 * pool of this Artifact is Boolean using Boolean.valueOf(). | 949 * pool of this Artifact is Boolean using Boolean.valueOf(). |
940 * | 950 * |
941 * @param name The name of the StateData object. | 951 * @param name The name of the StateData object. |
942 * | 952 * |
943 * @return a Boolean representing the value of the data object or null if no | 953 * @return a Boolean representing the value of the data object or |
944 * such object is existing. | 954 * null if no such object is existing. |
945 */ | 955 */ |
946 public Boolean getDataAsBoolean(String name) { | 956 public Boolean getDataAsBoolean(String name) { |
947 String value = getDataAsString(name); | 957 String value = getDataAsString(name); |
948 | 958 |
949 if (value == null || value.length() == 0) { | 959 if (value == null || value.length() == 0) { |
962 public void addStringData(String name, String value) { | 972 public void addStringData(String name, String value) { |
963 addData(name, new DefaultStateData(name, null, null, value)); | 973 addData(name, new DefaultStateData(name, null, null, value)); |
964 } | 974 } |
965 | 975 |
966 /** | 976 /** |
967 * This method returns all stored StateData in this artifact as a Collection | 977 * Returns all stored StateData in this artifact as a Collection |
968 * @return a Collection of all StateData objects in this artifact | 978 * @return a Collection of all StateData objects in this artifact |
969 */ | 979 */ |
970 public Collection<StateData> getAllData() { | 980 public Collection<StateData> getAllData() { |
971 return data.values(); | 981 return data.values(); |
972 } | 982 } |
1101 * otherwise false. | 1111 * otherwise false. |
1102 */ | 1112 */ |
1103 protected boolean isStateReachable(String stateId, Object context) { | 1113 protected boolean isStateReachable(String stateId, Object context) { |
1104 | 1114 |
1105 if (log.isDebugEnabled()) { | 1115 if (log.isDebugEnabled()) { |
1106 log.debug("Determine if the state '" + stateId + "' is reachable."); | 1116 log.debug("Determine if the state '" |
1117 + stateId + "' is reachable."); | |
1107 } | 1118 } |
1108 | 1119 |
1109 RiverContext flysContext = RiverUtils.getFlysContext(context); | 1120 RiverContext flysContext = RiverUtils.getFlysContext(context); |
1110 | 1121 |
1111 State currentState = getCurrentState(context); | 1122 State currentState = getCurrentState(context); |
1188 } | 1199 } |
1189 | 1200 |
1190 List<Facet> fFacets = filterFacets.get(outName); | 1201 List<Facet> fFacets = filterFacets.get(outName); |
1191 if (fFacets != null) { | 1202 if (fFacets != null) { |
1192 if (debug) { | 1203 if (debug) { |
1193 log.debug("" + fFacets.size() + " filters for: " + outName); | 1204 log.debug("" + fFacets.size() |
1205 + " filters for: " + outName); | |
1194 for (Facet tmp: fFacets) { | 1206 for (Facet tmp: fFacets) { |
1195 log.debug(" filter = '" + tmp.getName() + "'"); | 1207 log.debug(" filter = '" + tmp.getName() + "'"); |
1196 } | 1208 } |
1197 } | 1209 } |
1198 | 1210 |
1428 return generated; | 1440 return generated; |
1429 } | 1441 } |
1430 | 1442 |
1431 | 1443 |
1432 /** | 1444 /** |
1433 * Dispatches the computation request to compute(CallContext context, String | 1445 * Dispatches the computation request to |
1434 * hash) with the current hash value of the artifact which is provided by | 1446 * compute(CallContext context, String hash) |
1447 * with the current hash value of the artifact which is provided by | |
1435 * hash(). | 1448 * hash(). |
1436 * | 1449 * |
1437 * @param context The CallContext. | 1450 * @param context The CallContext. |
1438 */ | 1451 */ |
1439 public Object compute( | 1452 public Object compute( |
1515 Object old = null; | 1528 Object old = null; |
1516 | 1529 |
1517 if (cache != null) { | 1530 if (cache != null) { |
1518 net.sf.ehcache.Element element = cache.get(key); | 1531 net.sf.ehcache.Element element = cache.get(key); |
1519 if (element != null) { | 1532 if (element != null) { |
1520 log.debug("Got computation result from cache for key: " + key); | 1533 log.debug( |
1534 "Got computation result from cache for key: " + key); | |
1521 old = element.getValue(); | 1535 old = element.getValue(); |
1522 } | 1536 } |
1523 } | 1537 } |
1524 else { | 1538 else { |
1525 log.debug("cache not configured."); | 1539 log.debug("cache not configured."); |
1532 break; | 1546 break; |
1533 case ADVANCE: | 1547 case ADVANCE: |
1534 res = state.computeAdvance(this, key, context, fs, old); | 1548 res = state.computeAdvance(this, key, context, fs, old); |
1535 break; | 1549 break; |
1536 case INIT: | 1550 case INIT: |
1537 res = state.computeInit(this, key, context, context.getMeta(), fs); | 1551 res = state.computeInit( |
1552 this, key, context, context.getMeta(), fs); | |
1538 default: | 1553 default: |
1539 res = null; | 1554 res = null; |
1540 } | 1555 } |
1541 | 1556 |
1542 if (cache != null && old != res && res != null) { | 1557 if (cache != null && old != res && res != null) { |
1677 public void endOfLife(Object context) { | 1692 public void endOfLife(Object context) { |
1678 if (log.isDebugEnabled()) { | 1693 if (log.isDebugEnabled()) { |
1679 log.debug("D4EArtifact.endOfLife: " + identifier()); | 1694 log.debug("D4EArtifact.endOfLife: " + identifier()); |
1680 } | 1695 } |
1681 | 1696 |
1682 ArrayList<String> ids = (ArrayList<String>) getPreviousStateIds(); | 1697 ArrayList<String> ids = (ArrayList<String>) getPreviousStateIds(); |
1683 ArrayList<String> toDestroy = (ArrayList<String>) ids.clone(); | 1698 ArrayList<String> toDestroy = (ArrayList<String>) ids.clone(); |
1684 | 1699 |
1685 toDestroy.add(getCurrentStateId()); | 1700 toDestroy.add(getCurrentStateId()); |
1686 | 1701 |
1687 destroyStates(toDestroy, context); | 1702 destroyStates(toDestroy, context); |