view flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java @ 227:7f7f6d2c4b2c

We can now distinuish between different artifact types based on its name in the DESCRIBE. The ArtifactCreator returns concrete instances of Artifacts now. flys-client/trunk@1673 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 12 Apr 2011 13:46:33 +0000
parents f8a5f2c5e2b7
children c9549074ecd1
line wrap: on
line source
package de.intevation.flys.client.server;

import org.w3c.dom.Document;

import de.intevation.artifacts.common.utils.XMLUtils;
import de.intevation.artifacts.common.ArtifactNamespaceContext;

import de.intevation.artifacts.httpclient.utils.ArtifactCreator;

import de.intevation.flys.client.shared.model.Artifact;
import de.intevation.flys.client.shared.model.DefaultArtifact;
import de.intevation.flys.client.shared.model.WINFOArtifact;


/**
 * An implementation of an {@link ArtifactCreator}. This class uses the document
 * that is returned by the artifact server to parse important information (like
 * uuid, hash) and returns a new {@link Artifact} instance.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class FLYSArtifactCreator implements ArtifactCreator {

    /** The XPath to the artifact's uuid.*/
    public static final String XPATH_UUID = "/art:result/art:uuid/@art:value";

    /** The XPath to the artifact's hash value.*/
    public static final String XPATH_HASH = "/art:result/art:hash/@art:value";

    /** The XPath to the artifact's name value.*/
    public static final String XPATH_NAME = "/art:result/art:name/@art:value";


    /**
     * Creates a new instance of an {@link ArtifactCreator}.
     */
    public FLYSArtifactCreator() {
    }


    /**
     * This concreate implementation returns an instance of {@link Artifact}
     * that is used in the FLYS GWT Client code.
     *
     * @param doc A document that describes the artifact that has been created
     * in the artifact server.
     *
     * @return an instance if {@link Artifact}.
     */
    public Object create(Document doc) {
        Artifact artifact = extractArtifact(doc);
        artifact.setArtifactDescription(
            ArtifactDescriptionFactory.createArtifactDescription(doc));

        return artifact;
    }


    /**
     * This method extracts the UUID und HASH information of the returned
     * artifact document.
     *
     * @param doc The result of the CREATE operation.
     *
     * @return an instance of an {@link Artifact}.
     */
    protected Artifact extractArtifact(Document doc) {
        System.out.println("FLYSArtifactCreator - extractArtifact()");

        String uuid = XMLUtils.xpathString(
            doc, XPATH_UUID, ArtifactNamespaceContext.INSTANCE);

        String hash = XMLUtils.xpathString(
            doc, XPATH_HASH, ArtifactNamespaceContext.INSTANCE);

        String name = XMLUtils.xpathString(
            doc, XPATH_NAME, ArtifactNamespaceContext.INSTANCE);

        System.out.println("NEW Artifact UUID: " + uuid);
        System.out.println("NEW Artifact HASH: " + hash);
        System.out.println("NEW Artifact NAME: " + name);

        if (name == null) {
            return new DefaultArtifact(uuid, hash);
        }

        name = name.trim();

        if (name.length() > 0 && name.equals("winfo")) {
            System.out.println("+++++ NEW WINFO ARTIFACT.");
            return new WINFOArtifact(uuid, hash);
        }

        return new DefaultArtifact(uuid, hash);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org