view artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 27:75bdaf900473

Added REST handler for 'describe'. artifacts/trunk@64 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 10 Sep 2009 14:21:58 +0000
parents 83a059c204f8
children c2d53bd30ab8
line wrap: on
line source
package de.intevation.artifactdatabase;

import java.util.HashMap;

import de.intevation.artifacts.ArtifactDatabase;
import de.intevation.artifacts.ArtifactFactory;
import de.intevation.artifacts.Artifact;

/**
 *  @author Sascha L. Teichmann
 */
public class ArtifactDatabaseImpl
implements   ArtifactDatabase
{
    protected String [] factoryNames;
    protected HashMap   name2factory;

    protected Backend   backend;
    protected Object    context;

    public ArtifactDatabaseImpl() {
    }

    public ArtifactDatabaseImpl(FactoryBootstrap bootstrap, Backend backend) {
        name2factory = new HashMap();

        ArtifactFactory [] factories = bootstrap.getArtifactFactories();
        factoryNames = new String[factories.length];

        for (int i = 0; i < factories.length; ++i) {
            ArtifactFactory factory = factories[i];
            name2factory.put(factoryNames[i] = factory.getName(), factory);
        }

        context = bootstrap.getContext();

        this.backend = backend;
    }

    public String [] getArtifactFactoryNames() {
        return factoryNames;
    }

    public Artifact getArtifact(String identifier) {
        return backend.getArtifact(identifier);
    }

    public Artifact createArtifactWithFactory(String factoryName) {
        ArtifactFactory factory = (ArtifactFactory)name2factory.get(factoryName);
        return  factory == null
            ? null
            : backend.createArtifactWithFactory(factory, context);
    }

    public Object getArtifactContext() {
        return context;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org