0N/A/*
157N/A * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
157N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
157N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
157N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
157N/A * or visit www.oracle.com if you need additional information or have any
157N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.corba.se.impl.interceptors;
0N/A
0N/Aimport com.sun.corba.se.spi.orb.ORB;
0N/Aimport org.omg.PortableInterceptor.Current;
0N/Aimport org.omg.PortableInterceptor.InvalidSlot;
0N/Aimport org.omg.CORBA.Any;
0N/Aimport org.omg.CORBA.BAD_INV_ORDER;
0N/Aimport org.omg.CORBA.CompletionStatus;
0N/A
0N/Aimport com.sun.corba.se.spi.logging.CORBALogDomains ;
0N/Aimport com.sun.corba.se.impl.logging.OMGSystemException ;
0N/A
0N/A/**
0N/A * PICurrent is the implementation of Current as specified in the Portable
0N/A * Interceptors Spec orbos/99-12-02.
0N/A * IMPORTANT: PICurrent is implemented with the assumption that get_slot()
0N/A * or set_slot() will not be called in ORBInitializer.pre_init() and
0N/A * post_init().
0N/A */
0N/Apublic class PICurrent extends org.omg.CORBA.LocalObject
0N/A implements Current
0N/A{
0N/A // slotCounter is used to keep track of ORBInitInfo.allocate_slot_id()
0N/A private int slotCounter;
0N/A
0N/A // The ORB associated with this PICurrent object.
0N/A private ORB myORB;
0N/A
0N/A private OMGSystemException wrapper ;
0N/A
0N/A // True if the orb is still initialzing and get_slot and set_slot are not
0N/A // to be called.
0N/A private boolean orbInitializing;
0N/A
0N/A // ThreadLocal contains a stack of SlotTable which are used
0N/A // for resolve_initial_references( "PICurrent" );
0N/A private ThreadLocal threadLocalSlotTable
0N/A = new ThreadLocal( ) {
0N/A protected Object initialValue( ) {
0N/A SlotTable table = new SlotTable( myORB, slotCounter );
0N/A return new SlotTableStack( myORB, table );
0N/A }
0N/A };
0N/A
0N/A /**
0N/A * PICurrent constructor which will be called for every ORB
0N/A * initialization.
0N/A */
0N/A PICurrent( ORB myORB ) {
0N/A this.myORB = myORB;
0N/A wrapper = OMGSystemException.get( myORB,
0N/A CORBALogDomains.RPC_PROTOCOL ) ;
0N/A this.orbInitializing = true;
0N/A slotCounter = 0;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * This method will be called from ORBInitInfo.allocate_slot_id( ).
0N/A * simply returns a slot id by incrementing slotCounter.
0N/A */
0N/A int allocateSlotId( ) {
0N/A int slotId = slotCounter;
0N/A slotCounter = slotCounter + 1;
0N/A return slotId;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * This method gets the SlotTable which is on the top of the
0N/A * ThreadLocalStack.
0N/A */
0N/A SlotTable getSlotTable( ) {
0N/A SlotTable table = (SlotTable)
0N/A ((SlotTableStack)threadLocalSlotTable.get()).peekSlotTable();
0N/A return table;
0N/A }
0N/A
0N/A /**
0N/A * This method pushes a SlotTable on the SlotTableStack. When there is
0N/A * a resolve_initial_references("PICurrent") after this call. The new
0N/A * PICurrent will be returned.
0N/A */
0N/A void pushSlotTable( ) {
0N/A SlotTableStack st = (SlotTableStack)threadLocalSlotTable.get();
0N/A st.pushSlotTable( );
0N/A }
0N/A
0N/A
0N/A /**
0N/A * This method pops a SlotTable on the SlotTableStack.
0N/A */
0N/A void popSlotTable( ) {
0N/A SlotTableStack st = (SlotTableStack)threadLocalSlotTable.get();
0N/A st.popSlotTable( );
0N/A }
0N/A
0N/A /**
0N/A * This method sets the slot data at the given slot id (index) in the
0N/A * Slot Table which is on the top of the SlotTableStack.
0N/A */
0N/A public void set_slot( int id, Any data ) throws InvalidSlot
0N/A {
0N/A if( orbInitializing ) {
0N/A // As per ptc/00-08-06 if the ORB is still initializing, disallow
0N/A // calls to get_slot and set_slot. If an attempt is made to call,
0N/A // throw a BAD_INV_ORDER.
0N/A throw wrapper.invalidPiCall3() ;
0N/A }
0N/A
0N/A getSlotTable().set_slot( id, data );
0N/A }
0N/A
0N/A /**
0N/A * This method gets the slot data at the given slot id (index) from the
0N/A * Slot Table which is on the top of the SlotTableStack.
0N/A */
0N/A public Any get_slot( int id ) throws InvalidSlot
0N/A {
0N/A if( orbInitializing ) {
0N/A // As per ptc/00-08-06 if the ORB is still initializing, disallow
0N/A // calls to get_slot and set_slot. If an attempt is made to call,
0N/A // throw a BAD_INV_ORDER.
0N/A throw wrapper.invalidPiCall4() ;
0N/A }
0N/A
0N/A return getSlotTable().get_slot( id );
0N/A }
0N/A
0N/A /**
0N/A * This method resets all the slot data to null in the
0N/A * Slot Table which is on the top of SlotTableStack.
0N/A */
0N/A void resetSlotTable( ) {
0N/A getSlotTable().resetSlots();
0N/A }
0N/A
0N/A /**
0N/A * Called from ORB when the ORBInitializers are about to start
0N/A * initializing.
0N/A */
0N/A void setORBInitializing( boolean init ) {
0N/A this.orbInitializing = init;
0N/A }
0N/A}