KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > poa > Current


1 package org.jacorb.poa;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import org.jacorb.poa.except.*;
24
25 import org.omg.PortableServer.CurrentPackage.NoContext JavaDoc;
26
27 import java.util.*;
28
29 /**
30  * This class provides access to the identity of the object on which a method
31  * was invoked and the responsible POA for this object.
32  *
33  * @author Reimo Tiedemann, FU Berlin
34  * @version $Id: Current.java,v 1.20 2004/05/06 12:40:00 nicolas Exp $
35  */

36
37 public class Current
38     extends org.omg.PortableServer._CurrentLocalBase
39   // extends org.omg.CORBA.LocalObject
40
// implements org.omg.PortableServer.Current
41
{
42     private Hashtable threadTable = new Hashtable();
43     // Thread -> vector of InvocationContext elements (Stack)
44

45     private Current()
46     {
47     }
48
49     public static Current _Current_init()
50     {
51         return new Current();
52     }
53
54     public synchronized void _addContext(Thread JavaDoc t, InvocationContext c)
55     {
56         Vector cv = (Vector) threadTable.get(t);
57
58         if (cv == null) {
59             cv = new Vector();
60             threadTable.put(t, cv);
61         }
62
63         cv.addElement(c);
64     }
65
66     public synchronized void _removeContext(Thread JavaDoc t)
67     {
68         Vector cv = (Vector) threadTable.get(t);
69
70         if (cv != null) {
71
72             cv.removeElementAt(cv.size()-1);
73
74             if (cv.size() == 0) {
75                 threadTable.remove(t);
76             }
77         }
78     }
79
80     public byte[] get_object_id()
81         throws NoContext JavaDoc
82     {
83         return getInvocationContext().getObjectId();
84     }
85
86     public org.omg.CORBA.Object JavaDoc get_reference ()
87         throws NoContext JavaDoc
88     {
89         return get_servant()._this_object (getORB ());
90     }
91
92     public org.omg.PortableServer.Servant JavaDoc get_servant ()
93         throws NoContext JavaDoc
94     {
95         return getInvocationContext().getServant ();
96     }
97
98     public org.omg.PortableServer.POA JavaDoc get_POA ()
99         throws NoContext JavaDoc
100     {
101         return getInvocationContext().getPOA ();
102     }
103
104     synchronized private InvocationContext getInvocationContext()
105         throws NoContext JavaDoc
106     {
107         Thread JavaDoc ct = Thread.currentThread();
108
109         Vector cv = (Vector) threadTable.get(ct);
110
111         if (cv != null)
112         {
113             InvocationContext c = (InvocationContext) cv.lastElement();
114
115             if (c != null)
116             {
117                 return c;
118             }
119         }
120
121         throw new NoContext JavaDoc();
122     }
123
124     protected org.omg.CORBA.ORB JavaDoc getORB()
125         throws NoContext JavaDoc
126     {
127         return getInvocationContext().getORB();
128     }
129
130     protected org.omg.PortableServer.Servant JavaDoc getServant()
131         throws NoContext JavaDoc
132     {
133         return getInvocationContext().getServant();
134     }
135 }
136
Popular Tags