KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > impl > ElementsInnerProxyMap


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.impl;
16
17 import java.util.AbstractMap JavaDoc;
18 import java.util.Map JavaDoc;
19 import java.util.Set JavaDoc;
20
21 /**
22  * Implements a {@link java.util.Map} as a proxy to an actual map of elements, provided by an
23  * extension point. The proxy is unmodifiable and will work with the extension point to generate the
24  * real map of elements in a just-in-time manner.
25  *
26  * @author Knut Wannheden
27  * @since 1.1
28  */

29 public final class ElementsInnerProxyMap extends AbstractMap JavaDoc
30 {
31     private Map JavaDoc _inner;
32
33     private ConfigurationPointImpl _point;
34
35     private ElementsProxyMap _outer;
36
37     ElementsInnerProxyMap(ConfigurationPointImpl point, ElementsProxyMap outer)
38     {
39         _point = point;
40         _outer = outer;
41
42         _outer.setInner(this);
43     }
44
45     public Set JavaDoc entrySet()
46     {
47         return inner().entrySet();
48     }
49
50     private synchronized Map JavaDoc inner()
51     {
52         if (_inner == null)
53         {
54             _inner = _point.constructMapElements();
55
56             // Replace ourselves in the outer proxy with the actual list.
57
_outer.setInner(_inner);
58         }
59
60         return _inner;
61     }
62
63     public boolean equals(Object JavaDoc o)
64     {
65         if (this == o)
66             return true;
67
68         if (o == null)
69             return false;
70
71         return inner().equals(o);
72     }
73
74     public int hashCode()
75     {
76         return inner().hashCode();
77     }
78
79     public synchronized String JavaDoc toString()
80     {
81         if (_inner != null)
82             return _inner.toString();
83
84         return "<Element Map Proxy for " + _point.getExtensionPointId() + ">";
85     }
86
87 }
Popular Tags