001    /*
002     * 
003     * $Revision$ $Date$
004     *
005     * This file is part of ***  M y C o R e  ***
006     * See http://www.mycore.de/ for details.
007     *
008     * This program is free software; you can use it, redistribute it
009     * and / or modify it under the terms of the GNU General Public License
010     * (GPL) as published by the Free Software Foundation; either version 2
011     * of the License or (at your option) any later version.
012     *
013     * This program is distributed in the hope that it will be useful, but
014     * WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program, in a file called gpl.txt or license.txt.
020     * If not, write to the Free Software Foundation Inc.,
021     * 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
022     */
023    
024    package org.mycore.access.mcrimpl;
025    
026    import java.util.Collection;
027    
028    import org.apache.log4j.Logger;
029    import org.mycore.common.MCRConfiguration;
030    
031    /**
032     * The purpose of this interface is to make the choice of the persistence layer
033     * configurable. Any concrete database-class which stores MyCoRe Access control
034     * must implement this interface. Which database actually will be used can then
035     * be configured by reading the value <code>MCR.Persistence.Rule.Store_Class</code>
036     * from mycore.properties.access
037     * 
038     * @author Arne Seifert
039     */
040    public abstract class MCRRuleStore {
041        public abstract void createRule(MCRAccessRule rule);
042    
043        public abstract void updateRule(MCRAccessRule rule);
044    
045        public abstract void deleteRule(String ruleid);
046    
047        public abstract MCRAccessRule getRule(String ruleid);
048    
049        public abstract boolean existsRule(String ruleid);
050        
051        public abstract Collection<String> retrieveAllIDs();
052        
053        public abstract Collection<String> retrieveRuleIDs(String ruleExpression, String description);
054        
055        public abstract int getNextFreeRuleID(String prefix);
056    
057        public abstract MCRAccessRule retrieveRule(String ruleid);
058    
059        public static Logger logger = Logger.getLogger(MCRRuleStore.class.getName());
060    
061        final protected static String sqlDateformat = "yyyy-MM-dd HH:mm:ss";
062    
063        final protected static String ruletablename = MCRConfiguration.instance().getString("MCR.Persistence.Access.Store.Table.Rule", "MCRACCESSRULE");
064    
065        static private MCRRuleStore implementation;
066    
067        public static MCRRuleStore getInstance() {
068            try {
069                if (implementation == null) {
070                    implementation = (MCRRuleStore) MCRConfiguration.instance().getSingleInstanceOf("MCR.Persistence.Rule.Store_Class", "org.mycore.backend.hibernate.MCRHIBRuleStore");
071                }
072            } catch (Exception e) {
073                logger.error(e);
074            }
075    
076            return implementation;
077        }
078    }