KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > graph > NodePropertyChangeOperation


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.graph;
21
22 import org.apache.cayenne.util.Util;
23
24 /**
25  * @since 1.2
26  * @author Andrus Adamchik
27  */

28 public class NodePropertyChangeOperation extends NodeDiff {
29
30     protected String JavaDoc property;
31     protected Object JavaDoc oldValue;
32     protected Object JavaDoc newValue;
33
34     public NodePropertyChangeOperation(Object JavaDoc nodeId, String JavaDoc property, Object JavaDoc oldValue,
35             Object JavaDoc newValue) {
36
37         super(nodeId);
38         this.property = property;
39         this.oldValue = oldValue;
40         this.newValue = newValue;
41     }
42
43     public NodePropertyChangeOperation(Object JavaDoc nodeId, String JavaDoc property, Object JavaDoc oldValue,
44             Object JavaDoc newValue, int diffId) {
45         super(nodeId, diffId);
46         
47         this.property = property;
48         this.oldValue = oldValue;
49         this.newValue = newValue;
50     }
51
52     /**
53      * Returns true if both old and new value are equal.
54      */

55     public boolean isNoop() {
56         return Util.nullSafeEquals(oldValue, newValue);
57     }
58
59     public void apply(GraphChangeHandler tracker) {
60         tracker.nodePropertyChanged(nodeId, property, oldValue, newValue);
61     }
62
63     public void undo(GraphChangeHandler tracker) {
64         tracker.nodePropertyChanged(nodeId, property, newValue, oldValue);
65     }
66 }
67
Popular Tags