001    /*
002     * 
003     * $Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06. Feb 2008) $
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.frontend.indexbrowser.lucene;
025    
026    import org.mycore.common.events.MCREvent;
027    import org.mycore.common.events.MCREventHandlerBase;
028    import org.mycore.datamodel.metadata.MCRObject;
029    
030    /**
031     * This class implements an event handler that reacts on object modify / create /
032     * delete events. It basically clears the different classification caches to
033     * make sure the number of documents for each classification item is displayed
034     * correctly. This has also an impact to the question if a classification item
035     * can be expanded to display subitems.
036     * 
037     * @author Robert Stephan
038     */
039    public class MCRIndexBrowserEventHandler extends MCREventHandlerBase {
040    
041        /**
042         * 
043         * @param evt
044         *            the event that occured
045         * @param obj
046         *            the MCRObject that caused the event
047         */
048        protected final void handleObjectCreated(MCREvent evt, MCRObject obj) {
049            MCRIndexBrowserCache.deleteIndexCacheFromHashtable(getObjectType(obj));
050        }
051    
052        private String getObjectType(MCRObject obj) {
053            String typeID = obj.getId().getTypeId();
054            return typeID;
055        }
056    
057        /**
058         * This method update the data to SQL table of XML data via
059         * MCRXMLTableManager.
060         * 
061         * @param evt
062         *            the event that occured
063         * @param obj
064         *            the MCRObject that caused the event
065         */
066        protected final void handleObjectUpdated(MCREvent evt, MCRObject obj) {
067            MCRIndexBrowserCache.deleteIndexCacheFromHashtable(getObjectType(obj));
068        }
069    
070        /**
071         * This method delete the XML data from SQL table data via
072         * MCRXMLTableManager.
073         * 
074         * @param evt
075         *            the event that occured
076         * @param obj
077         *            the MCRObject that caused the event
078         */
079        protected final void handleObjectDeleted(MCREvent evt, MCRObject obj) {
080            MCRIndexBrowserCache.deleteIndexCacheFromHashtable(getObjectType(obj));
081        }
082    
083    }