view flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java @ 16:f8a5f2c5e2b7

The DESCRIBE document returned by the artifact server is parsed after calling create() of the artifact service and a new Artifact is created with an ArtifactDescription that contains the UUID, HASH, und the current Data. flys-client/trunk@1329 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 18 Feb 2011 14:23:12 +0000
parents fe2f4d1dd784
children 7f7f6d2c4b2c
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;


/**
 * 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";


    /**
     * 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);

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

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

http://dive4elements.wald.intevation.org