Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactCollection.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/DefaultArtifactCollection.java@f367be55dd35 |
children | 415df0fc4fa1 |
comparison
equal
deleted
inserted
replaced
472:783cc1b6b615 | 473:d0ac790a6c89 |
---|---|
1 /* | |
2 * Copyright (c) 2011 by Intevation GmbH | |
3 * | |
4 * This program is free software under the LGPL (>=v2.1) | |
5 * Read the file LGPL.txt coming with the software for details | |
6 * or visit http://www.gnu.org/licenses/ if it does not exist. | |
7 */ | |
8 package de.intevation.artifactdatabase; | |
9 | |
10 import java.io.IOException; | |
11 import java.io.OutputStream; | |
12 | |
13 import java.util.ArrayList; | |
14 import java.util.Date; | |
15 import java.util.HashMap; | |
16 import java.util.List; | |
17 import java.util.Map; | |
18 | |
19 import org.apache.log4j.Logger; | |
20 | |
21 import org.w3c.dom.Document; | |
22 | |
23 import de.intevation.artifacts.Artifact; | |
24 import de.intevation.artifacts.ArtifactCollection; | |
25 import de.intevation.artifacts.ArtifactCollectionFactory; | |
26 import de.intevation.artifacts.CallContext; | |
27 import de.intevation.artifacts.User; | |
28 | |
29 import de.intevation.artifacts.common.utils.XMLUtils; | |
30 | |
31 | |
32 /** | |
33 * Trivial implementation of an artifact collection. Useful to be subclassed. | |
34 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
35 */ | |
36 public class DefaultArtifactCollection | |
37 implements ArtifactCollection | |
38 { | |
39 /** The logger used in this class. */ | |
40 private static Logger logger = | |
41 Logger.getLogger(DefaultArtifactCollection.class); | |
42 | |
43 /** The identifier of the collection. */ | |
44 protected String identifier; | |
45 | |
46 /** The identifier of the collection. */ | |
47 protected String name; | |
48 | |
49 /** The owner of this collection. */ | |
50 protected User user; | |
51 | |
52 /** The attribute of this collection. */ | |
53 protected Document attribute; | |
54 | |
55 /** The artifacts stored in this collection. */ | |
56 protected List<Artifact> artifacts; | |
57 | |
58 /** | |
59 * The attributes used for the artifacts stored in this collection. The key | |
60 * of this map represents the identifier of the artifact which the attribute | |
61 * belong to. | |
62 */ | |
63 protected Map<String, Document> attributes; | |
64 | |
65 /** The creation time of this collection.*/ | |
66 protected Date creationTime; | |
67 | |
68 protected long ttl; | |
69 | |
70 | |
71 /** | |
72 * Default constructor. | |
73 */ | |
74 public DefaultArtifactCollection() { | |
75 } | |
76 | |
77 | |
78 /** | |
79 * When created by a factory this method is called to | |
80 * initialize the collection. | |
81 * @param identifier The identifier from collection database | |
82 * @param factory The factory which created this collection. | |
83 * @param context The global context of the runtime system. | |
84 * @param data The data which can be use to setup a collection with | |
85 * more details. | |
86 */ | |
87 public void setup( | |
88 String identifier, | |
89 String name, | |
90 Date creationTime, | |
91 long ttl, | |
92 ArtifactCollectionFactory factory, | |
93 Object context, | |
94 Document data) | |
95 { | |
96 logger.debug("DefaultArtifactCollection.setup: " + identifier); | |
97 | |
98 artifacts = new ArrayList<Artifact>(); | |
99 attributes = new HashMap<String, Document>(); | |
100 | |
101 setIdentifier(identifier); | |
102 setName(name); | |
103 setCreationTime(creationTime); | |
104 setTTL(ttl); | |
105 setAttribute(data); | |
106 } | |
107 | |
108 | |
109 public Document describe(CallContext context) { | |
110 logger.debug("DefaultArtifactCollection.describe: " + identifier); | |
111 | |
112 return XMLUtils.newDocument(); | |
113 } | |
114 | |
115 | |
116 /** | |
117 * Set a new identifier for this collection. | |
118 * @param identifier New identifier for this collection. | |
119 */ | |
120 public void setIdentifier(String identifier) { | |
121 this.identifier = identifier; | |
122 } | |
123 | |
124 | |
125 /** | |
126 * Identify this collection. | |
127 * @return Returns unique string to identify this collection globally. | |
128 */ | |
129 public String identifier() { | |
130 return identifier; | |
131 } | |
132 | |
133 | |
134 /** | |
135 * Name of this collection. | |
136 * @return Returns the name of this collection | |
137 */ | |
138 public String getName() { | |
139 return name; | |
140 } | |
141 | |
142 /** | |
143 * Name of this collection. | |
144 * @param name the name of this collection | |
145 */ | |
146 public void setName(String name) { | |
147 this.name = name; | |
148 } | |
149 | |
150 | |
151 /** | |
152 * Set a new owner of this collection. | |
153 * @param user New owner for this collection. | |
154 */ | |
155 public void setUser(User user) { | |
156 this.user = user; | |
157 } | |
158 | |
159 | |
160 /** | |
161 * Identify the owner of the collection. | |
162 * @return Returns owner of the collection. | |
163 */ | |
164 public User getUser() { | |
165 return user; | |
166 } | |
167 | |
168 | |
169 /** | |
170 * Returns the creation time of the collection. | |
171 * | |
172 * @return the creation time of the collection. | |
173 */ | |
174 public Date getCreationTime() { | |
175 return creationTime; | |
176 } | |
177 | |
178 | |
179 /** | |
180 * Sets the creation time of the collection. | |
181 * | |
182 * @param creationTime The new creation time. | |
183 */ | |
184 public void setCreationTime(Date creationTime) { | |
185 this.creationTime = creationTime; | |
186 } | |
187 | |
188 | |
189 public long getTTL() { | |
190 return ttl; | |
191 } | |
192 | |
193 | |
194 public void setTTL(long ttl) { | |
195 this.ttl = ttl; | |
196 } | |
197 | |
198 | |
199 /** | |
200 * Returns the attribute of the collection. | |
201 * | |
202 * @return the attribute of the collection. | |
203 */ | |
204 public Document getAttribute() { | |
205 return attribute; | |
206 } | |
207 | |
208 | |
209 /** | |
210 * Sets the attribute of the collection. | |
211 * | |
212 * @param attribute The attribute of this collection. | |
213 */ | |
214 public void setAttribute(Document attribute) { | |
215 this.attribute = attribute; | |
216 } | |
217 | |
218 | |
219 /** | |
220 * Called from artifact database when an artifact is | |
221 * going to be removed from system. | |
222 * @param context The global context of the runtime system. | |
223 */ | |
224 public void endOfLife(Object context) { | |
225 logger.debug("DefaultArtifactCollection.endOfLife"); | |
226 } | |
227 | |
228 | |
229 /** | |
230 * Internal hash of this collection. | |
231 * @return Returns hash that should stay the same if the internal | |
232 * value has not changed. Useful for caching | |
233 */ | |
234 public String hash() { | |
235 logger.debug("DefaultArtifactCollection.hash"); | |
236 | |
237 return String.valueOf(hashCode()); | |
238 } | |
239 | |
240 | |
241 /** | |
242 * Called from artifact database before an artifact is | |
243 * going to be exported as xml document. | |
244 * @param context The global context of the runtime system. | |
245 */ | |
246 public void cleanup(Object context) { | |
247 logger.debug("DefaultArtifactCollection.cleanup"); | |
248 } | |
249 | |
250 | |
251 /** | |
252 * Adds a new artifact to this collection. | |
253 * | |
254 * @param artifact The new artifact. | |
255 * @param attribute The attributes used for this artifact. | |
256 * @param context The CallContext. | |
257 */ | |
258 public void addArtifact( | |
259 Artifact artifact, | |
260 Document attribute, | |
261 CallContext context) | |
262 { | |
263 logger.debug("DefaultArtifactCollection.addArtifact"); | |
264 | |
265 artifacts.add(artifact); | |
266 attributes.put(artifact.identifier(), attribute); | |
267 } | |
268 | |
269 | |
270 /** | |
271 * Removes the given artifact from this collection. | |
272 * | |
273 * @param artifact The artifact that should be removed. | |
274 * @param context The CallContext. | |
275 */ | |
276 public void removeArtifact(Artifact artifact, CallContext context) { | |
277 logger.debug("DefaultArtifactCollection.removeArtifact"); | |
278 | |
279 if (artifact == null) { | |
280 return; | |
281 } | |
282 | |
283 artifacts.remove(artifact); | |
284 attributes.remove(artifact.identifier()); | |
285 } | |
286 | |
287 | |
288 /** | |
289 * Returns a list of artifacts that are stored in this collection. | |
290 * | |
291 * @param context The CallContext. | |
292 * | |
293 * @return the list of artifacts stored in this collection. | |
294 */ | |
295 public Artifact[] getArtifacts(CallContext context) { | |
296 logger.debug("DefaultArtifactCollection.getArtifacts"); | |
297 | |
298 return (Artifact[]) artifacts.toArray(); | |
299 } | |
300 | |
301 | |
302 /** | |
303 * Returns the attribute document for the given artifact. | |
304 * | |
305 * @param artifact The artifact. | |
306 * @param context The CallContext. | |
307 * | |
308 * @return a document that contains the attributes of the artifact. | |
309 */ | |
310 public Document getAttribute(Artifact artifact, CallContext context) { | |
311 logger.debug("DefaultArtifactCollection.getAttribute"); | |
312 | |
313 return attributes.get(artifact.identifier()); | |
314 } | |
315 | |
316 | |
317 /** | |
318 * Set the attribute for the given artifact. | |
319 * | |
320 * @param artifact The artifact of the attribute. | |
321 * @param document The new attribute of the artifact. | |
322 * @param context The CallContext. | |
323 */ | |
324 public void setAttribute( | |
325 Artifact artifact, | |
326 Document document, | |
327 CallContext context) | |
328 { | |
329 logger.debug("DefaultArtifactCollection.setAttribute"); | |
330 | |
331 attributes.put(artifact.identifier(), document); | |
332 } | |
333 | |
334 | |
335 /** | |
336 * Produce output for this collection. | |
337 * @param type Specifies the output type. | |
338 * @param format Specifies the format of the output. | |
339 * @param out Stream to write the result data to. | |
340 * @param context The global context of the runtime system. | |
341 * @throws IOException Thrown if an I/O occurs. | |
342 */ | |
343 public void out( | |
344 String type, | |
345 Document format, | |
346 OutputStream out, | |
347 CallContext context) | |
348 throws IOException | |
349 { | |
350 logger.debug("DefaultArtifactCollection.out"); | |
351 } | |
352 } | |
353 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |