# HG changeset patch # User Ingo Weinzierl # Date 1301560973 0 # Node ID dd977fb7552e9b42208cbb8ef120c91875f109cf # Parent 4bb6bfaca393c9acc1aac9f446e8f1b97f692568 Added an implementation of DeferredOutput for ArtifactCollections and implemented the out() operation of ArtifactCollections. artifacts/trunk@1630 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4bb6bfaca393 -r dd977fb7552e ChangeLog --- 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 + + * 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 * artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java: diff -r 4bb6bfaca393 -r dd977fb7552e artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.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 :