Mercurial > dive4elements > framework
changeset 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 | 70cbbe144931 |
children | ecfc33a4ba3d |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactCallContext.java artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/CollectionCallContext.java |
diffstat | 5 files changed, 356 insertions(+), 142 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Mar 24 15:48:26 2011 +0000 +++ b/ChangeLog Thu Mar 24 16:16:51 2011 +0000 @@ -1,3 +1,18 @@ +2011-03-24 Ingo Weinzierl <ingo@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java: + Removed the inner CallContextImpl class. This class is split up into an + abstract class AbstractCallContext and concrete classes for artifacts + and collections. We need to do so, because the describe() of an + ArtifactCollection needs the CallContext - but the former + CallContextImpl was specific for artifacts. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/CollectionCallContext.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactCallContext.java: + An abstract CallContext and two concrete implementations for Artifacts + and ArtifactCollections. + 2011-03-24 Ingo Weinzierl <ingo@intevation.de> * artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactCollection.java,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java Thu Mar 24 16:16:51 2011 +0000 @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.artifactdatabase; + +import java.util.HashMap; + +import de.intevation.artifacts.ArtifactDatabase; +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; + + +/** + * Abstract class that implements some basic methods of a CallContext. + * + * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public abstract class AbstractCallContext implements CallContext { + + /** + * The ArtifactDatabase instance. + */ + protected ArtifactDatabaseImpl database; + + /** + * The action to be performed after the artifacts or collections calls. + */ + protected int action; + + /** + * The meta information of the concrete call (preferred languages et. al.) + */ + protected CallMeta callMeta; + + /** + * The global context. + */ + protected Object context; + + /** + * Map to act like a clipboard when nesting calls like a proxy artifact. + */ + protected HashMap customValues; + + + /** + * The default constructor of this abstract CallContext. + * + * @param action The action. + * @param callMeta The CallMeta object. + * @param context The global context. + */ + public AbstractCallContext( + ArtifactDatabaseImpl artifactDatabase, + int action, + CallMeta callMeta, + Object context) + { + this.database = artifactDatabase; + this.action = action; + this.callMeta = callMeta; + this.context = context; + } + + + public abstract void postCall(); + + public abstract void afterCall(int action); + + public abstract Long getTimeToLive(); + + public abstract void afterBackground(int action); + + + public Object globalContext() { + return context; + } + + + public ArtifactDatabase getDatabase() { + return database; + } + + + public CallMeta getMeta() { + return callMeta; + } + + + public Object getContextValue(Object key) { + return customValues != null + ? customValues.get(key) + : null; + } + + public Object putContextValue(Object key, Object value) { + if (customValues == null) { + customValues = new HashMap(); + } + return customValues.put(key, value); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactCallContext.java Thu Mar 24 16:16:51 2011 +0000 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.artifactdatabase; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.CallMeta; + +import de.intevation.artifactdatabase.Backend.PersistentArtifact; + + +/** + * Class that implements the call context handed to the methods calls + * describe(), feed(), etc. of the artifact. + * + * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> + */ +public class ArtifactCallContext extends AbstractCallContext { + + private static Logger logger = Logger.getLogger(ArtifactCallContext.class); + + + /** + * Error message issued if an artifact wants to translate itself + * into a none valid persistent state. + */ + public static final String INVALID_CALL_STATE = "Invalid after call state"; + + /** + * Error message issued if one tries to remove a requested artifact + * from the list of artifacts running in background which is + * not in this list. + */ + public static final String NOT_IN_BACKGROUND = "Not in background"; + + + /** + * The persistence wrapper around the living artifact + */ + protected PersistentArtifact artifact; + + + public ArtifactCallContext( + ArtifactDatabaseImpl artifactDatabase, + int action, + CallMeta callMeta, + Object context, + PersistentArtifact artifact) + { + super(artifactDatabase, action, callMeta, context); + + this.artifact = artifact; + } + + + public void afterCall(int action) { + this.action = action; + if (action == BACKGROUND) { + database.addIdToBackground(artifact.getId()); + } + } + + + public void afterBackground(int action) { + if (this.action != BACKGROUND) { + throw new IllegalStateException(NOT_IN_BACKGROUND); + } + database.fromBackground(artifact, action); + } + + + public Long getTimeToLive() { + return artifact.getTTL(); + } + + + /** + * Dispatches and executes the persistence action after + * the return of the concrete artifact call. + */ + public void postCall() { + switch (action) { + case NOTHING: + break; + case TOUCH: + artifact.touch(); + break; + case STORE: + artifact.store(); + break; + case BACKGROUND: + logger.warn( + "BACKGROUND processing is not fully implemented, yet!"); + artifact.store(); + break; + default: + logger.error(INVALID_CALL_STATE + ": " + action); + throw new IllegalStateException(INVALID_CALL_STATE); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Thu Mar 24 15:48:26 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Thu Mar 24 16:16:51 2011 +0000 @@ -88,21 +88,6 @@ "No such artifact"; /** - * Error message issued if one tries to remove a requested artifact - * from the list of artifacts running in background which is - * not in this list. - */ - public static final String NOT_IN_BACKGROUND = - "Not in background"; - - /** - * Error message issued if an artifact wants to translate itself - * into a none valid persistent state. - */ - public static final String INVALID_CALL_STATE = - "Invalid after call state"; - - /** * Error message issued if the creation of an artifact failed. */ public static final String CREATION_FAILED = @@ -231,120 +216,6 @@ /** - * Inner class that implements the call context handed - * to the methods calls describe(), feed(), etc. of the artifact. - */ - public class CallContextImpl - implements CallContext - { - /** - * The persistence wrapper around the living artifact - */ - protected PersistentArtifact artifact; - /** - * The action to be performed after the artifact calls - * desribe(), feed(), etc. return. - */ - protected int action; - /** - * The meta information of the concrete call - * (preferred languages et. al.) - */ - protected CallMeta callMeta; - /** - * Map to act like a clipboard when nesting calls - * like a proxy artifact. - */ - protected HashMap customValues; - - /** - * Constructor to create a call context with a given - * persistent artifact, a default action and meta informations. - * @param artifact The persistent wrapper around a living artifact. - * @param action The action to be performed after the concrete - * artifact call has returned. - * @param callMeta The meta information for this call context. - */ - public CallContextImpl( - PersistentArtifact artifact, - int action, - CallMeta callMeta - ) { - this.artifact = artifact; - this.action = action; - this.callMeta = callMeta; - } - - public void afterCall(int action) { - this.action = action; - if (action == BACKGROUND) { - addIdToBackground(artifact.getId()); - } - } - - public void afterBackground(int action) { - if (this.action != BACKGROUND) { - throw new IllegalStateException(NOT_IN_BACKGROUND); - } - fromBackground(artifact, action); - } - - public Object globalContext() { - return context; - } - - public ArtifactDatabase getDatabase() { - return ArtifactDatabaseImpl.this; - } - - public CallMeta getMeta() { - return callMeta; - } - - public Long getTimeToLive() { - return artifact.getTTL(); - } - - /** - * Dispatches and executes the persistence action after - * the return of the concrete artifact call. - */ - public void postCall() { - switch (action) { - case NOTHING: - break; - case TOUCH: - artifact.touch(); - break; - case STORE: - artifact.store(); - break; - case BACKGROUND: - logger.warn( - "BACKGROUND processing is not fully implemented, yet!"); - artifact.store(); - break; - default: - logger.error(INVALID_CALL_STATE + ": " + action); - throw new IllegalStateException(INVALID_CALL_STATE); - } - } - - public Object getContextValue(Object key) { - return customValues != null - ? customValues.get(key) - : null; - } - - public Object putContextValue(Object key, Object value) { - if (customValues == null) { - customValues = new HashMap(); - } - return customValues.put(key, value); - } - } // class CallContextImpl - - /** * This inner class allows the deferral of writing the output * of the artifact's out() call. */ @@ -390,8 +261,12 @@ public void write(OutputStream output) throws IOException { - CallContextImpl cc = new CallContextImpl( - artifact, CallContext.TOUCH, callMeta); + ArtifactCallContext cc = new ArtifactCallContext( + ArtifactDatabaseImpl.this, + CallContext.TOUCH, + callMeta, + context, + artifact); try { artifact.getArtifact().out(format, output, cc); @@ -697,8 +572,12 @@ throw new ArtifactDatabaseException(CREATION_FAILED); } - CallContextImpl cc = new CallContextImpl( - persistentArtifact, CallContext.NOTHING, callMeta); + ArtifactCallContext cc = new ArtifactCallContext( + ArtifactDatabaseImpl.this, + CallContext.NOTHING, + callMeta, + context, + persistentArtifact); try { return artifact.describe(null, cc); @@ -722,8 +601,12 @@ throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); } - CallContextImpl cc = new CallContextImpl( - artifact, CallContext.TOUCH, callMeta); + ArtifactCallContext cc = new ArtifactCallContext( + ArtifactDatabaseImpl.this, + CallContext.TOUCH, + callMeta, + context, + artifact); try { return artifact.getArtifact().describe(data, cc); @@ -747,8 +630,12 @@ throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); } - CallContextImpl cc = new CallContextImpl( - artifact, CallContext.STORE, callMeta); + ArtifactCallContext cc = new ArtifactCallContext( + ArtifactDatabaseImpl.this, + CallContext.STORE, + callMeta, + context, + artifact); try { return artifact.getArtifact().advance(target, cc); @@ -768,8 +655,12 @@ throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT); } - CallContextImpl cc = new CallContextImpl( - artifact, CallContext.STORE, callMeta); + ArtifactCallContext cc = new ArtifactCallContext( + ArtifactDatabaseImpl.this, + CallContext.STORE, + callMeta, + context, + artifact); try { return artifact.getArtifact().feed(data, cc); @@ -969,8 +860,12 @@ throw new ArtifactDatabaseException(CREATION_FAILED); } - CallContextImpl cc = new CallContextImpl( - persistentArtifact, CallContext.NOTHING, callMeta); + ArtifactCallContext cc = new ArtifactCallContext( + ArtifactDatabaseImpl.this, + CallContext.NOTHING, + callMeta, + context, + persistentArtifact); try { return artifact.describe(input, cc); @@ -1263,8 +1158,32 @@ throws ArtifactDatabaseException { logger.debug("Describe collection: " + collectionId); + ArtifactCollectionFactory acf = getArtifactCollectionFactory(); - throw new ArtifactDatabaseException("Not implemented yet."); + 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); + } + + CallContext cc = new CollectionCallContext( + ArtifactDatabaseImpl.this, + CallContext.NOTHING, + callMeta, + context, + c); + + return c.describe(cc); } public Document getCollectionAttribute(String collectionId, String artifactId,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/CollectionCallContext.java Thu Mar 24 16:16:51 2011 +0000 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.artifactdatabase; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.ArtifactCollection; +import de.intevation.artifacts.CallMeta; + + +/** + * Class that implements the call context handed to ArtifactCollection specific + * operations. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class CollectionCallContext extends AbstractCallContext { + + private static Logger log = Logger.getLogger(CollectionCallContext.class); + + /** + * The ArtifactCollection. + */ + protected ArtifactCollection collection; + + + public CollectionCallContext( + ArtifactDatabaseImpl artifactDatabase, + int action, + CallMeta callMeta, + Object context, + ArtifactCollection collection) + { + super(artifactDatabase, action, callMeta, context); + + this.collection = collection; + } + + + public void afterCall(int action) { + log.debug("CollectionCallContext.afterCall - NOT IMPLEMENTED"); + } + + + public void afterBackground(int action) { + log.debug("CollectionCallContext.afterBackground - NOT IMPLEMENTED"); + } + + + public Long getTimeToLive() { + log.debug("CollectionCallContext.getTimeToLive - NOT IMPLEMENTED"); + return null; + } + + + public void postCall() { + log.debug("CollectionCallContext.postCall - NOT IMPLEMENTED"); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :