KickJava   Java API By Example, From Geeks To Geeks.

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


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.AbstractList JavaDoc;
18 import java.util.List JavaDoc;
19
20 /**
21  * Implements a {@link java.util.List} as a proxy to an actual list of
22  * elements, provided by an extension point. The proxy is unmodifiable
23  * and will work with the extension point to generate the real list
24  * of elements in a just-in-time manner.
25  *
26  * @author Howard Lewis Ship
27  */

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