Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java @ 3807:d73c43798a99 pre2.6-2011-11-04
merged flys-backend/pre2.6-2011-11-04
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:51 +0200 |
parents | c62ff9e72cea |
children | a8910c1c82fb |
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 :