1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.trinidad.model;
20
21 import java.util.EventObject;
22
23 /**
24 * Event that is generated when RowKey changes.
25 * This event is fired when a row is updated, inserted or deleted
26 * The oldRowKey or new RowKey can be NULL
27 *
28 * The serialization behavior depends on the implementation of the collectionModel that consumes
29 * the RowKeyChangeEvent. If the collectionModel implementation is serializable and keeps track
30 * of row key change events that it recevies, then these events are serialized with the model;
31 * otherwise, the events are not serialized
32 */
33 public class RowKeyChangeEvent extends EventObject
34 {
35 /**
36 * The operation that triggers row key to change
37 */
38 public enum Cause
39 {
40 UPDATE,
41 INSERT,
42 DELETE
43 };
44
45 /**
46 * Creates a new RowKeyChangeEvent
47 * @param source the source of the event
48 * @param oldRowKey the old RowKey.
49 * @param newRowKey the new RowKey.
50 * @param cause the operation that triggers this event
51 */
52 public RowKeyChangeEvent(CollectionModel source, Object oldRowKey, Object newRowKey, Cause cause)
53 {
54 super(source);
55
56 _oldRowKey = oldRowKey;
57 _newRowKey = newRowKey;
58 _cause = cause;
59 }
60
61 /**
62 * retrieve the old RowKey from the event
63 * @return the old RowKey of the event.
64 */
65 public Object getOldRowKey()
66 {
67 return _oldRowKey;
68 }
69
70 /**
71 * retrieve the new row key from the event
72 * @return the new row key of the event.
73 */
74 public Object getNewRowKey()
75 {
76 return _newRowKey;
77 }
78
79 public Cause getCause()
80 {
81 return _cause;
82 }
83
84 @Override
85 public boolean equals(Object o)
86 {
87 if (o == this)
88 return true;
89 else if (!(o instanceof RowKeyChangeEvent))
90 return false;
91 else
92 {
93 RowKeyChangeEvent otherEvent = (RowKeyChangeEvent)o;
94
95 return _oldRowKey.equals(otherEvent._oldRowKey) &&
96 _newRowKey.equals(otherEvent._newRowKey) &&
97 _cause == otherEvent._cause;
98 }
99 }
100
101 @Override
102 public int hashCode()
103 {
104 int hashCode = 17;
105 hashCode = 31 * hashCode + _oldRowKey.hashCode();
106 hashCode = 31 * hashCode + _newRowKey.hashCode();
107 hashCode = 31 * hashCode + _cause.hashCode();
108 return hashCode;
109 }
110
111 @Override
112 public String toString()
113 {
114 return super.toString() +
115 "[oldRowKey=" + _oldRowKey.toString() +
116 ", newRowKey=" + _newRowKey.toString() +
117 ", cause=" + _cause.toString() + "]";
118 }
119
120 private final Object _oldRowKey;
121 private final Object _newRowKey;
122 private final Cause _cause;
123 private static final long serialVersionUID = 1L;
124 }