comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactCallContext.java @ 219:cabe4c02ab64

Refactored the CallContextImpl - there are two concrete classes for Artifacts and ArtifactCollections now. artifacts/trunk@1559 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 24 Mar 2011 16:16:51 +0000
parents
children a8a06bbe306c
comparison
equal deleted inserted replaced
218:70cbbe144931 219:cabe4c02ab64
1 /*
2 * Copyright (c) 2010, 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 org.apache.log4j.Logger;
11
12 import de.intevation.artifacts.CallMeta;
13
14 import de.intevation.artifactdatabase.Backend.PersistentArtifact;
15
16
17 /**
18 * Class that implements the call context handed to the methods calls
19 * describe(), feed(), etc. of the artifact.
20 *
21 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
22 */
23 public class ArtifactCallContext extends AbstractCallContext {
24
25 private static Logger logger = Logger.getLogger(ArtifactCallContext.class);
26
27
28 /**
29 * Error message issued if an artifact wants to translate itself
30 * into a none valid persistent state.
31 */
32 public static final String INVALID_CALL_STATE = "Invalid after call state";
33
34 /**
35 * Error message issued if one tries to remove a requested artifact
36 * from the list of artifacts running in background which is
37 * not in this list.
38 */
39 public static final String NOT_IN_BACKGROUND = "Not in background";
40
41
42 /**
43 * The persistence wrapper around the living artifact
44 */
45 protected PersistentArtifact artifact;
46
47
48 public ArtifactCallContext(
49 ArtifactDatabaseImpl artifactDatabase,
50 int action,
51 CallMeta callMeta,
52 Object context,
53 PersistentArtifact artifact)
54 {
55 super(artifactDatabase, action, callMeta, context);
56
57 this.artifact = artifact;
58 }
59
60
61 public void afterCall(int action) {
62 this.action = action;
63 if (action == BACKGROUND) {
64 database.addIdToBackground(artifact.getId());
65 }
66 }
67
68
69 public void afterBackground(int action) {
70 if (this.action != BACKGROUND) {
71 throw new IllegalStateException(NOT_IN_BACKGROUND);
72 }
73 database.fromBackground(artifact, action);
74 }
75
76
77 public Long getTimeToLive() {
78 return artifact.getTTL();
79 }
80
81
82 /**
83 * Dispatches and executes the persistence action after
84 * the return of the concrete artifact call.
85 */
86 public void postCall() {
87 switch (action) {
88 case NOTHING:
89 break;
90 case TOUCH:
91 artifact.touch();
92 break;
93 case STORE:
94 artifact.store();
95 break;
96 case BACKGROUND:
97 logger.warn(
98 "BACKGROUND processing is not fully implemented, yet!");
99 artifact.store();
100 break;
101 default:
102 logger.error(INVALID_CALL_STATE + ": " + action);
103 throw new IllegalStateException(INVALID_CALL_STATE);
104 }
105 }
106 }
107 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org