001: package org.jacorb.poa;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import org.omg.PortableServer.CurrentPackage.NoContext;
024:
025: import java.util.*;
026:
027: /**
028: * This class provides access to the identity of the object on which a method
029: * was invoked and the responsible POA for this object.
030: *
031: * @author Reimo Tiedemann
032: * @version $Id: Current.java,v 1.22 2006/05/23 18:25:45 alphonse.bendt Exp $
033: */
034:
035: public class Current extends org.omg.PortableServer._CurrentLocalBase {
036: // Thread -> vector of InvocationContext elements (Stack)
037: private final Map threadTable = new HashMap();
038:
039: public synchronized void _addContext(Thread thread,
040: InvocationContext c) {
041: LinkedList list = (LinkedList) threadTable.get(thread);
042:
043: if (list == null) {
044: list = new LinkedList();
045: threadTable.put(thread, list);
046: }
047:
048: list.add(c);
049: }
050:
051: public synchronized void _removeContext(Thread thread) {
052: LinkedList list = (LinkedList) threadTable.get(thread);
053:
054: if (list != null) {
055: list.removeLast();
056:
057: if (list.isEmpty()) {
058: threadTable.remove(thread);
059: }
060: }
061: }
062:
063: public byte[] get_object_id() throws NoContext {
064: return getInvocationContext().getObjectId();
065: }
066:
067: public org.omg.CORBA.Object get_reference() throws NoContext {
068: return get_servant()._this _object(getORB());
069: }
070:
071: public org.omg.PortableServer.Servant get_servant()
072: throws NoContext {
073: return getInvocationContext().getServant();
074: }
075:
076: public org.omg.PortableServer.POA get_POA() throws NoContext {
077: return getInvocationContext().getPOA();
078: }
079:
080: private synchronized InvocationContext getInvocationContext()
081: throws NoContext {
082: Thread thread = Thread.currentThread();
083:
084: LinkedList list = (LinkedList) threadTable.get(thread);
085:
086: if (list != null) {
087: InvocationContext context = (InvocationContext) list
088: .getLast();
089:
090: if (context != null) {
091: return context;
092: }
093: }
094:
095: throw new NoContext();
096: }
097:
098: protected org.omg.CORBA.ORB getORB() throws NoContext {
099: return getInvocationContext().getORB();
100: }
101:
102: protected org.omg.PortableServer.Servant getServant()
103: throws NoContext {
104: return getInvocationContext().getServant();
105: }
106: }
|