ingo@226: package de.intevation.artifactdatabase.state; ingo@226: felix@351: import java.util.List; felix@351: ingo@295: import org.w3c.dom.Document; ingo@295: import org.w3c.dom.Element; ingo@295: import org.w3c.dom.Node; ingo@295: ingo@280: import de.intevation.artifacts.Artifact; ingo@295: import de.intevation.artifacts.ArtifactNamespaceContext; ingo@280: import de.intevation.artifacts.CallContext; ingo@280: ingo@295: import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; ingo@295: ingo@226: ingo@226: /** ingo@226: * The default implementation of a Facet. ingo@226: * ingo@226: * @author Ingo Weinzierl ingo@226: */ ingo@226: public class DefaultFacet implements Facet { ingo@226: felix@351: /** The index of this facet. */ ingo@277: protected int index; ingo@277: felix@351: /** The name of this facet. */ ingo@226: protected String name; ingo@226: felix@351: /** The description of this facet. */ ingo@226: protected String description; ingo@226: felix@351: felix@351: /** Trivial, empty constructor. */ sascha@322: public DefaultFacet() { sascha@322: } ingo@226: felix@351: ingo@226: /** ingo@226: * The default constructor to create new Facet objects. ingo@226: * ingo@226: * @param name The name of this new facet. ingo@226: * @param description The description of this new facet. ingo@226: */ ingo@226: public DefaultFacet(String name, String description) { ingo@277: this(0, name, description); ingo@277: } ingo@277: ingo@277: ingo@277: /** ingo@277: * The default constructor to create new Facet objects. ingo@277: * ingo@277: * @param index The index of this new facet. ingo@277: * @param name The name of this new facet. ingo@277: * @param description The description of this new facet. ingo@277: */ ingo@277: public DefaultFacet(int index, String name, String description) { ingo@277: this.index = index; ingo@226: this.name = name; ingo@226: this.description = description; ingo@226: } ingo@226: felix@351: felix@367: /** Get index. */ ingo@277: public int getIndex() { ingo@277: return index; ingo@277: } ingo@277: ingo@277: felix@367: /** Returns the name ('type'). */ ingo@226: public String getName() { ingo@226: return name; ingo@226: } ingo@226: ingo@226: felix@367: /** Returns the description (e.g. displayed in gui). */ ingo@226: public String getDescription() { ingo@226: return description; ingo@226: } ingo@280: ingo@280: felix@351: /** felix@351: * @return null felix@351: */ ingo@280: public Object getData(Artifact artifact, CallContext context) { ingo@280: return null; ingo@280: } sascha@283: felix@351: felix@351: /** felix@351: * (Do not) provide data. felix@351: * Override to allow other facets to access your data. felix@351: * @return always null. felix@351: */ felix@351: public Object provideBlackboardData( felix@351: Artifact artifact, felix@351: Object key, felix@351: Object param, felix@351: CallContext context felix@351: ) { felix@351: return null; felix@351: } felix@351: felix@351: felix@351: /** felix@351: * Return list of keys (objects) for which this facet can provide data felix@351: * ("external parameterization"), for other facets, via blackboard. felix@357: * @param artifact that this facet belongs to. felix@351: */ felix@357: public List getDataProviderKeys(Artifact artifact) { felix@351: return null; felix@351: } felix@351: felix@351: felix@367: /** Create a xml represantation. */ ingo@295: public Node toXML(Document doc) { ingo@295: ElementCreator ec = new ElementCreator( ingo@295: doc, ingo@295: ArtifactNamespaceContext.NAMESPACE_URI, ingo@295: ArtifactNamespaceContext.NAMESPACE_PREFIX); ingo@295: ingo@295: Element facet = ec.create("facet"); ingo@295: ec.addAttr(facet, "description", description, true); ingo@295: ec.addAttr(facet, "name", name, true); ingo@295: ec.addAttr(facet, "index", String.valueOf(index), true); ingo@295: ingo@295: return facet; ingo@295: } felix@367: felix@367: felix@367: /** Create a string representation. */ felix@367: public String toString() { felix@367: return new StringBuilder("name = '") felix@367: .append(name).append("', index = ") felix@367: .append(index).append(", description = '") felix@367: .append(description).append("'") felix@367: .toString(); felix@367: } felix@367: felix@367: felix@367: /** felix@367: * Copies name, index and description of other facet. felix@367: */ felix@367: public void set(Facet other) { felix@367: index = other.getIndex(); felix@367: name = other.getName(); felix@367: description = other.getDescription(); felix@367: } felix@367: felix@367: felix@367: /** Create a deep copy of this facet. */ felix@367: public Facet deepCopy() { felix@367: DefaultFacet copy = new DefaultFacet(); felix@367: copy.set(this); felix@367: return copy; felix@367: } ingo@226: } ingo@226: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :