001    // This file is part of AceWiki.
002    // Copyright 2011, AceWiki developers.
003    //
004    // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005    // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006    // the License, or (at your option) any later version.
007    //
008    // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009    // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010    // Lesser General Public License for more details.
011    //
012    // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013    // not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.acewiki;
016    
017    import java.util.Map;
018    
019    import ch.uzh.ifi.attempto.acewiki.core.AceWikiStorage;
020    import ch.uzh.ifi.attempto.acewiki.core.FileBasedStorage;
021    import ch.uzh.ifi.attempto.acewiki.core.Ontology;
022    
023    /**
024     * This class is used as the backend of an AceWiki.
025     * It contains the ontology for the AceWiki and the parameters.
026     *
027     * @author Yu Changyuan
028     */
029    public class Backend {
030        private final Ontology ontology;
031        private static AceWikiStorage storage;
032        private final Map<String, String> parameters;
033    
034        /**
035         * Creates a new Backend instance for the given parameters.
036         *
037         * @param parameters The parameters for the AceWiki Backend.
038         */
039        public Backend(Map<String, String> parameters) {
040            this.parameters = parameters;
041            if (storage == null) {
042                storage = new FileBasedStorage(parameters.get("context:datadir"));
043            }
044            ontology = getStorage().getOntology(parameters.get("ontology"), parameters);
045        }
046    
047        /**
048         * Get the storage associated with this backend.
049         *
050         * @return The AceWikiStorage instance.
051         */
052        public AceWikiStorage getStorage() {
053            return storage;
054        }
055    
056        /**
057         * Get the Ontology instance for this Backend.
058         *
059         * @return The Ontology object.
060         */
061        public Ontology getOntology() {
062            return ontology;
063        }
064    
065        /**
066         * Get the parameters of this Backend.
067         *
068         * @return The parameters.
069         */
070        public Map<String, String> getParameters() {
071            return parameters;
072        }
073    
074        /**
075         * Get a specific parameter for this Backend.
076         *
077         * @param param The parameter name.
078         * @return The value of the parameter, or null if the parameter does not exist.
079         */
080        public String getParameter(String param) {
081            return parameters.get(param);
082        }
083    }