01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1999-2004 Gerald Brose
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Library General Public License for more details.
15: *
16: * You should have received a copy of the GNU Library General Public
17: * License along with this library; if not, write to the Free
18: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19: *
20: */
21:
22: package org.jacorb.notification.util;
23:
24: import java.util.Map;
25: import java.util.WeakHashMap;
26:
27: /**
28: * @author Alphonse Bendt
29: * @version $Id: WeakCacheWildcardMap.java,v 1.1 2005/02/14 00:13:05 alphonse.bendt Exp $
30: */
31: public class WeakCacheWildcardMap implements WildcardMap {
32: private final WildcardMap delegate_;
33: private final Map cache_ = new WeakHashMap();
34:
35: public WeakCacheWildcardMap(WildcardMap delegate) {
36: delegate_ = delegate;
37: }
38:
39: public WeakCacheWildcardMap() {
40: this (new DefaultWildcardMap());
41: }
42:
43: public void clear() {
44: delegate_.clear();
45: cache_.clear();
46: }
47:
48: public Object getNoExpansion(Object key) {
49: return delegate_.getNoExpansion(key);
50: }
51:
52: public Object[] getWithExpansion(Object key) {
53: Object[] result = (Object[]) cache_.get(key.toString());
54:
55: if (result != null) {
56: return result;
57: }
58:
59: result = delegate_.getWithExpansion(key);
60: cache_.put(key.toString(), result);
61:
62: return result;
63: }
64:
65: public Object put(Object key, Object value) {
66: cache_.remove(key.toString());
67:
68: return delegate_.put(key, value);
69: }
70:
71: public Object remove(Object key) {
72: cache_.remove(key.toString());
73:
74: return delegate_.remove(key);
75: }
76: }
|