KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > core > event > RelationEvent


1 /*
2  * Created on 21-jun-2005
3  * This software is OSI Certified Open Source Software.
4  * OSI Certified is a certification mark of the Open Source Initiative. The
5  * license (Mozilla version 1.0) can be read at the MMBase site. See
6  * http://www.MMBase.org/license
7  */

8 package org.mmbase.core.event;
9
10 import java.io.Serializable JavaDoc;
11 import java.util.*;
12 import org.mmbase.util.HashCodeUtil;
13 import org.mmbase.module.core.MMBase;
14
15 /**
16  * This class reflects a ,,change relation event. it contains information about the kind of event (new, delete, change),
17  * and it contains a reference to the appropriate typerel node, which allows you to find out on which relation from
18  * which builder to which builder, the event occered. This is usefull for caching optimization.<br/> A relation changed
19  * event is called the twoo nodes that the relation links (or used to).
20  *
21  * @author Ernst Bunders
22  * @since MMBase-1.8
23  * @version $Id: RelationEvent.java,v 1.18 2006/06/20 21:23:57 michiel Exp $
24  */

25 public class RelationEvent extends Event implements Serializable JavaDoc, Cloneable JavaDoc {
26
27     /**
28      *
29      */

30     private static final long serialVersionUID = 1L;
31
32     private final int relationSourceNumber, relationDestinationNumber;
33     // these are not final becouse they can be reset by MMObjectBuilder.notify()
34
private String JavaDoc relationSourceType;
35     private String JavaDoc relationDestinationType;
36
37     private final int role; // the reldef node number
38

39     private NodeEvent nodeEvent;
40
41     /**
42      * Constructor for relation event
43      *
44      * @param nodeEvent
45      * @param relationSourceNumber the nodenumber of the 'soucre' node
46      * @param relationDestinationNumber the nodenumber of the 'destination' node
47      * @param relationSourceType the builder name of the 'source' node
48      * @param relationDestinationType the builder name of the 'destination' node
49      * @param role the nodenumber of the reldef node
50      */

51     public RelationEvent(NodeEvent nodeEvent, int relationSourceNumber, int relationDestinationNumber,
52             String JavaDoc relationSourceType, String JavaDoc relationDestinationType, int role) {
53         super(nodeEvent.getMachine(), nodeEvent.getType());
54         this.nodeEvent = nodeEvent;
55         this.relationSourceNumber = relationSourceNumber;
56         this.relationDestinationNumber = relationDestinationNumber;
57         this.relationSourceType = relationSourceType;
58         this.relationDestinationType = relationDestinationType;
59         this.role = role;
60     }
61
62
63     /**
64      * @return Returns the relationSourceType.
65      */

66     public String JavaDoc getRelationSourceType() {
67         return relationSourceType;
68     }
69
70
71     /**
72      * @return Returns the relationDestinationType.
73      */

74     public String JavaDoc getRelationDestinationType() {
75         return relationDestinationType;
76     }
77
78     /**
79      * @return Returns the relationSourceNumber.
80      */

81     public int getRelationSourceNumber() {
82         return relationSourceNumber;
83     }
84
85     /**
86      * @return Returns the relationDestinationNumber.
87      */

88     public int getRelationDestinationNumber() {
89         return relationDestinationNumber;
90     }
91
92     public int getType() {
93         return eventType;
94     }
95
96     /**
97      * @return the role number
98      */

99     public int getRole() {
100         return role;
101     }
102
103     /**
104      * I think this method is not needed.
105      * @deprecated
106      */

107     /*
108     public RelationEvent clone(String sourceType, String destType) {
109         RelationEvent clone = (RelationEvent) super.clone();
110         clone.nodeEvent = (NodeEvent) nodeEvent.clone();
111         clone.relationSourceType = sourceType;
112         clone.relationDestinationType = destType;
113         return clone;
114     }
115     */

116
117     public int hashCode() {
118         int result = nodeEvent.hashCode();
119         result = HashCodeUtil.hashCode(result, relationSourceNumber);
120         result = HashCodeUtil.hashCode(result, relationDestinationNumber);
121         result = HashCodeUtil.hashCode(result, relationSourceType);
122         result = HashCodeUtil.hashCode(result, relationDestinationType);
123         result = HashCodeUtil.hashCode(result, role);
124         result = HashCodeUtil.hashCode(result, eventType);
125         return result;
126     }
127
128     public boolean equals(Object JavaDoc o) {
129         if (o instanceof RelationEvent) {
130             RelationEvent re = (RelationEvent) o;
131             return
132                 nodeEvent.equals(re.nodeEvent) &&
133                 eventType == re.eventType &&
134                 role == re.role &&
135                 relationSourceType.equals(re.relationSourceType) &&
136                 relationDestinationType.equals(re.relationDestinationType) &&
137                 relationSourceNumber == re.relationSourceNumber &&
138                 relationDestinationNumber == re.relationDestinationNumber;
139         } else {
140             return false;
141         }
142     }
143
144
145     public NodeEvent getNodeEvent() {
146         return nodeEvent;
147     }
148
149     public String JavaDoc toString() {
150         return "Relation event. type: " + NodeEvent.getEventTypeGuiName(getType())
151                 + ", sourcetype: " + relationSourceType + ", destinationtype: " + relationDestinationType
152                 + ", source-node number: " + relationSourceNumber + ", destination-node number: "
153                 + relationDestinationNumber + ", role: " + role + " node event: " + nodeEvent;
154     }
155
156
157
158 }
159
Popular Tags