felix@1723: package de.intevation.flys.artifacts; felix@1723: felix@1723: import java.util.ArrayList; felix@1723: import java.util.List; felix@1723: felix@1723: import org.apache.log4j.Logger; felix@1723: felix@1723: import org.w3c.dom.Document; felix@1723: felix@1725: import de.intevation.artifactdatabase.data.DefaultStateData; felix@1725: felix@1723: import de.intevation.artifactdatabase.state.Facet; felix@1723: import de.intevation.artifactdatabase.state.DefaultOutput; felix@1723: import de.intevation.artifactdatabase.state.State; felix@1723: felix@1723: import de.intevation.artifacts.Artifact; felix@1723: import de.intevation.artifacts.ArtifactFactory; felix@1723: import de.intevation.artifacts.ArtifactNamespaceContext; felix@1723: import de.intevation.artifacts.CallMeta; felix@1723: felix@1723: import de.intevation.flys.artifacts.model.WKms; felix@1723: import de.intevation.flys.artifacts.model.WKmsFacet; felix@1723: import de.intevation.flys.artifacts.model.WstValueTable; felix@1723: import de.intevation.flys.artifacts.model.WstValueTableFactory; felix@1723: import de.intevation.flys.artifacts.model.WKmsFactory; felix@1723: felix@1723: import de.intevation.flys.artifacts.states.StaticState; felix@1723: import de.intevation.flys.artifacts.resources.Resources; felix@1723: felix@1723: import de.intevation.flys.utils.FLYSUtils; felix@1723: import de.intevation.artifacts.common.utils.XMLUtils; felix@1723: felix@1723: felix@1723: /** felix@1723: * Artifact to access additional "waterlevel"-type of data, like the height felix@1723: * of protective measures (dikes). felix@1723: * felix@1723: * This artifact neglects (Static)FLYSArtifacts capabilities of interaction felix@1723: * with the StateEngine by overriding the getState*-methods. felix@1723: */ felix@1723: public class StaticWKmsArtifact felix@1723: extends StaticFLYSArtifact felix@1723: { felix@1723: /** The logger for this class. */ felix@1723: private static Logger logger = felix@1723: Logger.getLogger(StaticWKmsArtifact.class); felix@1723: felix@1723: /** XPath to access initial parameter. */ felix@1723: public static final String XPATH_DATA = felix@1723: "/art:action/art:ids/@value"; felix@1723: felix@1723: /** One and only state to be in. */ felix@1723: protected transient State state = null; felix@1723: felix@1723: felix@1723: /** felix@1723: * Trivial Constructor. felix@1723: */ felix@1723: public StaticWKmsArtifact() { felix@1723: logger.debug("StaticWKmsArtifact.StaticWKmsArtifact"); felix@1723: } felix@1723: felix@1723: felix@1723: /** felix@1723: * Gets called from factory, to set things up. felix@1723: */ felix@1723: @Override felix@1723: public void setup( felix@1723: String identifier, felix@1723: ArtifactFactory factory, felix@1723: Object context, felix@1723: CallMeta callMeta, felix@1723: Document data) felix@1723: { felix@1723: logger.debug("StaticWKmsArtifact.setup"); felix@1723: felix@1723: state = new StaticState( felix@1723: "state.additional_wkms.static", felix@1723: "state.additional_wkms.static"); felix@1725: felix@1723: List fs = new ArrayList(); felix@1723: logger.debug(XMLUtils.toString(data)); felix@1723: String code = XMLUtils.xpathString( felix@1723: data, XPATH_DATA, ArtifactNamespaceContext.INSTANCE); felix@1723: felix@1723: logger.debug("makes: " + code); felix@1723: felix@1725: // TODO Go for JSON, one day. felix@1723: //ex.: flood_protection-wstv-114-12 felix@1723: if (code != null) { felix@1723: String [] parts = code.split("-"); felix@1725: felix@1725: if (parts.length >= 4) { felix@1725: try { felix@1725: Integer.valueOf(parts[2]); felix@1725: Integer.valueOf(parts[3]); felix@1725: addStringData("col_pos", parts[2]); felix@1725: addStringData("wst_id", parts[3]); felix@1725: } felix@1725: catch (Exception e) {} felix@1725: } felix@1723: } felix@1723: felix@1723: Facet facet = new WKmsFacet(Resources.getMsg(callMeta, felix@1723: "facet.discharge_curves.mainvalues.w", felix@1723: "facet.discharge_curves.mainvalues.w")); felix@1723: fs.add(facet); felix@1723: facets.put(state.getID(), fs); felix@1723: felix@1723: spawnState(); felix@1723: super.setup(identifier, factory, context, callMeta, data); felix@1723: } felix@1723: felix@1723: felix@1723: /** felix@1723: * Initialize the static state with output. felix@1725: * @return static state felix@1723: */ felix@1723: protected State spawnState() { felix@1723: state = new StaticState( felix@1723: "state.additional_wkms.static", felix@1723: "state.additional_wkms.static"); felix@1723: List fs = (List) facets.get("state.additional_wkms.static"); felix@1723: DefaultOutput output = new DefaultOutput( felix@1723: "w_differences", felix@1723: "w_differences.longitudinal_section", "image/png", felix@1723: fs, felix@1723: "chart"); felix@1723: // TODO: also add longitudinal_section output? felix@1723: felix@1723: state.getOutputs().add(output); felix@1723: return state; felix@1723: } felix@1723: felix@1723: felix@1723: /** felix@1723: * Called via setup. felix@1723: */ felix@1723: @Override felix@1723: protected void initialize(Artifact artifact, Object context, CallMeta meta) { felix@1723: logger.debug("StaticWKmsArtifact.initialize"); felix@1723: WINFOArtifact winfo = (WINFOArtifact) artifact; felix@1723: // TODO: The river is of no interest, so far. felix@1723: addData("river", winfo.getData("river")); felix@1723: } felix@1723: felix@1723: felix@1723: /** felix@1723: * Get a list containing the one and only State. felix@1723: * @param context ignored. felix@1723: * @return list with one and only state. felix@1723: */ felix@1723: @Override felix@1723: protected List getStates(Object context) { felix@1723: ArrayList states = new ArrayList(); felix@1723: states.add(getState()); felix@1723: return states; felix@1723: } felix@1723: felix@1723: felix@1723: /** felix@1723: * Get the "current" state (there is but one). felix@1723: * @param cc ignored. felix@1723: * @return the "current" (only possible) state. felix@1723: */ felix@1723: @Override felix@1723: public State getCurrentState(Object cc) { felix@1723: return getState(); felix@1723: } felix@1723: felix@1723: felix@1723: /** felix@1723: * Get the only possible state. felix@1723: * @return the state. felix@1723: */ felix@1723: protected State getState() { felix@1723: return getState(null, null); felix@1723: } felix@1723: felix@1723: felix@1723: /** felix@1723: * Get the state. felix@1723: * @param context ignored. felix@1723: * @param stateID ignored. felix@1723: * @return the state. felix@1723: */ felix@1723: @Override felix@1723: protected State getState(Object context, String stateID) { felix@1723: if (state != null) felix@1723: return state; felix@1723: else felix@1723: return spawnState(); felix@1723: } felix@1723: felix@1723: felix@1723: /** felix@1723: * Get WKms from factory. felix@1723: * @param TODO idx param is not needed felix@1723: * @return WKms according to parameterization (can be null); felix@1723: */ felix@1723: public WKms getWKms(int idx) { felix@1723: logger.debug("StaticWKmsArtifact.getWKms"); felix@1723: felix@1723: return WKmsFactory.getWKms( felix@1725: Integer.valueOf(getDataAsString("col_pos")), felix@1725: Integer.valueOf(getDataAsString("wst_id"))); felix@1723: } felix@1723: } felix@1723: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :