001 /*
002 * Copyright (c) 1995-2010, The University of Sheffield. See the file
003 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
004 *
005 * This file is part of GATE (see http://gate.ac.uk/), and is free
006 * software, licenced under the GNU Library General Public License,
007 * Version 2, June 1991 (in the distribution as file licence.html,
008 * and also available at http://gate.ac.uk/gate/licence.html).
009 *
010 * Valentin Tablan 13/07/2001
011 *
012 * $Id: CorpusEvent.java 12006 2009-12-01 17:24:28Z thomas_heitz $
013 */
014
015 package gate.event;
016
017 import gate.Corpus;
018 import gate.Document;
019
020 /**
021 * Models events fired by corpora when documents are added or removed.
022 */
023 public class CorpusEvent extends GateEvent {
024
025 /**
026 * Event type that is fired when a new document is added to a corpus
027 */
028 public final static int DOCUMENT_ADDED = 401;
029
030 /**
031 * Event type that is fired when a document is removed from a corpus
032 */
033 public final static int DOCUMENT_REMOVED = 402;
034
035 /**
036 * Creates a new CorpusEvent.
037 * @param source the corpus that fires the event
038 * @param doc the document this event refers to
039 * @param type the type of event ({@link #DOCUMENT_ADDED} or
040 * {@link #DOCUMENT_REMOVED}).
041 */
042 public CorpusEvent(Corpus source, Document doc, int index, int type){
043 this(source, doc, index, null, type);
044 }
045
046 /**
047 * Creates a new CorpusEvent.
048 * @param source the corpus that fires the event
049 * @param doc the document this event refers to
050 * @param documentLRID the persistence ID of the document that has been added
051 * or removed.
052 * @param type the type of event ({@link #DOCUMENT_ADDED} or
053 * {@link #DOCUMENT_REMOVED}).
054 */
055 public CorpusEvent(Corpus source, Document doc, int index,
056 Object documentLRID, int type){
057 super(source, type);
058 this.document = doc;
059 this.documentIndex = index;
060 this.documentLRID = documentLRID;
061 }
062
063 /**
064 * Gets the dcument this event refers to
065 */
066 public gate.Document getDocument() {
067 return document;
068 }
069
070 /**
071 * Gets the index of the document this event refers to
072 */
073 public int getDocumentIndex() {
074 return this.documentIndex;
075 }
076
077
078 /**
079 * Gets the persistence ID of the document to which this event refers.
080 * This value could be <code>null</code>, if the document does not have a
081 * persistence ID.
082 * @return the documentLRID
083 */
084 public Object getDocumentLRID() {
085 return documentLRID;
086 }
087
088
089 /**
090 * The document that has been added/removed.
091 */
092 private gate.Document document;
093
094 /**
095 * The index of the document which has been removed. Needed because
096 * the document itself might not have been loaded in memory, so the
097 * index could be used instead.
098 */
099 private int documentIndex;
100
101 /**
102 * The persistence ID of the document to which this event refers.
103 */
104 private Object documentLRID;
105
106 }
|