KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > interceptors > SlotTable


1 /*
2  * @(#)SlotTable.java 1.9 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.interceptors;
9
10 import com.sun.corba.se.impl.corba.AnyImpl;
11 import com.sun.corba.se.spi.orb.ORB;
12 import org.omg.PortableInterceptor.Current JavaDoc;
13 import org.omg.PortableInterceptor.InvalidSlot JavaDoc;
14 import org.omg.CORBA.Any JavaDoc;
15
16 /**
17  * SlotTable is used internally by PICurrent to store the slot information.
18  */

19 public class SlotTable {
20     // The vector where all the slot data for the current thread is stored
21
private Any JavaDoc[] theSlotData;
22
23     // Required for instantiating Any object.
24
private ORB orb;
25
26     // The flag to check whether there are any updates in the current SlotTable.
27
// The slots will be reset to null, only if this flag is set.
28
private boolean dirtyFlag;
29
30     /**
31      * The constructor instantiates an Array of Any[] of size given by slotSize
32      * parameter.
33      */

34     SlotTable( ORB orb, int slotSize ) {
35         dirtyFlag = false;
36         this.orb = orb;
37         theSlotData = new Any JavaDoc[slotSize];
38     }
39
40     /**
41      * This method sets the slot data at the given slot id (index).
42      */

43     public void set_slot( int id, Any JavaDoc data ) throws InvalidSlot JavaDoc
44     {
45         // First check whether the slot is allocated
46
// If not, raise the invalid slot exception
47
if( id >= theSlotData.length ) {
48             throw new InvalidSlot JavaDoc();
49         }
50         dirtyFlag = true;
51         theSlotData[id] = data;
52     }
53
54     /**
55      * This method get the slot data for the given slot id (index).
56      */

57     public Any JavaDoc get_slot( int id ) throws InvalidSlot JavaDoc
58     {
59         // First check whether the slot is allocated
60
// If not, raise the invalid slot exception
61
if( id >= theSlotData.length ) {
62             throw new InvalidSlot JavaDoc();
63         }
64         if( theSlotData[id] == null ) {
65             theSlotData [id] = new AnyImpl(orb);
66         }
67         return theSlotData[ id ];
68     }
69
70
71     /**
72      * This method resets all the slot data to null if dirtyFlag is set.
73      */

74     void resetSlots( ) {
75         if( dirtyFlag == true ) {
76             for( int i = 0; i < theSlotData.length; i++ ) {
77                 theSlotData[i] = null;
78             }
79         }
80     }
81
82     /**
83      * This method returns the size of the allocated slots.
84      */

85     int getSize( ) {
86         return theSlotData.length;
87     }
88
89 }
90     
91
Popular Tags