teichmann@475: package org.dive4elements.artifactdatabase.state; ingo@226: rrenkert@519: import java.util.HashMap; felix@351: import java.util.List; rrenkert@519: import java.util.Map; 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: teichmann@475: import org.dive4elements.artifacts.Artifact; teichmann@475: import org.dive4elements.artifacts.ArtifactNamespaceContext; teichmann@475: import org.dive4elements.artifacts.CallContext; ingo@280: teichmann@475: import org.dive4elements.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: aheinecke@488: /** The out this facet is bound to. */ aheinecke@488: protected String boundToOut; aheinecke@488: felix@351: /** The description of this facet. */ ingo@226: protected String description; ingo@226: rrenkert@519: /** The meta data this facet provides. */ rrenkert@519: protected Map metaData; felix@351: felix@351: /** Trivial, empty constructor. */ sascha@322: public DefaultFacet() { rrenkert@519: this.metaData = new HashMap(); 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; rrenkert@519: this.metaData = new HashMap(); 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: /** aheinecke@488: * Returns the name of the out this facet is bound to. aheinecke@488: * aheinecke@488: * @return the name of the out this facet is bound to. aheinecke@488: */ aheinecke@488: public String getBoundToOut() { aheinecke@488: return boundToOut; aheinecke@488: } aheinecke@488: aheinecke@488: aheinecke@488: /** aheinecke@488: * Binds this facet to an out. aheinecke@488: */ aheinecke@488: public void setBoundToOut(String value) { aheinecke@488: boundToOut = value; aheinecke@488: } aheinecke@488: aheinecke@488: aheinecke@488: /** 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: /** rrenkert@519: * Returns the meta data this facet provides. rrenkert@519: * rrenkert@519: * @param artifact The owner artifact. rrenkert@519: * @param context The CallContext. rrenkert@519: * rrenkert@519: * @return the meta data. rrenkert@519: */ rrenkert@519: @Override rrenkert@519: public Map getMetaData( rrenkert@519: Artifact artifact, rrenkert@519: CallContext context) rrenkert@519: { rrenkert@519: return this.metaData; rrenkert@519: } rrenkert@519: rrenkert@519: @Override rrenkert@519: public Map getMetaData() { rrenkert@519: return this.metaData; rrenkert@519: } rrenkert@519: rrenkert@524: @Override rrenkert@524: public void addMetaData(String key, String value) { rrenkert@524: this.metaData.put(key, value); rrenkert@524: } rrenkert@524: rrenkert@519: /** 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@378: /* felix@378: * Return list of keys (objects) for which this facet can provide data felix@378: * ("external parameterization"), for other facets, via blackboard. felix@378: * These are the keys that are independent from the current call (thus felix@378: * 'static'). felix@378: * @param artifact that this facet belongs to. felix@378: */ felix@378: public List getStaticDataProviderKeys(Artifact artifact) { felix@378: return null; felix@378: } felix@378: 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@378: public List getDataProviderKeys(Artifact artifact, CallContext context) { felix@378: return getStaticDataProviderKeys(artifact); 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); aheinecke@488: ec.addAttr(facet, "boundToOut", boundToOut, 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 = '") aheinecke@488: .append(description).append("', bound_out = '") aheinecke@488: .append(boundToOut).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(); aheinecke@488: boundToOut = other.getBoundToOut(); gernotbelger@552: // FIXME: metadata ist NOT immutable, but a reference is simply copied during a 'deep' copy operation... rrenkert@519: metaData = other.getMetaData(); 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 :