view artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 24:d5dc2900392f

* Added callback parameter to Artifact.setup() * New namespace context for artifacts. artifacts/trunk@58 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 10 Sep 2009 08:57:09 +0000
parents 0d6badf6af42
children 83a059c204f8
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();
    }

    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