view artifact-database/src/main/java/de/intevation/artifactdatabase/ProxyArtifact.java @ 67:ed03cc0e5800

Added method to XMLUtils to copy an XML document to an output stream. artifacts/trunk@553 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 17 Jan 2010 14:00:06 +0000
parents 85d996328c8a
children 48d1a9a082c2
line wrap: on
line source
package de.intevation.artifactdatabase;

import org.w3c.dom.Document;

import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.CallContext;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.OutputStream;

/**
 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
 */
public class ProxyArtifact
extends      DefaultArtifact
{
    public static final Object REPLACE_PROXY = new Object();

    private static Logger logger = Logger.getLogger(ProxyArtifact.class);

    protected Artifact proxied;

    public ProxyArtifact() {
    }

    public ProxyArtifact(Artifact proxied) {
        this.proxied = proxied;
    }

    public Artifact getProxied() {
        return proxied;
    }

    public void setProxied(Artifact proxied) {
        this.proxied = proxied;
    }

    protected void checkReplacement(CallContext callContext) {
        Object replacement = callContext.getContextValue(REPLACE_PROXY);
        if (replacement instanceof Artifact) {
            setProxied((Artifact)replacement);
        }
    }

    public String hash() {
        return proxied != null
            ? proxied.hash()
            : super.hash();
    }

    public Document describe(Document data, CallContext context) {
        try {
            return proxied != null
                ? proxied.describe(data, context)
                : super.describe(data, context);
        }
        finally {
            checkReplacement(context);
        }
    }

    public Document advance(Document target, CallContext context) {
        try {
            return proxied != null
                ? proxied.advance(target, context)
                : super.advance(target, context);
        }
        finally {
            checkReplacement(context);
        }
    }

    public Document feed(Document target, CallContext context) {
        try {
            return proxied != null 
                ? proxied.feed(target, context)
                : super.feed(target, context);
        }
        finally {
            checkReplacement(context);
        }
    }

    public void out(
        Document     format,
        OutputStream out,
        CallContext  context
    )
    throws IOException
    {
        try {
            if (proxied != null) {
                proxied.out(format, out, context);
            }
            else {
                super.out(format, out, context);
            }
        }
        finally {
            checkReplacement(context);
        }
    }

    public void endOfLife(Object context) {
        if (proxied != null) {
            proxied.endOfLife(context);
        }
        else {
            super.endOfLife(context);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org