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.backend.jdom;
025
026 import org.apache.log4j.Logger;
027 import org.mycore.common.events.MCREvent;
028 import org.mycore.common.events.MCREventHandlerBase;
029 import org.mycore.datamodel.metadata.MCRObject;
030 import org.mycore.datamodel.metadata.MCRObjectID;
031
032 /**
033 * This class builds indexes from mycore meta data in a temporary JDOM store.
034 *
035 * @author Jens Kupferschmidt
036 */
037 public class MCRJDOMEventHandlerIndexMeta extends MCREventHandlerBase {
038 // the logger
039 private static Logger LOGGER = Logger.getLogger(MCRJDOMEventHandlerIndexMeta.class);
040
041 // the temporary store
042 private static final MCRJDOMMemoryStore store = MCRJDOMMemoryStore.instance();
043
044 /**
045 * This class create an index of meta data objects in the temporary JDOM
046 * tree.
047 *
048 * @param evt
049 * the event that occured
050 * @param obj
051 * the MCRObject that caused the event
052 */
053 protected void handleObjectCreated(MCREvent evt, MCRObject obj) {
054 // save the start time
055 long t1 = System.currentTimeMillis();
056
057 // create
058 MCRObjectID mcr_id = obj.getId();
059 LOGGER.debug("MCRJDOMEventHandlerIndexMeta create: MCRObjectID : " + mcr_id.getId());
060
061 org.jdom.Document doc = obj.createXML();
062 store.addElement(mcr_id, doc);
063
064 // save the stop time
065 long t2 = System.currentTimeMillis();
066 double diff = (t2 - t1) / 1000.0;
067 LOGGER.debug("MCRJDOMEventHandlerIndexMeta create: done in " + diff + " sec.");
068 }
069
070 /**
071 * This class update an index of meta data objects in the temporary JDOM
072 * tree.
073 *
074 * @param evt
075 * the event that occured
076 * @param obj
077 * the MCRObject that caused the event
078 */
079 protected void handleObjectUpdated(MCREvent evt, MCRObject obj) {
080 // save the start time
081 long t1 = System.currentTimeMillis();
082
083 // update
084 MCRObjectID mcr_id = obj.getId();
085 LOGGER.debug("MCRJDOMEventHandlerIndexMeta update: MCRObjectID : " + mcr_id.getId());
086
087 org.jdom.Document doc = obj.createXML();
088 store.removeElement(mcr_id);
089 store.addElement(mcr_id, doc);
090
091 // save the stop time
092 long t2 = System.currentTimeMillis();
093 double diff = (t2 - t1) / 1000.0;
094 LOGGER.debug("MCRJDOMEventHandlerIndexMeta update: done in " + diff + " sec.");
095 }
096
097 /**
098 * This class delete an index of meta data objects from the temporary JDOM
099 * tree.
100 *
101 * @param evt
102 * the event that occured
103 * @param obj
104 * the MCRObject that caused the event
105 */
106 protected void handleObjectDeleted(MCREvent evt, MCRObject obj) {
107 // save the start time
108 long t1 = System.currentTimeMillis();
109
110 // delete
111 MCRObjectID mcr_id = obj.getId();
112 LOGGER.debug("MCRJDOMEventHandlerIndexMeta delete: MCRObjectID : " + mcr_id.getId());
113 store.removeElement(mcr_id);
114
115 // save the stop time
116 long t2 = System.currentTimeMillis();
117 double diff = (t2 - t1) / 1000.0;
118 LOGGER.debug("MCRJDOMEventHandlerIndexMeta delete: done in " + diff + " sec.");
119 }
120
121 /**
122 * This class update an index of meta data objects in the temporary JDOM
123 * tree.
124 *
125 * @param evt
126 * the event that occured
127 * @param obj
128 * the MCRObject that caused the event
129 */
130 protected void handleObjectRepaired(MCREvent evt, MCRObject obj) {
131 // save the start time
132 long t1 = System.currentTimeMillis();
133
134 // update
135 MCRObjectID mcr_id = obj.getId();
136 LOGGER.debug("MCRJDOMEventHandlerIndexMeta repair: MCRObjectID : " + mcr_id.getId());
137
138 org.jdom.Document doc = obj.createXML();
139 store.removeElement(mcr_id);
140 store.addElement(mcr_id, doc);
141
142 // save the stop time
143 long t2 = System.currentTimeMillis();
144 double diff = (t2 - t1) / 1000.0;
145 LOGGER.debug("MCRJDOMEventHandlerIndexMeta repair: done in " + diff + " sec.");
146 }
147
148 }