Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 689:f8ac04b2dbd0 facets-slt
Added two more compute() methods to ComputeCallback to distinguish between different phases of the artifact.
flys-artifacts/branches/facets-slt@2129 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 16 Jun 2011 08:43:58 +0000 |
parents | 06689035024c |
children | 3481cd37e609 |
comparison
equal
deleted
inserted
replaced
688:dc3613c4daf6 | 689:f8ac04b2dbd0 |
---|---|
49 import de.intevation.flys.artifacts.model.DischargeTables; | 49 import de.intevation.flys.artifacts.model.DischargeTables; |
50 import de.intevation.flys.artifacts.model.RiverFactory; | 50 import de.intevation.flys.artifacts.model.RiverFactory; |
51 import de.intevation.flys.artifacts.model.Segment; | 51 import de.intevation.flys.artifacts.model.Segment; |
52 | 52 |
53 import de.intevation.flys.artifacts.states.DefaultState; | 53 import de.intevation.flys.artifacts.states.DefaultState; |
54 import de.intevation.flys.artifacts.states.CalculationSelect; | |
54 import de.intevation.flys.artifacts.states.LocationDistanceSelect; | 55 import de.intevation.flys.artifacts.states.LocationDistanceSelect; |
55 | 56 |
56 | 57 |
57 /** | 58 /** |
58 * The defaul FLYS artifact. | 59 * The defaul FLYS artifact. |
192 Element result = creator.create("result"); | 193 Element result = creator.create("result"); |
193 doc.appendChild(result); | 194 doc.appendChild(result); |
194 | 195 |
195 try { | 196 try { |
196 saveData(target, XPATH_FEED_INPUT, context); | 197 saveData(target, XPATH_FEED_INPUT, context); |
198 | |
199 compute(context); | |
200 | |
197 return describe(target, context); | 201 return describe(target, context); |
198 } | 202 } |
199 catch (IllegalArgumentException iae) { | 203 catch (IllegalArgumentException iae) { |
200 // do not store state if validation fails. | 204 // do not store state if validation fails. |
201 context.afterCall(CallContext.NOTHING); | 205 context.afterCall(CallContext.NOTHING); |
254 logger.debug("Remove state id '" + prev + "'"); | 258 logger.debug("Remove state id '" + prev + "'"); |
255 prevs.remove(prev); | 259 prevs.remove(prev); |
256 } | 260 } |
257 | 261 |
258 setCurrentStateId(targetState); | 262 setCurrentStateId(targetState); |
263 | |
264 compute(context); | |
259 | 265 |
260 return describe(target, context); | 266 return describe(target, context); |
261 } | 267 } |
262 | 268 |
263 logger.warn("Advance: Cannot advance to '" + targetState + "'"); | 269 logger.warn("Advance: Cannot advance to '" + targetState + "'"); |
1036 | 1042 |
1037 return getCurrentStateId() + hash; | 1043 return getCurrentStateId() + hash; |
1038 } | 1044 } |
1039 | 1045 |
1040 | 1046 |
1047 /** | |
1048 * Dispatches the computation request to compute(CallContext context, String | |
1049 * hash) with the current hash value of the artifact which is provided by | |
1050 * hash(). | |
1051 * | |
1052 * @param context The CallContext. | |
1053 */ | |
1054 public Object compute(CallContext context) { | |
1055 return compute(context, hash()); | |
1056 } | |
1057 | |
1058 | |
1059 /** | |
1060 * Dispatches computation requests to the current state which needs to | |
1061 * implement a createComputeCallback(String hash, FLYSArtifact artifact) | |
1062 * method. | |
1063 * | |
1064 * @param context The CallContext. | |
1065 * @param hash The hash value which is used to fetch computed data from | |
1066 * cache. | |
1067 * | |
1068 * @return the computed data. | |
1069 */ | |
1070 public Object compute(CallContext context, String hash) { | |
1071 String calc = (String) getData(CalculationSelect.FIELD_MODE).getValue(); | |
1072 | |
1073 DefaultState current = (DefaultState) getCurrentState(context); | |
1074 | |
1075 ComputeCallback callback = current.createComputeCallback(hash(), this); | |
1076 | |
1077 if (callback == null) { | |
1078 logger.info("There is no data which needs to be computed."); | |
1079 return null; | |
1080 } | |
1081 | |
1082 return compute(hash, callback); | |
1083 } | |
1084 | |
1085 | |
1041 public Object compute(String key, ComputeCallback callback) { | 1086 public Object compute(String key, ComputeCallback callback) { |
1042 Cache cache = CacheFactory.getCache(COMPUTING_CACHE); | 1087 Cache cache = CacheFactory.getCache(COMPUTING_CACHE); |
1043 | 1088 |
1044 if (cache == null) { | 1089 if (cache == null) { |
1045 return callback.compute(facets); | 1090 return callback.compute(facets); |