felix@1047: package de.intevation.flys.artifacts; felix@1047: felix@1047: import java.util.ArrayList; felix@1047: import java.util.List; felix@1047: felix@1047: import org.apache.log4j.Logger; felix@1047: felix@1047: import org.w3c.dom.Document; felix@1047: import org.w3c.dom.Element; felix@1047: import org.w3c.dom.Node; felix@1047: felix@1047: import de.intevation.artifacts.Artifact; felix@1047: import de.intevation.artifacts.ArtifactFactory; felix@1047: import de.intevation.artifacts.ArtifactNamespaceContext; felix@1047: import de.intevation.artifacts.CallContext; felix@1047: import de.intevation.artifacts.CallMeta; felix@1047: felix@1047: import de.intevation.flys.artifacts.context.FLYSContext; felix@1047: felix@1047: import de.intevation.flys.artifacts.states.DefaultState; felix@1047: import de.intevation.artifactdatabase.ProtocolUtils; felix@1047: import de.intevation.artifacts.Artifact; felix@1047: import de.intevation.artifactdatabase.state.Facet; felix@1047: import de.intevation.artifactdatabase.state.DefaultOutput; felix@1047: import de.intevation.artifactdatabase.state.Output; felix@1047: import de.intevation.artifactdatabase.state.DefaultFacet; felix@1047: import de.intevation.artifacts.common.utils.XMLUtils; felix@1047: felix@1047: /** felix@1047: * Artifact to access names of Points Of Interest along a segment of a river. felix@1047: */ felix@1047: public class MainValuesArtifact felix@1047: extends StaticFLYSArtifact felix@1047: implements Facet { felix@1047: felix@1047: /** The logger for this class. */ felix@1047: private static Logger logger = Logger.getLogger(WINFOArtifact.class); felix@1047: felix@1047: /** The name of the artifact. */ felix@1047: public static final String ARTIFACT_NAME = "annotation"; felix@1047: felix@1047: public MainValuesArtifact() { felix@1047: logger.warn("MainValuesArtifact.MainValuesartifact()"); felix@1047: } felix@1047: felix@1047: /** felix@1047: * Gets called from factory, to set things up. felix@1047: * Do nothing. felix@1047: */ felix@1047: @Override felix@1047: public void setup( felix@1047: String identifier, felix@1047: ArtifactFactory factory, felix@1047: Object context, felix@1047: CallMeta callMeta, felix@1047: Document data) felix@1047: { felix@1047: logger.warn("MainValuesArtifact.setup"); felix@1047: ; felix@1047: } felix@1047: felix@1047: /** felix@1047: * Create the description of this MainValuesArtiface-instance. felix@1047: * felix@1047: * @param data some data. felix@1047: * @param context the CallContext. felix@1047: * felix@1047: * @return the description of this artifact. felix@1047: */ felix@1047: @Override felix@1047: public Document describe(Document data, CallContext context) { felix@1047: logger.debug("MainValuesArtifact.describe"); felix@1047: felix@1047: if (logger.isDebugEnabled()) { felix@1047: dumpArtifact(); felix@1047: } felix@1047: felix@1047: FLYSContext flysContext = getFlysContext(context); felix@1047: felix@1047: Document description = XMLUtils.newDocument(); felix@1047: XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( felix@1047: description, felix@1047: ArtifactNamespaceContext.NAMESPACE_URI, felix@1047: ArtifactNamespaceContext.NAMESPACE_PREFIX); felix@1047: felix@1047: Element root = ProtocolUtils.createRootNode(creator); felix@1047: description.appendChild(root); felix@1047: felix@1047: ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); felix@1047: felix@1047: Element name = ProtocolUtils.createArtNode( felix@1047: creator, "name", felix@1047: new String[] { "value" }, felix@1047: new String[] { getName() }); felix@1047: felix@1047: Element outs = ProtocolUtils.createArtNode( felix@1047: creator, "outputmodes", null, null); felix@1047: appendOutputModes(description, outs, context); felix@1047: felix@1047: root.appendChild(name); felix@1047: root.appendChild(outs); felix@1047: felix@1047: return description; felix@1047: } felix@1047: felix@1047: felix@1047: /** felix@1047: * Append outputmode elements to given document. felix@1047: * felix@1047: * @param doc Document to add outputmodes to. felix@1047: * @param outs Element to add outputmode elements to. felix@1047: * @param context The given CallContext (mostly for internationalization). felix@1047: */ felix@1047: protected void appendOutputModes( felix@1047: Document doc, felix@1047: Element outs, felix@1047: CallContext context) felix@1047: { felix@1047: // TODO outputmodes felix@1047: XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( felix@1047: doc, felix@1047: ArtifactNamespaceContext.NAMESPACE_URI, felix@1047: ArtifactNamespaceContext.NAMESPACE_PREFIX); felix@1047: felix@1047: FLYSContext flysContext = getFlysContext(context); felix@1047: felix@1047: for (int i = 0; i < 1; i++) { felix@1047: logger.debug("Append output mode."); felix@1047: felix@1047: // TODO create outputs. felix@1047: /* felix@1047: List list = state.getOutputs(); felix@1047: if (list == null || list.size() == 0) { felix@1047: logger.debug("-> No output modes for this state."); felix@1047: continue; felix@1047: }*/ felix@1047: List fs = new ArrayList(); felix@1047: DefaultOutput mainValuesOutput = new DefaultOutput( felix@1047: "discharge_curve", "output.discharge_curve", "image/png", felix@1047: fs, felix@1047: "chart"); felix@1047: felix@1047: // Create facets. felix@1047: if (fs == null || fs.size() == 0) { felix@1047: logger.debug("No facets found."); felix@1047: continue; felix@1047: } felix@1047: logger.debug("Built stateless facets."); felix@1047: // TODO remember issues here. felix@1047: //List generated = generateOutputs(list, fs); felix@1047: //ProtocolUtils.appendOutputModes(doc, outs, generated); felix@1047: } felix@1047: felix@1047: try { felix@1047: DefaultState cur = (DefaultState) getCurrentState(context); felix@1047: if (cur.validate(this, context)) { felix@1047: List list = cur.getOutputs(); felix@1047: if (list != null && list.size() > 0) { felix@1047: logger.debug( felix@1047: "Append output modes for state: " + cur.getID()); felix@1047: felix@1047: List fs = facets.get(cur.getID()); felix@1047: if (fs != null && fs.size() > 0) { felix@1047: List generated = generateOutputs(list, fs); felix@1047: felix@1047: logger.debug("Found " + fs.size() + " current facets."); felix@1047: if (!generated.isEmpty()) { felix@1047: ProtocolUtils.appendOutputModes( felix@1047: doc, outs, generated); felix@1047: } felix@1047: else{ felix@1047: logger.debug("Cannot append output to generated document."); felix@1047: } felix@1047: } felix@1047: else { felix@1047: logger.debug("No facets found for the current state."); felix@1047: } felix@1047: } felix@1047: } felix@1047: } felix@1047: catch (IllegalArgumentException iae) { felix@1047: // state is not valid, so we do not append its outputs. felix@1047: } felix@1047: } felix@1047: felix@1047: felix@1047: /* FACET IMPLEMENTATION */ felix@1047: felix@1047: felix@1047: // TODO implement; what is index used for? felix@1047: /** felix@1047: * Returns the index of this facet. felix@1047: * felix@1047: * @return the index of this facet. felix@1047: */ felix@1047: public int getIndex() { felix@1047: return 0; felix@1047: } felix@1047: felix@1047: felix@1047: /** felix@1047: * Returns the name of this facet. felix@1047: * felix@1047: * @return the name of this facet. felix@1047: */ felix@1047: public String getName() { felix@1047: // TODO define, static felix@1047: return "FACETNAME"; felix@1047: } felix@1047: felix@1047: felix@1047: /** felix@1047: * Returns the description of this facet. felix@1047: * felix@1047: * @return the description of this facet. felix@1047: */ felix@1047: public String getDescription() { felix@1047: return null; felix@1047: } felix@1047: felix@1047: felix@1047: /** felix@1047: * Returns the data this facet requires. felix@1047: * felix@1047: * @param artifact The owner artifact. felix@1047: * @param context The CallContext. felix@1047: * felix@1047: * @return the data. felix@1047: */ felix@1047: public Object getData(Artifact artifact, CallContext context) { felix@1047: return null; felix@1047: } felix@1047: felix@1047: felix@1047: /** felix@1047: * Write the internal representation of a facet to a node. felix@1047: * felix@1047: * @param doc A Document. felix@1047: * felix@1047: * @return the representation as Node. felix@1047: */ felix@1047: public Node toXML(Document doc) { felix@1047: return null; felix@1047: } felix@1047: felix@1047: }