comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 1777:a8aa343799a2

Extracet getFlysContext from FLYSArtifact to FLYSUtils. flys-artifacts/trunk@3099 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 28 Oct 2011 09:00:51 +0000
parents c62ff9e72cea
children 376c81aa7d55
comparison
equal deleted inserted replaced
1776:7d1bd710a4b3 1777:a8aa343799a2
28 28
29 import de.intevation.flys.artifacts.cache.CacheFactory; 29 import de.intevation.flys.artifacts.cache.CacheFactory;
30 30
31 import de.intevation.flys.artifacts.context.FLYSContext; 31 import de.intevation.flys.artifacts.context.FLYSContext;
32 32
33 import de.intevation.flys.artifacts.states.DefaultState;
33 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; 34 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
34 35
35 import de.intevation.flys.artifacts.states.DefaultState; 36 import de.intevation.flys.utils.FLYSUtils;
36 37
37 import java.util.ArrayList; 38 import java.util.ArrayList;
38 import java.util.Collection; 39 import java.util.Collection;
39 import java.util.HashMap; 40 import java.util.HashMap;
40 import java.util.HashSet; 41 import java.util.HashSet;
122 * 123 *
123 * @return the name of the concrete artifact. 124 * @return the name of the concrete artifact.
124 */ 125 */
125 public String getName() { 126 public String getName() {
126 return name; 127 return name;
127 }
128
129 /**
130 * Returns the FLYSContext from context object.
131 *
132 * @param context The CallContext or the FLYSContext.
133 *
134 * @return the FLYSContext.
135 */
136 protected static FLYSContext getFlysContext(Object context) {
137 return context instanceof FLYSContext
138 ? (FLYSContext) context
139 : (FLYSContext) ((CallContext) context).globalContext();
140 } 128 }
141 129
142 130
143 /** 131 /**
144 * Initialize the artifact and insert new data if <code>data</code> contains 132 * Initialize the artifact and insert new data if <code>data</code> contains
159 { 147 {
160 logger.debug("Setup this artifact with the uuid: " + identifier); 148 logger.debug("Setup this artifact with the uuid: " + identifier);
161 149
162 super.setup(identifier, factory, context, callMeta, data); 150 super.setup(identifier, factory, context, callMeta, data);
163 151
164 FLYSContext flysContext = getFlysContext(context); 152 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
165 153
166 List<State> states = getStates(context); 154 List<State> states = getStates(context);
167 155
168 String name = getName(); 156 String name = getName();
169 logger.debug("Set initial state for artifact '" + name + "'"); 157 logger.debug("Set initial state for artifact '" + name + "'");
463 * Get list of existant states for this Artifact. 451 * Get list of existant states for this Artifact.
464 * @param context Contex to get StateEngine from. 452 * @param context Contex to get StateEngine from.
465 * @return list of states. 453 * @return list of states.
466 */ 454 */
467 protected List<State> getStates(Object context) { 455 protected List<State> getStates(Object context) {
468 FLYSContext flysContext = getFlysContext(context); 456 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
469 StateEngine engine = (StateEngine) flysContext.get( 457 StateEngine engine = (StateEngine) flysContext.get(
470 FLYSContext.STATE_ENGINE_KEY); 458 FLYSContext.STATE_ENGINE_KEY);
471 return engine.getStates(getName()); 459 return engine.getStates(getName());
472 } 460 }
473 461
477 * @param context Context to get StateEngine from. 465 * @param context Context to get StateEngine from.
478 * @param stateID ID of state to get. 466 * @param stateID ID of state to get.
479 * @return state with given ID. 467 * @return state with given ID.
480 */ 468 */
481 protected State getState(Object context, String stateID) { 469 protected State getState(Object context, String stateID) {
482 FLYSContext flysContext = getFlysContext(context); 470 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
483 StateEngine engine = (StateEngine) flysContext.get( 471 StateEngine engine = (StateEngine) flysContext.get(
484 FLYSContext.STATE_ENGINE_KEY); 472 FLYSContext.STATE_ENGINE_KEY);
485 return engine.getState(stateID); 473 return engine.getState(stateID);
486 } 474 }
487 475
633 * otherwise false. 621 * otherwise false.
634 */ 622 */
635 protected boolean isStateReachable(String stateId, Object context) { 623 protected boolean isStateReachable(String stateId, Object context) {
636 logger.debug("Determine if the state '" + stateId + "' is reachable."); 624 logger.debug("Determine if the state '" + stateId + "' is reachable.");
637 625
638 FLYSContext flysContext = getFlysContext(context); 626 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
639 627
640 State currentState = getCurrentState(context); 628 State currentState = getCurrentState(context);
641 StateEngine sEngine = (StateEngine) flysContext.get( 629 StateEngine sEngine = (StateEngine) flysContext.get(
642 FLYSContext.STATE_ENGINE_KEY); 630 FLYSContext.STATE_ENGINE_KEY);
643 631

http://dive4elements.wald.intevation.org