comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 1067:f364410c7bc9

Refactored (state access) to ease future development of more trivial artifacts. flys-artifacts/trunk@2549 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 24 Aug 2011 09:44:31 +0000
parents fdb0f4ef96f0
children 583314dafdb6
comparison
equal deleted inserted replaced
1066:7f5426c69ee0 1067:f364410c7bc9
158 { 158 {
159 logger.debug("Setup this artifact with the uuid: " + identifier); 159 logger.debug("Setup this artifact with the uuid: " + identifier);
160 160
161 super.setup(identifier, factory, context, callMeta, data); 161 super.setup(identifier, factory, context, callMeta, data);
162 162
163 FLYSContext flysContext = (FLYSContext) context; 163 FLYSContext flysContext = getFlysContext(context);
164 StateEngine engine = (StateEngine) flysContext.get( 164
165 FLYSContext.STATE_ENGINE_KEY); 165 List<State> states = getStates(context);
166 166
167 String name = getName(); 167 String name = getName();
168
169 logger.debug("Set initial state for artifact '" + name + "'"); 168 logger.debug("Set initial state for artifact '" + name + "'");
170 List<State> states = engine.getStates(name);
171 169
172 setCurrentState(states.get(0)); 170 setCurrentState(states.get(0));
173 171
174 String model = XMLUtils.xpathString( 172 String model = XMLUtils.xpathString(
175 data, 173 data,
434 * Returns the current state of the artifact. 432 * Returns the current state of the artifact.
435 * 433 *
436 * @return the current State of the artifact. 434 * @return the current State of the artifact.
437 */ 435 */
438 protected State getCurrentState(Object context) { 436 protected State getCurrentState(Object context) {
437 return getState(context, getCurrentStateId());
438 }
439
440
441 /**
442 * Get list of existant states for this Artifact.
443 * @param context Contex to get StateEngine from.
444 * @return list of states.
445 */
446 protected List<State> getStates(Object context) {
439 FLYSContext flysContext = getFlysContext(context); 447 FLYSContext flysContext = getFlysContext(context);
440 StateEngine engine = (StateEngine) flysContext.get( 448 StateEngine engine = (StateEngine) flysContext.get(
441 FLYSContext.STATE_ENGINE_KEY); 449 FLYSContext.STATE_ENGINE_KEY);
442 450 return engine.getStates(getName());
443 return engine.getState(getCurrentStateId()); 451 }
444 } 452
445 453
454 /**
455 * Get state with given ID.
456 * @param context Context to get StateEngine from.
457 * @param stateID ID of state to get.
458 * @return state with given ID.
459 */
446 protected State getState(Object context, String stateID) { 460 protected State getState(Object context, String stateID) {
447 FLYSContext flysContext = getFlysContext(context); 461 FLYSContext flysContext = getFlysContext(context);
448 StateEngine engine = (StateEngine) flysContext.get( 462 StateEngine engine = (StateEngine) flysContext.get(
449 FLYSContext.STATE_ENGINE_KEY); 463 FLYSContext.STATE_ENGINE_KEY);
450 return engine.getState(stateID); 464 return engine.getState(stateID);
670 684
671 public List<Output> getOutputs(Object context) { 685 public List<Output> getOutputs(Object context) {
672 List<String> stateIds = getPreviousStateIds(); 686 List<String> stateIds = getPreviousStateIds();
673 List<Output> generated = new ArrayList<Output>(); 687 List<Output> generated = new ArrayList<Output>();
674 688
675 FLYSContext flysContext = getFlysContext(context);
676 StateEngine engine = (StateEngine) flysContext.get(
677 FLYSContext.STATE_ENGINE_KEY);
678
679 for (String stateId: stateIds) { 689 for (String stateId: stateIds) {
680 DefaultState state = (DefaultState) engine.getState(stateId); 690 DefaultState state = (DefaultState) getState(context, stateId);
681 generated.addAll(getOutputForState(state)); 691 generated.addAll(getOutputForState(state));
682 } 692 }
683 693
684 generated.addAll(getCurrentOutputs(context)); 694 generated.addAll(getCurrentOutputs(context));
685 695

http://dive4elements.wald.intevation.org