Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 690:3481cd37e609 facets-slt
Use enums to dispatch computeFeed() and computeAdvance().
flys-artifacts/branches/facets-slt@2130 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 16 Jun 2011 08:57:05 +0000 |
parents | f8ac04b2dbd0 |
children | 2600aa2c7319 |
comparison
equal
deleted
inserted
replaced
689:f8ac04b2dbd0 | 690:3481cd37e609 |
---|---|
44 import de.intevation.flys.artifacts.context.FLYSContext; | 44 import de.intevation.flys.artifacts.context.FLYSContext; |
45 | 45 |
46 import de.intevation.flys.artifacts.cache.CacheFactory; | 46 import de.intevation.flys.artifacts.cache.CacheFactory; |
47 | 47 |
48 import de.intevation.flys.artifacts.model.ComputeCallback; | 48 import de.intevation.flys.artifacts.model.ComputeCallback; |
49 import de.intevation.flys.artifacts.model.ComputeCallback.ComputeType; | |
49 import de.intevation.flys.artifacts.model.DischargeTables; | 50 import de.intevation.flys.artifacts.model.DischargeTables; |
50 import de.intevation.flys.artifacts.model.RiverFactory; | 51 import de.intevation.flys.artifacts.model.RiverFactory; |
51 import de.intevation.flys.artifacts.model.Segment; | 52 import de.intevation.flys.artifacts.model.Segment; |
52 | 53 |
53 import de.intevation.flys.artifacts.states.DefaultState; | 54 import de.intevation.flys.artifacts.states.DefaultState; |
194 doc.appendChild(result); | 195 doc.appendChild(result); |
195 | 196 |
196 try { | 197 try { |
197 saveData(target, XPATH_FEED_INPUT, context); | 198 saveData(target, XPATH_FEED_INPUT, context); |
198 | 199 |
199 compute(context); | 200 compute(context, ComputeType.FEED); |
200 | 201 |
201 return describe(target, context); | 202 return describe(target, context); |
202 } | 203 } |
203 catch (IllegalArgumentException iae) { | 204 catch (IllegalArgumentException iae) { |
204 // do not store state if validation fails. | 205 // do not store state if validation fails. |
259 prevs.remove(prev); | 260 prevs.remove(prev); |
260 } | 261 } |
261 | 262 |
262 setCurrentStateId(targetState); | 263 setCurrentStateId(targetState); |
263 | 264 |
264 compute(context); | 265 compute(context, ComputeType.ADVANCE); |
265 | 266 |
266 return describe(target, context); | 267 return describe(target, context); |
267 } | 268 } |
268 | 269 |
269 logger.warn("Advance: Cannot advance to '" + targetState + "'"); | 270 logger.warn("Advance: Cannot advance to '" + targetState + "'"); |
1049 * hash) with the current hash value of the artifact which is provided by | 1050 * hash) with the current hash value of the artifact which is provided by |
1050 * hash(). | 1051 * hash(). |
1051 * | 1052 * |
1052 * @param context The CallContext. | 1053 * @param context The CallContext. |
1053 */ | 1054 */ |
1054 public Object compute(CallContext context) { | 1055 public Object compute(CallContext context, ComputeType type) { |
1055 return compute(context, hash()); | 1056 return compute(context, hash(), type); |
1056 } | 1057 } |
1057 | 1058 |
1058 | 1059 |
1059 /** | 1060 /** |
1060 * Dispatches computation requests to the current state which needs to | 1061 * Dispatches computation requests to the current state which needs to |
1065 * @param hash The hash value which is used to fetch computed data from | 1066 * @param hash The hash value which is used to fetch computed data from |
1066 * cache. | 1067 * cache. |
1067 * | 1068 * |
1068 * @return the computed data. | 1069 * @return the computed data. |
1069 */ | 1070 */ |
1070 public Object compute(CallContext context, String hash) { | 1071 public Object compute(CallContext context, String hash, ComputeType type) { |
1071 String calc = (String) getData(CalculationSelect.FIELD_MODE).getValue(); | 1072 String calc = (String) getData(CalculationSelect.FIELD_MODE).getValue(); |
1072 | 1073 |
1073 DefaultState current = (DefaultState) getCurrentState(context); | 1074 DefaultState current = (DefaultState) getCurrentState(context); |
1074 | 1075 |
1075 ComputeCallback callback = current.createComputeCallback(hash(), this); | 1076 ComputeCallback callback = current.createComputeCallback(hash(), this); |
1077 if (callback == null) { | 1078 if (callback == null) { |
1078 logger.info("There is no data which needs to be computed."); | 1079 logger.info("There is no data which needs to be computed."); |
1079 return null; | 1080 return null; |
1080 } | 1081 } |
1081 | 1082 |
1082 return compute(hash, callback); | 1083 return compute(hash, callback, type); |
1083 } | 1084 } |
1084 | 1085 |
1085 | 1086 |
1086 public Object compute(String key, ComputeCallback callback) { | 1087 public Object compute( |
1088 String key, | |
1089 ComputeCallback callback, | |
1090 ComputeType type) | |
1091 { | |
1087 Cache cache = CacheFactory.getCache(COMPUTING_CACHE); | 1092 Cache cache = CacheFactory.getCache(COMPUTING_CACHE); |
1088 | 1093 |
1089 if (cache == null) { | 1094 if (cache == null) { |
1090 return callback.compute(facets); | 1095 switch (type) { |
1096 case FEED: | |
1097 return callback.computeFeed(facets); | |
1098 | |
1099 case ADVANCE: | |
1100 return callback.computeAdvance(facets); | |
1101 } | |
1091 } | 1102 } |
1092 | 1103 |
1093 net.sf.ehcache.Element element = cache.get(key); | 1104 net.sf.ehcache.Element element = cache.get(key); |
1094 if (element != null) { | 1105 if (element != null) { |
1095 logger.debug("Got computation values from cache."); | 1106 logger.debug("Got computation values from cache."); |
1096 return element.getValue(); | 1107 return element.getValue(); |
1097 } | 1108 } |
1098 | 1109 |
1099 Object result = callback.compute(facets); | 1110 Object result = null; |
1111 switch (type) { | |
1112 case FEED: | |
1113 result = callback.computeFeed(facets); | |
1114 break; | |
1115 | |
1116 case ADVANCE: | |
1117 result = callback.computeAdvance(facets); | |
1118 } | |
1100 | 1119 |
1101 if (result != null) { | 1120 if (result != null) { |
1102 cache.put(new net.sf.ehcache.Element(key, result)); | 1121 cache.put(new net.sf.ehcache.Element(key, result)); |
1103 } | 1122 } |
1104 | 1123 |