Mercurial > dive4elements > framework
changeset 228:dd977fb7552e
Added an implementation of DeferredOutput for ArtifactCollections and implemented the out() operation of ArtifactCollections.
artifacts/trunk@1630 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 31 Mar 2011 08:42:53 +0000 |
parents | 4bb6bfaca393 |
children | 328ef982d768 |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java |
diffstat | 2 files changed, 98 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Mar 30 15:19:08 2011 +0000 +++ b/ChangeLog Thu Mar 31 08:42:53 2011 +0000 @@ -1,3 +1,9 @@ +2011-03-31 Ingo Weinzierl <ingo@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java: + Added an implementation of DeferredOutput for ArtifactCollections and + implemented the out() operation of an ArtifactCollection. + 2011-03-30 Ingo Weinzierl <ingo@intevation.de> * artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Wed Mar 30 15:19:08 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Thu Mar 31 08:42:53 2011 +0000 @@ -284,6 +284,69 @@ } } // class DeferredOutputImpl + + /** + * This inner class allows the deferral of writing the output + * of the artifact's out() call. + */ + public class DeferredCollectionOutputImpl + implements DeferredOutput + { + /** + * The persistence wrapper around a living collection. + */ + protected ArtifactCollection collection; + /** + * The input document for the collection's out() call. + */ + protected Document format; + /** + * The meta information of the collection's out() call. + */ + protected CallMeta callMeta; + + /** + * Default constructor. + */ + public DeferredCollectionOutputImpl() { + } + + /** + * Constructor to create a deferred execution unit for + * the collection's out() call given a collection, an input document + * an the meta information. + * @param collection The collection. + * @param format The input document for the collection's out() call. + * @param callMeta The meta information of the collection's out() call. + */ + public DeferredCollectionOutputImpl( + ArtifactCollection collection, + Document format, + CallMeta callMeta + ) { + this.collection = collection; + this.format = format; + this.callMeta = callMeta; + } + + public void write(OutputStream output) throws IOException { + + CollectionCallContext cc = new CollectionCallContext( + ArtifactDatabaseImpl.this, + CallContext.TOUCH, + callMeta, + context, + collection); + + try { + collection.out(format, output, cc); + } + finally { + cc.postCall(); + } + } + } // class DeferredCollectionOutputImpl + /** * List of name/description pairs needed for * {@link #artifactFactoryNamesAndDescriptions() }. @@ -1354,8 +1417,35 @@ public DeferredOutput outCollection(String collectionId, Document format, CallMeta callMeta) - throws ArtifactDatabaseException{ - throw new ArtifactDatabaseException("Not implemented, yet!"); + throws ArtifactDatabaseException + { + ArtifactCollectionFactory acf = getArtifactCollectionFactory(); + + if (acf == null) { + throw new ArtifactDatabaseException(NO_SUCH_FACTORY); + } + + UserFactory uf = getUserFactory(); + if (uf == null) { + throw new ArtifactDatabaseException(NO_SUCH_FACTORY); + } + + ArtifactCollection c = backend.getCollection( + collectionId, acf, uf, context); + + if (c == null) { + logger.warn("No collection found with identifier: " + collectionId); + throw new ArtifactDatabaseException(NO_SUCH_COLLECTION); + } + + CallContext cc = new CollectionCallContext( + ArtifactDatabaseImpl.this, + CallContext.NOTHING, + callMeta, + context, + c); + + return new DeferredCollectionOutputImpl(c, format, callMeta); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :