1 | /* |
2 | * $Id: EventSourceToListenerCookieTable.java,v 1.2 2005/12/01 06:10:00 hastings Exp $ |
3 | * |
4 | * (c) Copyright, Moebius Solutions, Inc., 2004 |
5 | * |
6 | * All Rights Reserved |
7 | * |
8 | * This material may be reproduced by or for the U. S. Government |
9 | * pursuant to the copyright license under the clause at |
10 | * DFARS 252.227-7014 (OCT 2001). |
11 | */ |
12 | package com.moesol.bindings.platform_sdk.component_services; |
13 | |
14 | import java.util.Hashtable; |
15 | |
16 | import com.moesol.bindings.platform_sdk.component_services.IUnknown.Jni; |
17 | |
18 | /** |
19 | * |
20 | * @author Hastings |
21 | */ |
22 | public class EventSourceToListenerCookieTable { |
23 | |
24 | private static EventSourceToListenerCookieTable g_singleton = new EventSourceToListenerCookieTable(); |
25 | |
26 | /** |
27 | * Exposed for unit tests. |
28 | * |
29 | * @return the one an only EventSourceToListenerCookieTable |
30 | */ |
31 | public static EventSourceToListenerCookieTable singleton() { |
32 | return g_singleton; |
33 | } |
34 | |
35 | /** |
36 | * Exposed for unit tests |
37 | * |
38 | * @param unk |
39 | * @return the ListenerCookieTable for {@code unk}. |
40 | */ |
41 | public ListenerCookieTable findOrMakeListenerCookieTable(Jni unk) { |
42 | synchronized (this) { |
43 | Integer unk_key = extractKey(unk); |
44 | |
45 | ListenerCookieTable result = (ListenerCookieTable)m_table.get(unk_key); |
46 | if (result != null) { |
47 | return result; |
48 | } |
49 | |
50 | result = new ListenerCookieTable(); |
51 | m_table.put(unk_key, result); |
52 | return result; |
53 | } |
54 | } |
55 | |
56 | void removeListenerCookieTable(Jni unk) { |
57 | m_table.remove(extractKey(unk)); |
58 | } |
59 | |
60 | private static Integer extractKey(Jni unk) { |
61 | return new Integer(unk.hashCode()); |
62 | } |
63 | |
64 | private Hashtable m_table = new Hashtable(); |
65 | } |