ingo@1805: package de.intevation.flys.artifacts; ingo@1805: ingo@1805: import java.util.ArrayList; ingo@1805: import java.util.List; ingo@1805: ingo@1805: import org.w3c.dom.Document; ingo@1805: ingo@1805: import org.apache.log4j.Logger; ingo@1805: ingo@1805: import com.vividsolutions.jts.geom.Envelope; ingo@1805: ingo@1805: import de.intevation.artifacts.Artifact; ingo@1805: import de.intevation.artifacts.ArtifactFactory; ingo@1805: import de.intevation.artifacts.CallMeta; ingo@1805: ingo@1805: import de.intevation.artifactdatabase.data.DefaultStateData; ingo@1805: import de.intevation.artifactdatabase.state.Facet; ingo@1805: import de.intevation.artifactdatabase.state.State; ingo@1805: ingo@1805: import de.intevation.artifacts.common.ArtifactNamespaceContext; ingo@1805: import de.intevation.artifacts.common.utils.XMLUtils; ingo@1805: ingo@1805: import de.intevation.flys.artifacts.states.DefaultState; ingo@1805: import de.intevation.flys.artifacts.model.WMSDBLayerFacet; ingo@1805: ingo@1805: ingo@1805: public abstract class WMSDBArtifact extends StaticFLYSArtifact { ingo@1805: ingo@1805: private static final Logger logger = Logger.getLogger(WMSDBArtifact.class); ingo@1805: ingo@1805: public static final String XPATH_IDS = "/art:action/art:ids/@value"; ingo@1805: ingo@1805: ingo@1805: @Override ingo@1805: public void setup( ingo@1805: String identifier, ingo@1805: ArtifactFactory factory, ingo@1805: Object context, ingo@1805: CallMeta callMeta, ingo@1805: Document data) ingo@1805: { ingo@1805: logger.debug("WMSDBArtifact.setup"); ingo@1805: ingo@1805: super.setup(identifier, factory, context, callMeta, data); ingo@1805: ingo@1805: String ids = XMLUtils.xpathString( ingo@1805: data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE); ingo@1805: ingo@1805: if (ids != null && ids.length() > 0) { ingo@1805: addData("ids", new DefaultStateData("ids", null, null, ids)); ingo@1805: } ingo@1805: else { ingo@1805: throw new IllegalArgumentException("No attribute 'ids' found!"); ingo@1805: } ingo@1805: ingo@1805: List fs = new ArrayList(); ingo@1805: ingo@1805: WMSDBState state = (WMSDBState) getCurrentState(context); ingo@1805: state.computeInit(this, hash(), context, callMeta, fs); ingo@1805: ingo@1805: if (!fs.isEmpty()) { ingo@1805: facets.put(getCurrentStateId(), fs); ingo@1805: } ingo@1805: } ingo@1805: ingo@1805: ingo@1805: @Override ingo@1805: protected void initialize( ingo@1805: Artifact artifact, ingo@1805: Object context, ingo@1805: CallMeta callMeta) ingo@1805: { ingo@1805: // do nothing ingo@1805: } ingo@1805: ingo@1805: ingo@1805: /** ingo@1805: * Get a list containing the one and only State. ingo@1805: * @param context ignored. ingo@1805: * @return list with one and only state. ingo@1805: */ ingo@1805: @Override ingo@1805: protected List getStates(Object context) { ingo@1805: ArrayList states = new ArrayList(); ingo@1805: states.add(getCurrentState(context)); ingo@1805: ingo@1805: return states; ingo@1805: } ingo@1805: ingo@1805: ingo@1805: ingo@1805: public static abstract class WMSDBState extends DefaultState { ingo@1805: private static final Logger logger = Logger.getLogger(WMSDBState.class); ingo@1805: ingo@1805: protected WMSDBArtifact artifact; ingo@1805: ingo@1805: public WMSDBState(WMSDBArtifact artifact) { ingo@1805: this.artifact = artifact; ingo@1805: } ingo@1805: ingo@1805: @Override ingo@1805: public Object computeInit( ingo@1805: FLYSArtifact artifact, ingo@1805: String hash, ingo@1805: Object context, ingo@1805: CallMeta meta, ingo@1805: List facets ingo@1805: ) { ingo@1805: logger.debug("WMSDBState.computeInit"); ingo@1805: ingo@1805: String type = getFacetType(); ingo@1805: ingo@1805: WMSDBLayerFacet facet = new WMSDBLayerFacet( ingo@1805: 0, ingo@1805: type, ingo@1805: getTitle(meta), ingo@1805: ComputeType.INIT, ingo@1805: getID(), hash, ingo@1805: getUrl()); ingo@1805: ingo@1805: String name = artifact.identifier() + "-" + type; ingo@1805: ingo@1805: facet.addLayer(name); ingo@1805: facet.setExtent(getExtent()); ingo@1805: facet.setSrid(getSrid()); ingo@1805: facet.setData(getDataString()); ingo@1805: facet.setFilter(getFilter()); ingo@1816: facet.setGeometryType(getGeometryType()); ingo@1805: ingo@1805: facets.add(facet); ingo@1805: ingo@1805: return null; ingo@1805: } ingo@1805: ingo@1805: protected abstract String getFacetType(); ingo@1805: ingo@1805: protected abstract String getTitle(CallMeta meta); ingo@1805: ingo@1805: protected abstract String getUrl(); ingo@1805: ingo@1805: protected abstract String getSrid(); ingo@1805: ingo@1805: protected abstract Envelope getExtent(); ingo@1805: ingo@1805: protected abstract String getFilter(); ingo@1805: ingo@1805: protected abstract String getDataString(); ingo@1816: ingo@1816: protected abstract String getGeometryType(); ingo@1805: } // end of WMSDBState ingo@1805: } ingo@1805: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :