view flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java @ 1079:ef756e166154

Improved implementation of MainValueArtifact#MainValueFacet . flys-artifacts/trunk@2576 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 25 Aug 2011 10:42:23 +0000
parents feaf778d510e
children b2730e31ff5b
line wrap: on
line source
package de.intevation.flys.artifacts;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Document;

import org.apache.log4j.Logger;

import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.ArtifactFactory;
import de.intevation.artifacts.CallMeta;

import de.intevation.artifacts.common.ArtifactNamespaceContext;
import de.intevation.artifacts.common.utils.XMLUtils;

import de.intevation.artifactdatabase.data.DefaultStateData;
import de.intevation.artifactdatabase.state.Facet;

import de.intevation.flys.model.River;

import de.intevation.flys.artifacts.model.RiverFactory;
import de.intevation.flys.artifacts.states.DefaultState;


public class RiverAxisArtifact extends StaticFLYSArtifact {

    public static final String NAME = "riveraxis";

    public static final String XPATH_IDS = "/art:action/art:ids/@value";


    private static final Logger logger =
        Logger.getLogger(RiverAxisArtifact.class);


    @Override
    public String getName() {
        return NAME;
    }


    @Override
    public void setup(
        String          identifier,
        ArtifactFactory factory,
        Object          context,
        CallMeta        callMeta,
        Document        data)
    {
        logger.debug("RiverAxisArtifact.setup");

        super.setup(identifier, factory, context, callMeta, data);

        String ids = XMLUtils.xpathString(
            data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE);

        String[] splitted = ids != null ? ids.split(" ") : null;

        if (splitted != null && splitted.length > 0) {
            try {
                int   river_id = Integer.parseInt(splitted[0]);
                River river    = RiverFactory.getRiver(river_id);

                if (river == null) {
                    throw new IllegalArgumentException(
                        "No river found for id: " + river_id);
                }

                String name = river.getName();

                addData("river", new DefaultStateData("river",null,null,name));

                List<Facet> fs = new ArrayList<Facet>();

                DefaultState state = (DefaultState) getCurrentState(context);
                state.computeInit(this, hash(), context, callMeta, fs);

                if (!fs.isEmpty()) {
                    facets.put(getCurrentStateId(), fs);
                }
            }
            catch (NumberFormatException nfe) {
                logger.error("Could not create Artifact: " + nfe.getMessage());
                throw new IllegalArgumentException("No river id given.");
            }
        }
    }


    @Override
    protected void initialize(
        Artifact artifact,
        Object   context,
        CallMeta callMeta)
    {
        // do nothing
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org