view gnv-artifacts/src/main/java/de/intevation/gnv/state/PreSettingsTransferState.java @ 1060:cc4ec127d666

Remove the elements of an outdated state from cache if its endOfLife method is called. gnv-artifacts/trunk@1143 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 01 Jun 2010 16:54:21 +0000
parents 05bf8534a35a
children f953c9a559d8
line wrap: on
line source
package de.intevation.gnv.state;

import de.intevation.artifactdatabase.Config;

import de.intevation.artifacts.CallContext;

import de.intevation.gnv.state.exception.StateException;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * This special state does a lookup for already inserted data while
 * initializing. If there are some data for this state, take them for further
 * work.
 *
 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
 */
public class PreSettingsTransferState extends DefaultState {

    /**
     * The UID of this Class
     */
    private static final long serialVersionUID = 573381812690806922L;

    private String transferPreSettingsName = null;

    private String transferInputDataname = null;
    /**
     * Constructor
     */
    public PreSettingsTransferState() {
        super();
    }


    /**
     * This method does a lookup for already inserted data before initializing
     * it.
     *
     * @param uuid
     * @param context
     * @throws StateException
     */
    @Override
    public void initialize(String uuid, CallContext context)
                                                            throws StateException {
        Map<String, InputData> preSettings = this.getPreSettings();
        if (preSettings != null){
            InputData ip = preSettings.get(transferPreSettingsName);
            if (ip != null){
                Collection<InputData> localInputdata = new ArrayList<InputData>(1);
                localInputdata.add(new DefaultInputData(transferInputDataname,
                                                        ip.getValue()));
                this.putInputData(localInputdata, uuid);
            }
        }

        super.initialize(uuid, context);
    }


    /**
     *
     * @param configuration
     */
    @Override
    public void setup(Node configuration) {

        Element preSettingsNode = (Element)Config.getNodeXPath(configuration,
                                                         "presettings-transfer");
        if (preSettingsNode != null){
            this.transferPreSettingsName = preSettingsNode.getAttribute("presetting");
            this.transferInputDataname   = preSettingsNode.getAttribute("inputvalue");
        }
        super.setup(configuration);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org