KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > runtime > SlotImpl


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@objectweb.org
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Lesser General Public
9
// License as published by the Free Software Foundation; either
10
// version 2.1 of the License, or any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
// USA
21
//
22
// Initial developer(s): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ccm.runtime;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p>Default implementation of the <tt>Slot</tt> interface.</p>
36  **/

37 public class SlotImpl
38 extends org.omg.CORBA.LocalObject JavaDoc
39 implements org.coach.ECA.Slot
40 {
41     // slot
42
private java.util.Hashtable JavaDoc _values; // (thread id, hashtable of values)
43
private int _slot_id;
44     private String JavaDoc _slot_id_str;
45
46     // default constructor
47
public
48     SlotImpl(java.util.Hashtable JavaDoc values, int sid)
49     {
50         // slot
51
_values = values;
52         _slot_id = sid;
53         _slot_id_str = Integer.toString(sid);
54     }
55
56     //
57
// internal operations
58
//
59

60     private java.util.Hashtable JavaDoc
61     getStorageForThread(String JavaDoc tname)
62     {
63         java.util.Hashtable JavaDoc table = (java.util.Hashtable JavaDoc)_values.get(tname);
64         if (table==null) {
65             table = new java.util.Hashtable JavaDoc();
66             _values.put(tname, table);
67         }
68
69         return table;
70     }
71
72     private org.omg.CORBA.Any JavaDoc
73     getValue(String JavaDoc tname, String JavaDoc key)
74     {
75         String JavaDoc rkey = _slot_id_str + key;
76         return (org.omg.CORBA.Any JavaDoc)getStorageForThread(tname).get(rkey);
77     }
78
79     private void
80     putValue(String JavaDoc tname, String JavaDoc key, org.omg.CORBA.Any JavaDoc value)
81     {
82         String JavaDoc rkey = _slot_id_str + key;
83         getStorageForThread(tname).put(rkey, value);
84     }
85
86     //
87
// IDL:coach.org/ECA/Slot:1.0
88
//
89

90     final public void
91     put(String JavaDoc key, org.omg.CORBA.Any JavaDoc value)
92     {
93         putValue(Thread.currentThread().getName(), key, value);
94     }
95
96     final public org.omg.CORBA.Any JavaDoc
97     get(String JavaDoc key)
98     {
99         return getValue(Thread.currentThread().getName(), key);
100     }
101 }
102
Popular Tags