ingo@942: package de.intevation.flys.artifacts; ingo@942: ingo@942: import java.util.ArrayList; ingo@942: import java.util.List; ingo@942: ingo@1075: import org.w3c.dom.Document; ingo@1075: ingo@942: import org.apache.log4j.Logger; ingo@942: ingo@942: import de.intevation.artifacts.Artifact; ingo@1075: import de.intevation.artifacts.ArtifactFactory; ingo@952: import de.intevation.artifacts.CallMeta; ingo@942: ingo@1075: import de.intevation.artifacts.common.ArtifactNamespaceContext; ingo@1075: import de.intevation.artifacts.common.utils.XMLUtils; ingo@1075: ingo@1075: import de.intevation.artifactdatabase.data.DefaultStateData; ingo@942: import de.intevation.artifactdatabase.state.Facet; ingo@942: ingo@1075: import de.intevation.flys.model.River; ingo@1075: ingo@1075: import de.intevation.flys.artifacts.model.RiverFactory; ingo@942: import de.intevation.flys.artifacts.states.DefaultState; ingo@942: ingo@942: ingo@942: public class RiverAxisArtifact extends StaticFLYSArtifact { ingo@942: ingo@942: public static final String NAME = "riveraxis"; ingo@942: ingo@1075: public static final String XPATH_IDS = "/art:action/art:ids/@value"; ingo@1075: ingo@942: ingo@942: private static final Logger logger = ingo@942: Logger.getLogger(RiverAxisArtifact.class); ingo@942: ingo@942: ingo@942: @Override ingo@942: public String getName() { ingo@942: return NAME; ingo@942: } ingo@942: ingo@942: ingo@942: @Override ingo@1075: public void setup( ingo@1075: String identifier, ingo@1075: ArtifactFactory factory, ingo@1075: Object context, ingo@1075: CallMeta callMeta, ingo@1075: Document data) ingo@1075: { ingo@1075: logger.debug("RiverAxisArtifact.setup"); ingo@942: ingo@1075: super.setup(identifier, factory, context, callMeta, data); ingo@942: ingo@1075: String ids = XMLUtils.xpathString( ingo@1075: data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE); ingo@942: ingo@1075: String[] splitted = ids != null ? ids.split(" ") : null; ingo@1075: ingo@1075: if (splitted != null && splitted.length > 0) { ingo@1075: try { ingo@1075: int river_id = Integer.parseInt(splitted[0]); ingo@1075: River river = RiverFactory.getRiver(river_id); ingo@1075: ingo@1075: if (river == null) { ingo@1075: throw new IllegalArgumentException( ingo@1075: "No river found for id: " + river_id); ingo@1075: } ingo@1075: ingo@1075: String name = river.getName(); ingo@1075: ingo@1075: addData("river", new DefaultStateData("river",null,null,name)); ingo@1075: ingo@1075: List fs = new ArrayList(); ingo@1075: ingo@1075: DefaultState state = (DefaultState) getCurrentState(context); ingo@1075: state.computeInit(this, hash(), context, callMeta, fs); ingo@1075: ingo@1075: if (!fs.isEmpty()) { felix@1767: facets.addAll(fs); ingo@1075: } ingo@1075: } ingo@1075: catch (NumberFormatException nfe) { ingo@1075: logger.error("Could not create Artifact: " + nfe.getMessage()); ingo@1075: throw new IllegalArgumentException("No river id given."); ingo@1075: } ingo@942: } ingo@942: } ingo@1075: ingo@1075: ingo@1075: @Override ingo@1075: protected void initialize( ingo@1075: Artifact artifact, ingo@1075: Object context, ingo@1075: CallMeta callMeta) ingo@1075: { ingo@1075: // do nothing ingo@1075: } ingo@942: } ingo@942: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :