ingo@100: /* ingo@100: * Copyright (c) 2010 by Intevation GmbH ingo@100: * ingo@100: * This program is free software under the LGPL (>=v2.1) ingo@100: * Read the file LGPL.txt coming with the software for details ingo@100: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@100: */ ingo@100: sascha@5: package de.intevation.artifactdatabase; sascha@5: sascha@5: import java.util.HashMap; sascha@5: sascha@5: import org.w3c.dom.Document; sascha@5: sascha@5: /** sascha@5: * Default implementation of the context. sascha@5: * Besides of the configuration it hosts a map to store key/value pairs. sascha@5: * sascha@77: * @author Sascha L. Teichmann sascha@5: */ sascha@5: public class DefaultArtifactContext sascha@5: { sascha@90: /** sascha@90: * The global configuration document of the artifact database. sascha@90: */ sascha@5: protected Document config; sascha@5: sascha@90: /** sascha@90: * Custom key/value pairs to be used globally in the whole server. sascha@90: */ sascha@5: protected HashMap map; sascha@5: sascha@90: /** sascha@90: * Default constructor sascha@90: */ sascha@5: public DefaultArtifactContext() { sascha@5: this(null); sascha@5: } sascha@5: sascha@90: /** sascha@90: * Constructor to create a context with a given global sascha@90: * configuration document and an empty map of custom sascha@90: * key/value pairs. sascha@90: * @param config sascha@90: */ sascha@5: public DefaultArtifactContext(Document config) { sascha@5: this.config = config; sascha@5: map = new HashMap(); sascha@5: } sascha@5: sascha@90: /** sascha@90: * Fetch a custom value from the global key/value map using sascha@90: * a given key. sascha@90: * @param key The key. sascha@90: * @return The stored value or null if no value was found under sascha@90: * this key. sascha@90: */ sascha@5: public synchronized Object get(Object key) { sascha@5: return map.get(key); sascha@5: } sascha@5: sascha@90: /** sascha@90: * Store a custom key/value pair in the global map. sascha@90: * @param key The key to store sascha@90: * @param value The value to store sascha@90: * @return The old value registered under the key or null sascha@90: * if none wa there before. sascha@90: */ sascha@5: public synchronized Object put(Object key, Object value) { sascha@5: return map.put(key, value); sascha@5: } sascha@5: sascha@90: /** sascha@90: * Returns a reference to the global configuration document. sascha@90: * @return The global configuration document. sascha@90: */ sascha@5: public Document getConfig() { sascha@5: return config; sascha@5: } sascha@5: } sascha@90: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :