SlotTable.java revision 608:7e06bf1dcb09
1/* 2 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package com.sun.corba.se.impl.interceptors; 27 28import com.sun.corba.se.impl.corba.AnyImpl; 29import com.sun.corba.se.spi.orb.ORB; 30import org.omg.PortableInterceptor.Current; 31import org.omg.PortableInterceptor.InvalidSlot; 32import org.omg.CORBA.Any; 33 34/** 35 * SlotTable is used internally by PICurrent to store the slot information. 36 */ 37public class SlotTable { 38 // The vector where all the slot data for the current thread is stored 39 private Any[] theSlotData; 40 41 // Required for instantiating Any object. 42 private ORB orb; 43 44 // The flag to check whether there are any updates in the current SlotTable. 45 // The slots will be reset to null, only if this flag is set. 46 private boolean dirtyFlag; 47 48 /** 49 * The constructor instantiates an Array of Any[] of size given by slotSize 50 * parameter. 51 */ 52 SlotTable( ORB orb, int slotSize ) { 53 dirtyFlag = false; 54 this.orb = orb; 55 theSlotData = new Any[slotSize]; 56 } 57 58 /** 59 * This method sets the slot data at the given slot id (index). 60 */ 61 public void set_slot( int id, Any data ) throws InvalidSlot 62 { 63 // First check whether the slot is allocated 64 // If not, raise the invalid slot exception 65 if( id >= theSlotData.length ) { 66 throw new InvalidSlot(); 67 } 68 dirtyFlag = true; 69 theSlotData[id] = data; 70 } 71 72 /** 73 * This method get the slot data for the given slot id (index). 74 */ 75 public Any get_slot( int id ) throws InvalidSlot 76 { 77 // First check whether the slot is allocated 78 // If not, raise the invalid slot exception 79 if( id >= theSlotData.length ) { 80 throw new InvalidSlot(); 81 } 82 if( theSlotData[id] == null ) { 83 theSlotData [id] = new AnyImpl(orb); 84 } 85 return theSlotData[ id ]; 86 } 87 88 89 /** 90 * This method resets all the slot data to null if dirtyFlag is set. 91 */ 92 void resetSlots( ) { 93 if( dirtyFlag == true ) { 94 for( int i = 0; i < theSlotData.length; i++ ) { 95 theSlotData[i] = null; 96 } 97 } 98 } 99 100 /** 101 * This method returns the size of the allocated slots. 102 */ 103 int getSize( ) { 104 return theSlotData.length; 105 } 106 107} 108