Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 70:ce488c1d3fc4
Serve services over artifact database.
artifacts/trunk@597 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 22 Jan 2010 11:08:40 +0000 |
parents | 541814404822 |
children | d4c4c23847f5 |
comparison
equal
deleted
inserted
replaced
69:498bb84334d0 | 70:ce488c1d3fc4 |
---|---|
1 package de.intevation.artifactdatabase; | 1 package de.intevation.artifactdatabase; |
2 | 2 |
3 import de.intevation.artifactdatabase.Backend.PersistentArtifact; | |
4 | |
5 import de.intevation.artifacts.Artifact; | |
6 import de.intevation.artifacts.ArtifactDatabase; | |
7 import de.intevation.artifacts.ArtifactDatabaseException; | |
8 import de.intevation.artifacts.ArtifactFactory; | |
9 import de.intevation.artifacts.CallContext; | |
10 import de.intevation.artifacts.CallMeta; | |
11 import de.intevation.artifacts.Service; | |
12 import de.intevation.artifacts.ServiceFactory; | |
13 | |
14 import java.io.IOException; | |
15 import java.io.OutputStream; | |
16 | |
17 import java.util.ArrayList; | |
3 import java.util.HashMap; | 18 import java.util.HashMap; |
4 import java.util.HashSet; | 19 import java.util.HashSet; |
5 import java.util.ArrayList; | |
6 import java.util.List; | 20 import java.util.List; |
7 | 21 |
8 import de.intevation.artifacts.ArtifactDatabaseException; | |
9 import de.intevation.artifacts.ArtifactDatabase; | |
10 import de.intevation.artifacts.ArtifactFactory; | |
11 import de.intevation.artifacts.Artifact; | |
12 import de.intevation.artifacts.CallContext; | |
13 import de.intevation.artifacts.CallMeta; | |
14 | |
15 import de.intevation.artifactdatabase.Backend.PersistentArtifact; | |
16 | |
17 import org.apache.log4j.Logger; | 22 import org.apache.log4j.Logger; |
18 | 23 |
19 import org.w3c.dom.Document; | 24 import org.w3c.dom.Document; |
20 | |
21 import java.io.OutputStream; | |
22 import java.io.IOException; | |
23 | 25 |
24 /** | 26 /** |
25 * @author Sascha L. Teichmann | 27 * @author Sascha L. Teichmann |
26 */ | 28 */ |
27 public class ArtifactDatabaseImpl | 29 public class ArtifactDatabaseImpl |
45 public static final String CREATION_FAILED = | 47 public static final String CREATION_FAILED = |
46 "Creation of artifact failed"; | 48 "Creation of artifact failed"; |
47 | 49 |
48 public static final String INTERNAL_ERROR = | 50 public static final String INTERNAL_ERROR = |
49 "Creation of artifact failed"; | 51 "Creation of artifact failed"; |
52 | |
53 public static final String NO_SUCH_SERVICE = | |
54 "No such service"; | |
50 | 55 |
51 public class CallContextImpl | 56 public class CallContextImpl |
52 implements CallContext | 57 implements CallContext |
53 { | 58 { |
54 protected PersistentArtifact artifact; | 59 protected PersistentArtifact artifact; |
161 } // class DeferredOutputImpl | 166 } // class DeferredOutputImpl |
162 | 167 |
163 protected String [][] factoryNamesAndDescription; | 168 protected String [][] factoryNamesAndDescription; |
164 protected HashMap name2factory; | 169 protected HashMap name2factory; |
165 | 170 |
171 protected String [][] serviceNamesAndDescription; | |
172 protected HashMap name2service; | |
173 | |
166 protected Backend backend; | 174 protected Backend backend; |
167 protected Object context; | 175 protected Object context; |
168 | 176 |
169 protected HashSet backgroundIds; | 177 protected HashSet backgroundIds; |
170 | 178 |
176 } | 184 } |
177 | 185 |
178 public ArtifactDatabaseImpl(FactoryBootstrap bootstrap, Backend backend) { | 186 public ArtifactDatabaseImpl(FactoryBootstrap bootstrap, Backend backend) { |
179 | 187 |
180 backgroundIds = new HashSet(); | 188 backgroundIds = new HashSet(); |
189 | |
190 setupArtifactFactories(bootstrap); | |
191 setupServices(bootstrap); | |
192 | |
193 context = bootstrap.getContext(); | |
194 | |
195 wireWithBackend(backend); | |
196 } | |
197 | |
198 protected void setupArtifactFactories(FactoryBootstrap bootstrap) { | |
181 name2factory = new HashMap(); | 199 name2factory = new HashMap(); |
182 | 200 |
183 ArtifactFactory [] factories = bootstrap.getArtifactFactories(); | 201 ArtifactFactory [] factories = bootstrap.getArtifactFactories(); |
184 factoryNamesAndDescription = new String[factories.length][]; | 202 factoryNamesAndDescription = new String[factories.length][]; |
185 | 203 |
193 factoryNamesAndDescription[i] = | 211 factoryNamesAndDescription[i] = |
194 new String [] { name, description }; | 212 new String [] { name, description }; |
195 | 213 |
196 name2factory.put(name, factory); | 214 name2factory.put(name, factory); |
197 } | 215 } |
198 | 216 } |
199 context = bootstrap.getContext(); | 217 |
200 | 218 protected void setupServices(FactoryBootstrap bootstrap) { |
201 wireWithBackend(backend); | 219 |
220 name2service = new HashMap(); | |
221 | |
222 ServiceFactory [] serviceFactories = | |
223 bootstrap.getServiceFactories(); | |
224 | |
225 serviceNamesAndDescription = | |
226 new String[serviceFactories.length][]; | |
227 | |
228 for (int i = 0; i < serviceFactories.length; ++i) { | |
229 ServiceFactory factory = serviceFactories[i]; | |
230 | |
231 String name = factory.getName(); | |
232 String description = factory.getDescription(); | |
233 | |
234 serviceNamesAndDescription[i] = | |
235 new String [] { name, description }; | |
236 | |
237 name2service.put( | |
238 name, | |
239 factory.createService(bootstrap.getContext())); | |
240 } | |
241 | |
202 } | 242 } |
203 | 243 |
204 public void wireWithBackend(Backend backend) { | 244 public void wireWithBackend(Backend backend) { |
205 if (backend != null) { | 245 if (backend != null) { |
206 this.backend = backend; | 246 this.backend = backend; |
382 | 422 |
383 return new DeferredOutputImpl(artifact, format, callMeta); | 423 return new DeferredOutputImpl(artifact, format, callMeta); |
384 } | 424 } |
385 | 425 |
386 public String [][] serviceNamesAndDescriptions() { | 426 public String [][] serviceNamesAndDescriptions() { |
387 throw new IllegalArgumentException("Describing services is not implemented yet"); | 427 return serviceNamesAndDescription; |
388 } | 428 } |
389 | 429 |
390 public Document process(String service, Document input, CallMeta callMeta) { | 430 public Document process( |
391 throw new IllegalArgumentException("Service processing is not implemented yet"); | 431 String serviceName, |
432 Document input, | |
433 CallMeta callMeta | |
434 ) | |
435 throws ArtifactDatabaseException | |
436 { | |
437 Service service = (Service)name2service.get(serviceName); | |
438 | |
439 if (service == null) { | |
440 throw new ArtifactDatabaseException(NO_SUCH_SERVICE); | |
441 } | |
442 | |
443 return service.process(input, context, callMeta); | |
392 } | 444 } |
393 } | 445 } |
394 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: | 446 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |