KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > map > event > MapEvent


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
20 package org.apache.cayenne.map.event;
21
22 import org.apache.cayenne.event.CayenneEvent;
23 import org.apache.cayenne.util.Util;
24
25 /**
26  * Superclass of CayenneModeler events.
27  *
28  * @author Andrus Adamchik
29  */

30 public abstract class MapEvent extends CayenneEvent {
31
32     /**
33      * A type that describes object modification events. CHANGE is a default type of new
34      * MapEvents, unless the type is specified explicitly.
35      */

36     public static final int CHANGE = 1;
37
38     /**
39      * A type that describes object creation events.
40      */

41     public static final int ADD = 2;
42
43     /**
44      * A type that describes object removal events.
45      */

46     public static final int REMOVE = 3;
47
48     protected int id = CHANGE;
49     protected String JavaDoc oldName;
50     protected boolean oldNameSet;
51
52     /**
53      * Constructor for MapEvent.
54      *
55      * @param source event source
56      */

57     public MapEvent(Object JavaDoc source) {
58         super(source);
59     }
60
61     /**
62      * Constructor for MapEvent.
63      *
64      * @param source event source
65      */

66     public MapEvent(Object JavaDoc source, String JavaDoc oldName) {
67         super(source);
68         setOldName(oldName);
69     }
70
71     public boolean isNameChange() {
72         return oldNameSet && !Util.nullSafeEquals(getOldName(), getNewName());
73     }
74
75     /**
76      * Returns the id.
77      *
78      * @return int
79      */

80     public int getId() {
81         return id;
82     }
83
84     /**
85      * Returns the newName of the object that caused this event.
86      */

87     public abstract String JavaDoc getNewName();
88
89     /**
90      * Returns the oldName.
91      */

92     public String JavaDoc getOldName() {
93         return oldName;
94     }
95
96     /**
97      * Sets the id.
98      */

99     public void setId(int id) {
100         this.id = id;
101     }
102
103     /**
104      * Sets the oldName.
105      */

106     public void setOldName(String JavaDoc oldName) {
107         this.oldName = oldName;
108         this.oldNameSet = true;
109     }
110 }
111
Popular Tags