001: /*
002: * This software is OSI Certified Open Source Software.
003: * OSI Certified is a certification mark of the Open Source Initiative. The
004: * license (Mozilla version 1.0) can be read at the MMBase site. See
005: * http://www.MMBase.org/license
006: */
007: package org.mmbase.core.event;
008:
009: import java.io.Serializable;
010: import org.mmbase.util.HashCodeUtil;
011:
012: /**
013: * This class reflects a ,,change relation event. it contains information about the kind of event (new, delete, change),
014: * and it contains a reference to the appropriate typerel node, which allows you to find out on which relation from
015: * which builder to which builder, the event occered. This is usefull for caching optimization.<br/> A relation changed
016: * event is called the twoo nodes that the relation links (or used to).
017: *
018: * @author Ernst Bunders
019: * @since MMBase-1.8
020: * @version $Id: RelationEvent.java,v 1.21 2007/07/26 11:45:54 michiel Exp $
021: */
022: public class RelationEvent extends Event implements Serializable,
023: Cloneable {
024:
025: /**
026: *
027: */
028: private static final long serialVersionUID = 1L;
029:
030: private final int relationSourceNumber;
031: private final int relationDestinationNumber;
032: private final String relationSourceType;
033: private final String relationDestinationType;
034:
035: private final int role; // the reldef node number
036:
037: private final NodeEvent nodeEvent;
038:
039: /**
040: * Constructor for relation event
041: *
042: * @param nodeEvent
043: * @param relationSourceNumber the nodenumber of the 'soucre' node
044: * @param relationDestinationNumber the nodenumber of the 'destination' node
045: * @param relationSourceType the builder name of the 'source' node
046: * @param relationDestinationType the builder name of the 'destination' node
047: * @param role the nodenumber of the reldef node
048: */
049: public RelationEvent(NodeEvent nodeEvent, int relationSourceNumber,
050: int relationDestinationNumber, String relationSourceType,
051: String relationDestinationType, int role) {
052: super (nodeEvent.getMachine(), nodeEvent.getType());
053: this .nodeEvent = nodeEvent;
054: this .relationSourceNumber = relationSourceNumber;
055: this .relationDestinationNumber = relationDestinationNumber;
056: this .relationSourceType = relationSourceType;
057: this .relationDestinationType = relationDestinationType;
058: this .role = role;
059: }
060:
061: /**
062: * @return Returns the relationSourceType.
063: */
064: public String getRelationSourceType() {
065: return relationSourceType;
066: }
067:
068: /**
069: * @return Returns the relationDestinationType.
070: */
071: public String getRelationDestinationType() {
072: return relationDestinationType;
073: }
074:
075: /**
076: * @return Returns the relationSourceNumber.
077: */
078: public int getRelationSourceNumber() {
079: return relationSourceNumber;
080: }
081:
082: /**
083: * @return Returns the relationDestinationNumber.
084: */
085: public int getRelationDestinationNumber() {
086: return relationDestinationNumber;
087: }
088:
089: public int getType() {
090: return eventType;
091: }
092:
093: /**
094: * @return the role number
095: */
096: public int getRole() {
097: return role;
098: }
099:
100: public int hashCode() {
101: int result = nodeEvent.hashCode();
102: result = HashCodeUtil.hashCode(result, relationSourceNumber);
103: result = HashCodeUtil.hashCode(result,
104: relationDestinationNumber);
105: result = HashCodeUtil.hashCode(result, relationSourceType);
106: result = HashCodeUtil.hashCode(result, relationDestinationType);
107: result = HashCodeUtil.hashCode(result, role);
108: result = HashCodeUtil.hashCode(result, eventType);
109: return result;
110: }
111:
112: public boolean equals(Object o) {
113: if (o instanceof RelationEvent) {
114: RelationEvent re = (RelationEvent) o;
115: return nodeEvent.equals(re.nodeEvent)
116: && eventType == re.eventType
117: && role == re.role
118: && relationSourceType.equals(re.relationSourceType)
119: && relationDestinationType
120: .equals(re.relationDestinationType)
121: && relationSourceNumber == re.relationSourceNumber
122: && relationDestinationNumber == re.relationDestinationNumber;
123: } else {
124: return false;
125: }
126: }
127:
128: public NodeEvent getNodeEvent() {
129: return nodeEvent;
130: }
131:
132: public String toString() {
133: return "Relation event. type: "
134: + NodeEvent.getEventTypeGuiName(getType())
135: + ", sourcetype: " + relationSourceType
136: + ", destinationtype: " + relationDestinationType
137: + ", source-node number: " + relationSourceNumber
138: + ", destination-node number: "
139: + relationDestinationNumber + ", role: " + role
140: + " node event: " + nodeEvent;
141: }
142:
143: }
|