Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 48:41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
artifacts/trunk@168 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 01 Oct 2009 16:03:12 +0000 |
parents | 4ae4dc99127d |
children | 9a29899b31e5 |
comparison
equal
deleted
inserted
replaced
47:4ae4dc99127d | 48:41c225c8bd41 |
---|---|
8 import de.intevation.artifacts.ArtifactDatabaseException; | 8 import de.intevation.artifacts.ArtifactDatabaseException; |
9 import de.intevation.artifacts.ArtifactDatabase; | 9 import de.intevation.artifacts.ArtifactDatabase; |
10 import de.intevation.artifacts.ArtifactFactory; | 10 import de.intevation.artifacts.ArtifactFactory; |
11 import de.intevation.artifacts.Artifact; | 11 import de.intevation.artifacts.Artifact; |
12 import de.intevation.artifacts.CallContext; | 12 import de.intevation.artifacts.CallContext; |
13 import de.intevation.artifacts.CallMeta; | |
13 | 14 |
14 import de.intevation.artifactdatabase.Backend.PersistentArtifact; | 15 import de.intevation.artifactdatabase.Backend.PersistentArtifact; |
15 | 16 |
16 import org.apache.log4j.Logger; | 17 import org.apache.log4j.Logger; |
17 | 18 |
50 public class CallContextImpl | 51 public class CallContextImpl |
51 implements CallContext | 52 implements CallContext |
52 { | 53 { |
53 protected PersistentArtifact artifact; | 54 protected PersistentArtifact artifact; |
54 protected int action; | 55 protected int action; |
55 | 56 protected CallMeta callMeta; |
56 public CallContextImpl(PersistentArtifact artifact, int action) { | 57 |
58 public CallContextImpl( | |
59 PersistentArtifact artifact, | |
60 int action, | |
61 CallMeta callMeta | |
62 ) { | |
57 this.artifact = artifact; | 63 this.artifact = artifact; |
58 this.action = action; | 64 this.action = action; |
65 this.callMeta = callMeta; | |
59 } | 66 } |
60 | 67 |
61 public void afterCall(int action) { | 68 public void afterCall(int action) { |
62 this.action = action; | 69 this.action = action; |
63 if (action == BACKGROUND) { | 70 if (action == BACKGROUND) { |
72 fromBackground(artifact, action); | 79 fromBackground(artifact, action); |
73 } | 80 } |
74 | 81 |
75 public Object globalContext() { | 82 public Object globalContext() { |
76 return context; | 83 return context; |
84 } | |
85 | |
86 public CallMeta getMeta() { | |
87 return callMeta; | |
77 } | 88 } |
78 | 89 |
79 public void postCall() { | 90 public void postCall() { |
80 switch (action) { | 91 switch (action) { |
81 case NOTHING: | 92 case NOTHING: |
100 public class DeferredOutputImpl | 111 public class DeferredOutputImpl |
101 implements DeferredOutput | 112 implements DeferredOutput |
102 { | 113 { |
103 protected PersistentArtifact artifact; | 114 protected PersistentArtifact artifact; |
104 protected Document format; | 115 protected Document format; |
116 protected CallMeta callMeta; | |
105 | 117 |
106 public DeferredOutputImpl() { | 118 public DeferredOutputImpl() { |
107 } | 119 } |
108 | 120 |
109 public DeferredOutputImpl( | 121 public DeferredOutputImpl( |
110 PersistentArtifact artifact, | 122 PersistentArtifact artifact, |
111 Document format | 123 Document format, |
124 CallMeta callMeta | |
112 ) { | 125 ) { |
113 this.artifact = artifact; | 126 this.artifact = artifact; |
114 this.format = format; | 127 this.format = format; |
128 this.callMeta = callMeta; | |
115 } | 129 } |
116 | 130 |
117 public void write(OutputStream output) throws IOException { | 131 public void write(OutputStream output) throws IOException { |
118 | 132 |
119 CallContextImpl cc = new CallContextImpl( | 133 CallContextImpl cc = new CallContextImpl( |
120 artifact, CallContext.TOUCH); | 134 artifact, CallContext.TOUCH, callMeta); |
121 | 135 |
122 try { | 136 try { |
123 artifact.getArtifact().out(format, output, cc); | 137 artifact.getArtifact().out(format, output, cc); |
124 } | 138 } |
125 finally { | 139 finally { |
225 | 239 |
226 public ArtifactFactory getArtifactFactory(String factoryName) { | 240 public ArtifactFactory getArtifactFactory(String factoryName) { |
227 return (ArtifactFactory)name2factory.get(factoryName); | 241 return (ArtifactFactory)name2factory.get(factoryName); |
228 } | 242 } |
229 | 243 |
230 public Document createArtifactWithFactory(String factoryName) | 244 public Document createArtifactWithFactory( |
231 throws ArtifactDatabaseException | 245 String factoryName, |
246 CallMeta callMeta | |
247 ) | |
248 throws ArtifactDatabaseException | |
232 { | 249 { |
233 ArtifactFactory factory = getArtifactFactory(factoryName); | 250 ArtifactFactory factory = getArtifactFactory(factoryName); |
234 | 251 |
235 if (factory == null) { | 252 if (factory == null) { |
236 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); | 253 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); |
256 logger.error(e.getLocalizedMessage(), e); | 273 logger.error(e.getLocalizedMessage(), e); |
257 throw new ArtifactDatabaseException(CREATION_FAILED); | 274 throw new ArtifactDatabaseException(CREATION_FAILED); |
258 } | 275 } |
259 | 276 |
260 CallContextImpl cc = new CallContextImpl( | 277 CallContextImpl cc = new CallContextImpl( |
261 persistentArtifact, CallContext.NOTHING); | 278 persistentArtifact, CallContext.NOTHING, callMeta); |
262 | 279 |
263 try { | 280 try { |
264 return artifact.describe(cc); | 281 return artifact.describe(cc); |
265 } | 282 } |
266 finally { | 283 finally { |
267 cc.postCall(); | 284 cc.postCall(); |
268 } | 285 } |
269 } | 286 } |
270 | 287 |
271 public Document describe(String identifier) | 288 public Document describe(String identifier, CallMeta callMeta) |
272 throws ArtifactDatabaseException | 289 throws ArtifactDatabaseException |
273 { | 290 { |
274 // TODO: Handle background tasks | 291 // TODO: Handle background tasks |
275 PersistentArtifact artifact = backend.getArtifact(identifier); | 292 PersistentArtifact artifact = backend.getArtifact(identifier); |
276 | 293 |
277 if (artifact == null) { | 294 if (artifact == null) { |
278 throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); | 295 throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); |
279 } | 296 } |
280 | 297 |
281 CallContextImpl cc = new CallContextImpl( | 298 CallContextImpl cc = new CallContextImpl( |
282 artifact, CallContext.TOUCH); | 299 artifact, CallContext.TOUCH, callMeta); |
283 | 300 |
284 try { | 301 try { |
285 return artifact.getArtifact().describe(cc); | 302 return artifact.getArtifact().describe(cc); |
286 } | 303 } |
287 finally { | 304 finally { |
288 cc.postCall(); | 305 cc.postCall(); |
289 } | 306 } |
290 } | 307 } |
291 | 308 |
292 public Document advance(String identifier, Document target) | 309 public Document advance(String identifier, Document target, CallMeta callMeta) |
293 throws ArtifactDatabaseException | 310 throws ArtifactDatabaseException |
294 { | 311 { |
295 // TODO: Handle background tasks | 312 // TODO: Handle background tasks |
296 PersistentArtifact artifact = backend.getArtifact(identifier); | 313 PersistentArtifact artifact = backend.getArtifact(identifier); |
297 | 314 |
298 if (artifact == null) { | 315 if (artifact == null) { |
299 throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); | 316 throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); |
300 } | 317 } |
301 | 318 |
302 CallContextImpl cc = new CallContextImpl( | 319 CallContextImpl cc = new CallContextImpl( |
303 artifact, CallContext.STORE); | 320 artifact, CallContext.STORE, callMeta); |
304 | 321 |
305 try { | 322 try { |
306 return artifact.getArtifact().advance(target, cc); | 323 return artifact.getArtifact().advance(target, cc); |
307 } | 324 } |
308 finally { | 325 finally { |
309 cc.postCall(); | 326 cc.postCall(); |
310 } | 327 } |
311 } | 328 } |
312 | 329 |
313 public Document feed(String identifier, Document data) | 330 public Document feed(String identifier, Document data, CallMeta callMeta) |
314 throws ArtifactDatabaseException | 331 throws ArtifactDatabaseException |
315 { | 332 { |
316 // TODO: Handle background tasks | 333 // TODO: Handle background tasks |
317 PersistentArtifact artifact = backend.getArtifact(identifier); | 334 PersistentArtifact artifact = backend.getArtifact(identifier); |
318 | 335 |
319 if (artifact == null) { | 336 if (artifact == null) { |
320 throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); | 337 throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); |
321 } | 338 } |
322 | 339 |
323 CallContextImpl cc = new CallContextImpl( | 340 CallContextImpl cc = new CallContextImpl( |
324 artifact, CallContext.STORE); | 341 artifact, CallContext.STORE, callMeta); |
325 | 342 |
326 try { | 343 try { |
327 return artifact.getArtifact().feed(data, cc); | 344 return artifact.getArtifact().feed(data, cc); |
328 } | 345 } |
329 finally { | 346 finally { |
330 cc.postCall(); | 347 cc.postCall(); |
331 } | 348 } |
332 } | 349 } |
333 | 350 |
334 public DeferredOutput out(String identifier, Document format) | 351 public DeferredOutput out(String identifier, Document format, CallMeta callMeta) |
335 throws ArtifactDatabaseException | 352 throws ArtifactDatabaseException |
336 { | 353 { |
337 // TODO: Handle background tasks | 354 // TODO: Handle background tasks |
338 PersistentArtifact artifact = backend.getArtifact(identifier); | 355 PersistentArtifact artifact = backend.getArtifact(identifier); |
339 | 356 |
340 if (artifact == null) { | 357 if (artifact == null) { |
341 throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); | 358 throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); |
342 } | 359 } |
343 | 360 |
344 return new DeferredOutputImpl(artifact, format); | 361 return new DeferredOutputImpl(artifact, format, callMeta); |
345 } | 362 } |
346 } | 363 } |
347 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: | 364 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |