Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/AbstractCallContext.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/AbstractCallContext.java@f367be55dd35 |
children | 415df0fc4fa1 |
comparison
equal
deleted
inserted
replaced
472:783cc1b6b615 | 473:d0ac790a6c89 |
---|---|
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 java.util.ArrayList; | |
13 import java.util.List; | |
14 import java.util.Map; | |
15 import java.util.HashMap; | |
16 | |
17 import de.intevation.artifacts.ArtifactDatabase; | |
18 import de.intevation.artifacts.CallContext; | |
19 import de.intevation.artifacts.CallMeta; | |
20 import de.intevation.artifacts.DataProvider; | |
21 | |
22 | |
23 /** | |
24 * Abstract class that implements some basic methods of a CallContext. | |
25 * | |
26 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | |
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
28 */ | |
29 public abstract class AbstractCallContext implements CallContext { | |
30 | |
31 Logger logger = Logger.getLogger(AbstractCallContext.class); | |
32 | |
33 /** | |
34 * The ArtifactDatabase instance. | |
35 */ | |
36 protected ArtifactDatabaseImpl database; | |
37 | |
38 /** | |
39 * The action to be performed after the artifacts or collections calls. | |
40 */ | |
41 protected int action; | |
42 | |
43 /** | |
44 * The meta information of the concrete call (preferred languages et. al.) | |
45 */ | |
46 protected CallMeta callMeta; | |
47 | |
48 /** | |
49 * Map to act like a clipboard when nesting calls like a proxy artifact. | |
50 */ | |
51 protected Map customValues; | |
52 | |
53 /** | |
54 * Map to act like a clipboard when nesting calls like a proxy artifact. | |
55 */ | |
56 protected Map<Object, List<DataProvider>> dataProviders; | |
57 | |
58 | |
59 /** | |
60 * The default constructor of this abstract CallContext. | |
61 * | |
62 * @param artifactDatabase The artifact database. | |
63 * @param action The action. | |
64 * @param callMeta The CallMeta object. | |
65 */ | |
66 public AbstractCallContext( | |
67 ArtifactDatabaseImpl artifactDatabase, | |
68 int action, | |
69 CallMeta callMeta | |
70 ) { | |
71 this.database = artifactDatabase; | |
72 this.action = action; | |
73 this.callMeta = callMeta; | |
74 | |
75 database.initCallContext(this); | |
76 } | |
77 | |
78 | |
79 public void postCall() { | |
80 database.closeCallContext(this); | |
81 } | |
82 | |
83 public abstract void afterCall(int action); | |
84 | |
85 public abstract Long getTimeToLive(); | |
86 | |
87 public abstract void afterBackground(int action); | |
88 | |
89 | |
90 public Object globalContext() { | |
91 return database.context; | |
92 } | |
93 | |
94 | |
95 public ArtifactDatabase getDatabase() { | |
96 return database; | |
97 } | |
98 | |
99 | |
100 public CallMeta getMeta() { | |
101 return callMeta; | |
102 } | |
103 | |
104 | |
105 public Object getContextValue(Object key) { | |
106 return customValues != null | |
107 ? customValues.get(key) | |
108 : null; | |
109 } | |
110 | |
111 public Object putContextValue(Object key, Object value) { | |
112 if (customValues == null) { | |
113 customValues = new HashMap(); | |
114 } | |
115 return customValues.put(key, value); | |
116 } | |
117 | |
118 /** | |
119 * Get list of DataProviders that registered for given key. | |
120 * @return list (empty list if none found, never null). | |
121 */ | |
122 public List<DataProvider> getDataProvider(Object key) { | |
123 if (dataProviders != null) { | |
124 List<DataProvider> list = dataProviders.get(key); | |
125 return list != null | |
126 ? list | |
127 : java.util.Collections.<DataProvider>emptyList(); | |
128 } | |
129 return java.util.Collections.<DataProvider>emptyList(); | |
130 } | |
131 | |
132 | |
133 /** | |
134 * Let a DataProvider register itself with given key. | |
135 * Multiple DataProvider can register under the same key. | |
136 */ | |
137 public Object registerDataProvider(Object key, DataProvider value) { | |
138 List<DataProvider> providers = null; | |
139 if (dataProviders == null) { | |
140 dataProviders = new HashMap(); | |
141 providers = new ArrayList<DataProvider>(); | |
142 providers.add(value); | |
143 return dataProviders.put(key, providers); | |
144 } | |
145 providers = dataProviders.get(key); | |
146 | |
147 if (providers == null) { | |
148 providers = new ArrayList<DataProvider>(); | |
149 } | |
150 providers.add(value); | |
151 return dataProviders.put(key, providers); | |
152 } | |
153 } | |
154 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |