001: package net.javacoding.jspider.api.event;
002:
003: import java.util.Date;
004:
005: /**
006: * Base class of all JSpider API events. All events that will be dispatched
007: * towards JSpider modules will extends directly or indirectly from this
008: * class.
009: *
010: * $Id: JSpiderEvent.java,v 1.5 2003/03/23 15:44:48 vanrogu Exp $
011: *
012: * @author Günther Van Roey
013: */
014: public abstract class JSpiderEvent implements EventVisitable {
015:
016: public static final String EVENT_PACKAGE = "net.javacoding.jspider.api.event.";
017:
018: /** Event type used for events related to the JSpider engine. */
019: public static final int EVENT_TYPE_ENGINE = 1;
020:
021: /** Event type used for events related to monitoring. */
022: public static final int EVENT_TYPE_MONITORING = 2;
023:
024: /** Event type used for real spider events. */
025: public static final int EVENT_TYPE_SPIDER = 3;
026:
027: /** Timestamp of the event. */
028: protected Date date;
029:
030: /**
031: * Public constructor.
032: */
033: public JSpiderEvent() {
034: date = new Date();
035: }
036:
037: /**
038: * Returns the name of the event
039: * @return name of the event
040: */
041: public String getName() {
042: return getClass().getName().substring(EVENT_PACKAGE.length());
043: }
044:
045: /**
046: * Returns a Date object containing the event's timestamp
047: * @return Date object containing the event's timestamp
048: */
049: public Date getRaisedDate() {
050: return date;
051: }
052:
053: /**
054: * Returns optional comments on the event.
055: * @return comment on the event.
056: */
057: public abstract String getComment();
058:
059: /**
060: * Returns whether this event describes some sort of error situation.
061: * @return boolean that is true if this event describes an error
062: */
063: public boolean isError() {
064: return false;
065: }
066:
067: /**
068: * Returns whether this event can be filtered out. Only the most critical
069: * events will return FALSE.
070: * @return whether this event can be filtered out
071: */
072: public boolean isFilterable() {
073: return true;
074: }
075:
076: /**
077: * Returns the type of the event.
078: * @return the type of the Event - Engine / Monitoring / Spider
079: */
080: public int getType() {
081: // By default, it will be a normal spider event.
082: return JSpiderEvent.EVENT_TYPE_SPIDER;
083: }
084:
085: /**
086: * Accept method for the Visitor-pattern that's used for handling events.
087: * @param visitor the visitor instance that wants to visit the event
088: */
089: public void accept(EventVisitor visitor) {
090: visitor.visit(this );
091: }
092:
093: /**
094: * Object's overridden toString() method.
095: * @return String representation of the event
096: */
097: public String toString() {
098: return this.getClass().getName();
099: }
100: }
|