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@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.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.artifacts.common.utils.XMLUtils; 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: 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@1729: int col = Integer.valueOf(parts[2]); felix@1729: int wst = Integer.valueOf(parts[3]); felix@1729: felix@1725: addStringData("col_pos", parts[2]); felix@1725: addStringData("wst_id", parts[3]); felix@1729: felix@1729: String wkmsName = WKmsFactory.getWKmsName(col, wst); felix@1729: felix@1729: Facet facet = new WKmsFacet( felix@1729: Resources.getMsg( felix@1729: callMeta, felix@1729: wkmsName, felix@1729: wkmsName)); felix@1729: felix@1765: facets.add(facet); felix@1725: } felix@1725: catch (Exception e) {} felix@1725: } felix@1723: } 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@1765: DefaultOutput output1 = new DefaultOutput( felix@1723: "w_differences", felix@1723: "w_differences.longitudinal_section", "image/png", felix@1765: facets, felix@1723: "chart"); felix@1765: DefaultOutput output2 = new DefaultOutput( felix@1765: "longitudinal_section", felix@1765: "longitudinal_section.longitudinal_section", "image/png", felix@1765: facets, felix@1765: "chart"); felix@1723: felix@1765: state.getOutputs().add(output1); felix@1765: state.getOutputs().add(output2); 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@1729: felix@1729: felix@1729: /** felix@1729: * Determines Facets initial disposition regarding activity (think of felix@1729: * selection in Client ThemeList GUI). This will be checked one time felix@1729: * when the facet enters a collections describe document. felix@1729: * felix@1729: * @param facetName name of the facet. felix@1729: * @param index index of the facet. felix@1729: * felix@1729: * @return Always 0. Static Data will enter plots inactive. felix@1729: */ felix@1729: public int getInitialFacetActivity(String facetName, int index) { felix@1729: return 0; felix@1729: } felix@1729: felix@1723: } felix@1723: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :