comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/state/DefaultFacet.java @ 473:d0ac790a6c89 dive4elements-move

Moved directories to org.dive4elements
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 10:57:18 +0200
parents artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultFacet.java@71ff234713a6
children 415df0fc4fa1
comparison
equal deleted inserted replaced
472:783cc1b6b615 473:d0ac790a6c89
1 package de.intevation.artifactdatabase.state;
2
3 import java.util.List;
4
5 import org.w3c.dom.Document;
6 import org.w3c.dom.Element;
7 import org.w3c.dom.Node;
8
9 import de.intevation.artifacts.Artifact;
10 import de.intevation.artifacts.ArtifactNamespaceContext;
11 import de.intevation.artifacts.CallContext;
12
13 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
14
15
16 /**
17 * The default implementation of a Facet.
18 *
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
20 */
21 public class DefaultFacet implements Facet {
22
23 /** The index of this facet. */
24 protected int index;
25
26 /** The name of this facet. */
27 protected String name;
28
29 /** The description of this facet. */
30 protected String description;
31
32
33 /** Trivial, empty constructor. */
34 public DefaultFacet() {
35 }
36
37
38 /**
39 * The default constructor to create new Facet objects.
40 *
41 * @param name The name of this new facet.
42 * @param description The description of this new facet.
43 */
44 public DefaultFacet(String name, String description) {
45 this(0, name, description);
46 }
47
48
49 /**
50 * The default constructor to create new Facet objects.
51 *
52 * @param index The index of this new facet.
53 * @param name The name of this new facet.
54 * @param description The description of this new facet.
55 */
56 public DefaultFacet(int index, String name, String description) {
57 this.index = index;
58 this.name = name;
59 this.description = description;
60 }
61
62
63 /** Get index. */
64 public int getIndex() {
65 return index;
66 }
67
68
69 /** Returns the name ('type'). */
70 public String getName() {
71 return name;
72 }
73
74
75 /** Returns the description (e.g. displayed in gui). */
76 public String getDescription() {
77 return description;
78 }
79
80
81 /**
82 * @return null
83 */
84 public Object getData(Artifact artifact, CallContext context) {
85 return null;
86 }
87
88
89 /**
90 * (Do not) provide data.
91 * Override to allow other facets to access your data.
92 * @return always null.
93 */
94 public Object provideBlackboardData(
95 Artifact artifact,
96 Object key,
97 Object param,
98 CallContext context
99 ) {
100 return null;
101 }
102
103
104 /*
105 * Return list of keys (objects) for which this facet can provide data
106 * ("external parameterization"), for other facets, via blackboard.
107 * These are the keys that are independent from the current call (thus
108 * 'static').
109 * @param artifact that this facet belongs to.
110 */
111 public List getStaticDataProviderKeys(Artifact artifact) {
112 return null;
113 }
114
115 /**
116 * Return list of keys (objects) for which this facet can provide data
117 * ("external parameterization"), for other facets, via blackboard.
118 * @param artifact that this facet belongs to.
119 */
120 public List getDataProviderKeys(Artifact artifact, CallContext context) {
121 return getStaticDataProviderKeys(artifact);
122 }
123
124
125 /** Create a xml represantation. */
126 public Node toXML(Document doc) {
127 ElementCreator ec = new ElementCreator(
128 doc,
129 ArtifactNamespaceContext.NAMESPACE_URI,
130 ArtifactNamespaceContext.NAMESPACE_PREFIX);
131
132 Element facet = ec.create("facet");
133 ec.addAttr(facet, "description", description, true);
134 ec.addAttr(facet, "name", name, true);
135 ec.addAttr(facet, "index", String.valueOf(index), true);
136
137 return facet;
138 }
139
140
141 /** Create a string representation. */
142 public String toString() {
143 return new StringBuilder("name = '")
144 .append(name).append("', index = ")
145 .append(index).append(", description = '")
146 .append(description).append("'")
147 .toString();
148 }
149
150
151 /**
152 * Copies name, index and description of other facet.
153 */
154 public void set(Facet other) {
155 index = other.getIndex();
156 name = other.getName();
157 description = other.getDescription();
158 }
159
160
161 /** Create a deep copy of this facet. */
162 public Facet deepCopy() {
163 DefaultFacet copy = new DefaultFacet();
164 copy.set(this);
165 return copy;
166 }
167 }
168 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org