view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DataFacet.java @ 1061:b1b0a0b61845

Made facets cloneable with the right type. flys-artifacts/trunk@2533 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 23 Aug 2011 13:17:21 +0000
parents 3fd891d5228d
children b1ed0ec0236f
line wrap: on
line source
package de.intevation.flys.artifacts.model;

import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.CallContext;

import de.intevation.artifactdatabase.state.DefaultFacet;
import de.intevation.artifactdatabase.state.Facet;

import de.intevation.flys.artifacts.FLYSArtifact;

import de.intevation.flys.artifacts.states.DefaultState.ComputeType;

public class DataFacet
extends      DefaultFacet
{
    protected ComputeType type;
    protected String      hash;
    protected String      stateId;

    public DataFacet() {
    }

    public DataFacet(String name, String description) {
        this(name, description, ComputeType.ADVANCE);
    }

    public DataFacet(String name, String description, ComputeType type) {
        this(name, description, type, null);
    }

    public DataFacet(
        String      name,
        String      description,
        ComputeType type,
        String      hash
    ) {
        super(name, description);
        this.type = type;
        this.hash = hash;
    }


    public DataFacet(
        String      name,
        String      description,
        ComputeType type,
        String      hash,
        String      stateId
    ) {
        super(name, description);
        this.type    = type;
        this.hash    = hash;
        this.stateId = stateId;
    }

    @Override
    public Object getData(Artifact artifact, CallContext context) {
        FLYSArtifact flys = (FLYSArtifact)artifact;
        String    theHash = hash != null ? hash : flys.hash();

        return stateId != null && stateId.length() > 0
            ? flys.compute(context, stateId, theHash, type, false)
            : flys.compute(context, theHash, type, false);
    }

    @Override
    public Facet deepCopy() {
        DataFacet copy = new DataFacet();
        copy.set(this);
        copy.type    = type;
        copy.hash    = hash;
        copy.stateId = stateId;
        return copy;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org