KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26
27 /**
28  * A base implementation of GraphManager that stores graph nodes keyed by their ids.
29  * <h3>Tracking Object Changes</h3>
30  * <p>
31  * Registered objects may choose to notify GraphMap of their changes by using callback
32  * methods defined in GraphChangeHandler interface. GraphMap itself implements as noops,
33  * leaving it up to subclasses to handle object updates.
34  * </p>
35  *
36  * @since 1.2
37  * @author Andrus Adamchik
38  */

39 public class GraphMap implements GraphManager {
40
41     protected Map JavaDoc nodes;
42
43     /**
44      * Creates a new GraphMap.
45      */

46     public GraphMap() {
47         this.nodes = new HashMap JavaDoc();
48     }
49
50     // *** GraphMap methods
51

52     /**
53      * Returns an immutable collection of registered nodes.
54      */

55     public Collection JavaDoc registeredNodes() {
56         return Collections.unmodifiableCollection(nodes.values());
57     }
58
59     public synchronized Object JavaDoc getNode(Object JavaDoc nodeId) {
60         return nodes.get(nodeId);
61     }
62
63     public synchronized void registerNode(Object JavaDoc nodeId, Object JavaDoc nodeObject) {
64         nodes.put(nodeId, nodeObject);
65     }
66
67     public synchronized Object JavaDoc unregisterNode(Object JavaDoc nodeId) {
68         return nodes.remove(nodeId);
69     }
70
71     // *** methods for tracking local changes declared in GraphChangeHandler interface
72

73     public void arcCreated(Object JavaDoc nodeId, Object JavaDoc targetNodeId, Object JavaDoc arcId) {
74         // noop
75
}
76
77     public void arcDeleted(Object JavaDoc nodeId, Object JavaDoc targetNodeId, Object JavaDoc arcId) {
78         // noop
79
}
80
81     public void nodeCreated(Object JavaDoc nodeId) {
82         // noop
83
}
84
85     public void nodeRemoved(Object JavaDoc nodeId) {
86         // noop
87
}
88
89     public void nodeIdChanged(Object JavaDoc nodeId, Object JavaDoc newId) {
90         // noop
91
}
92
93     public void nodePropertyChanged(
94             Object JavaDoc nodeId,
95             String JavaDoc property,
96             Object JavaDoc oldValue,
97             Object JavaDoc newValue) {
98         // noop
99
}
100 }
101
Popular Tags