01: /*
02: * This software is OSI Certified Open Source Software.
03: * OSI Certified is a certification mark of the Open Source Initiative. The
04: * license (Mozilla version 1.0) can be read at the MMBase site. See
05: * http://www.MMBase.org/license
06: */
07: package org.mmbase.core.event;
08:
09: import java.io.Serializable;
10:
11: import org.mmbase.module.core.MMBase;
12:
13: /**
14: * This class is the base class for all mmbase events
15: *
16: * @author Ernst Bunders
17: * @since MMBase-1.8
18: * @version $Id: Event.java,v 1.12 2007/07/26 11:45:54 michiel Exp $
19: */
20: public abstract class Event implements Serializable,
21: org.mmbase.util.PublicCloneable {
22:
23: public static final int TYPE_UNSPECIFIED = -1;
24: public static final int TYPE_NEW = 0;
25: public static final int TYPE_CHANGE = 1;
26: public static final int TYPE_DELETE = 2;
27:
28: protected int eventType = TYPE_UNSPECIFIED;
29: protected String machine;
30:
31: /**
32: * Every event originates from a certain machine, which is identified by a String.
33: * If this equals {@link MMBase#getMachineName()} then this is a local event.
34: */
35: public String getMachine() {
36: return machine;
37: }
38:
39: public boolean isLocal() {
40: return MMBase.getMMBase().getMachineName().equals(machine);
41: }
42:
43: /**
44: * Most events will come in certain 'types', default contants which are provided are {@link
45: * #TYPE_NEW}, {@link #TYPE_CHANGE} and {@link #TYPE_DELETE}.
46: */
47: public int getType() {
48: return eventType;
49: }
50:
51: /**
52: * @param machine The machine name. If <code>null</code> the local machine name is extracted from MMBase, using
53: * {@link MMBase#getMachineName()}
54: */
55: public Event(String machine, int type) {
56: this .machine = machine == null ? MMBase.getMMBase()
57: .getMachineName() : machine;
58: this .eventType = type;
59: }
60:
61: public Event(String machine) {
62: this (machine, TYPE_UNSPECIFIED);
63: }
64:
65: /**
66: * @since MMBase-1.8.4
67: */
68: public Event() {
69: this (MMBase.getMMBase().getMachineName());
70: }
71:
72: public Object clone() {
73: Object clone = null;
74: try {
75: clone = super .clone();
76: } catch (CloneNotSupportedException e) {
77: }
78: return clone;
79: }
80:
81: }
|