# HG changeset patch # User Felix Wolfsteller # Date 1314179071 0 # Node ID f364410c7bc9aa643ce7d5278845a797b59ee8b7 # Parent 7f5426c69ee0180fda91312dfe0b04cc1881dc42 Refactored (state access) to ease future development of more trivial artifacts. flys-artifacts/trunk@2549 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 7f5426c69ee0 -r f364410c7bc9 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Aug 24 08:53:11 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Aug 24 09:44:31 2011 +0000 @@ -1,3 +1,9 @@ +2011-08-24 Felix Wolfsteller + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: + Extracted access to state and states in order to have fewer places to + modify when going for single/trivial state- artifacts. + 2011-08-24 Ingo Weinzierl * src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java: diff -r 7f5426c69ee0 -r f364410c7bc9 flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Wed Aug 24 08:53:11 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Wed Aug 24 09:44:31 2011 +0000 @@ -160,14 +160,12 @@ super.setup(identifier, factory, context, callMeta, data); - FLYSContext flysContext = (FLYSContext) context; - StateEngine engine = (StateEngine) flysContext.get( - FLYSContext.STATE_ENGINE_KEY); + FLYSContext flysContext = getFlysContext(context); + + List states = getStates(context); String name = getName(); - logger.debug("Set initial state for artifact '" + name + "'"); - List states = engine.getStates(name); setCurrentState(states.get(0)); @@ -436,13 +434,29 @@ * @return the current State of the artifact. */ protected State getCurrentState(Object context) { + return getState(context, getCurrentStateId()); + } + + + /** + * Get list of existant states for this Artifact. + * @param context Contex to get StateEngine from. + * @return list of states. + */ + protected List getStates(Object context) { FLYSContext flysContext = getFlysContext(context); StateEngine engine = (StateEngine) flysContext.get( FLYSContext.STATE_ENGINE_KEY); - - return engine.getState(getCurrentStateId()); + return engine.getStates(getName()); } + + /** + * Get state with given ID. + * @param context Context to get StateEngine from. + * @param stateID ID of state to get. + * @return state with given ID. + */ protected State getState(Object context, String stateID) { FLYSContext flysContext = getFlysContext(context); StateEngine engine = (StateEngine) flysContext.get( @@ -672,12 +686,8 @@ List stateIds = getPreviousStateIds(); List generated = new ArrayList(); - FLYSContext flysContext = getFlysContext(context); - StateEngine engine = (StateEngine) flysContext.get( - FLYSContext.STATE_ENGINE_KEY); - for (String stateId: stateIds) { - DefaultState state = (DefaultState) engine.getState(stateId); + DefaultState state = (DefaultState) getState(context, stateId); generated.addAll(getOutputForState(state)); }