sascha@58: package de.intevation.artifactdatabase; sascha@58: sascha@58: import org.w3c.dom.Document; sascha@58: sascha@58: import de.intevation.artifacts.Artifact; sascha@58: import de.intevation.artifacts.CallContext; sascha@58: import de.intevation.artifacts.ArtifactFactory; sascha@58: sascha@58: import org.apache.log4j.Logger; sascha@58: sascha@58: import java.io.IOException; sascha@58: import java.io.OutputStream; sascha@58: sascha@58: /** sascha@58: * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) sascha@58: */ sascha@58: public class ProxyArtifact sascha@58: extends DefaultArtifact sascha@58: { sascha@58: public static final Object REPLACE_PROXY = new Object(); sascha@58: sascha@58: private static Logger logger = Logger.getLogger(ProxyArtifact.class); sascha@58: sascha@58: protected Artifact proxied; sascha@58: sascha@58: public ProxyArtifact() { sascha@58: } sascha@58: sascha@58: public ProxyArtifact(Artifact proxied) { sascha@58: this.proxied = proxied; sascha@58: } sascha@58: sascha@58: public Artifact getProxied() { sascha@58: return proxied; sascha@58: } sascha@58: sascha@58: public void setProxied(Artifact proxied) { sascha@58: this.proxied = proxied; sascha@58: } sascha@58: sascha@58: protected void checkReplacement(CallContext callContext) { sascha@58: Object replacement = callContext.getContextValue(REPLACE_PROXY); sascha@58: if (replacement instanceof Artifact) { sascha@58: setProxied((Artifact)replacement); sascha@58: } sascha@58: } sascha@58: sascha@58: public String hash() { sascha@58: return proxied != null sascha@58: ? proxied.hash() sascha@58: : super.hash(); sascha@58: } sascha@58: sascha@58: public Document describe(Document data, CallContext context) { sascha@58: try { sascha@58: return proxied != null sascha@58: ? proxied.describe(data, context) sascha@58: : super.describe(data, context); sascha@58: } sascha@58: finally { sascha@58: checkReplacement(context); sascha@58: } sascha@58: } sascha@58: sascha@58: public Document advance(Document target, CallContext context) { sascha@58: try { sascha@58: return proxied != null sascha@58: ? proxied.advance(target, context) sascha@58: : super.advance(target, context); sascha@58: } sascha@58: finally { sascha@58: checkReplacement(context); sascha@58: } sascha@58: } sascha@58: sascha@58: public Document feed(Document target, CallContext context) { sascha@58: try { sascha@58: return proxied != null sascha@58: ? proxied.feed(target, context) sascha@58: : super.feed(target, context); sascha@58: } sascha@58: finally { sascha@58: checkReplacement(context); sascha@58: } sascha@58: } sascha@58: sascha@58: public void out( sascha@58: Document format, sascha@58: OutputStream out, sascha@58: CallContext context sascha@58: ) sascha@58: throws IOException sascha@58: { sascha@58: try { sascha@58: if (proxied != null) { sascha@58: proxied.out(format, out, context); sascha@58: } sascha@58: else { sascha@58: super.out(format, out, context); sascha@58: } sascha@58: } sascha@58: finally { sascha@58: checkReplacement(context); sascha@58: } sascha@58: } sascha@58: sascha@58: public void endOfLife(Object context) { sascha@58: if (proxied != null) { sascha@58: proxied.endOfLife(context); sascha@58: } sascha@58: else { sascha@58: super.endOfLife(context); sascha@58: } sascha@58: } sascha@58: } sascha@58: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: