1. /*
  2. * @(#)SlotTable.java 1.7 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.Interceptors;
  8. import com.sun.corba.se.internal.corba.AnyImpl;
  9. import org.omg.PortableInterceptor.Current;
  10. import org.omg.PortableInterceptor.InvalidSlot;
  11. import org.omg.CORBA.Any;
  12. import org.omg.CORBA.ORB;
  13. import com.sun.corba.se.internal.util.MinorCodes;
  14. /**
  15. * SlotTable is used internally by PICurrent to store the slot information.
  16. */
  17. public class SlotTable {
  18. // The vector where all the slot data for the current thread is stored
  19. private Any[] theSlotData;
  20. // Required for instantiating Any object.
  21. private ORB orb;
  22. // The flag to check whether there are any updates in the current SlotTable.
  23. // The slots will be reset to null, only if this flag is set.
  24. private boolean dirtyFlag;
  25. /**
  26. * The constructor instantiates an Array of Any[] of size given by slotSize
  27. * parameter.
  28. */
  29. SlotTable( PIORB piOrb, int slotSize ) {
  30. dirtyFlag = false;
  31. orb = piOrb;
  32. theSlotData = new Any[slotSize];
  33. }
  34. /**
  35. * This method sets the slot data at the given slot id (index).
  36. */
  37. public void set_slot( int id, Any data ) throws InvalidSlot
  38. {
  39. // First check whether the slot is allocated
  40. // If not, raise the invalid slot exception
  41. if( id >= theSlotData.length ) {
  42. throw new InvalidSlot();
  43. }
  44. dirtyFlag = true;
  45. theSlotData[id] = data;
  46. }
  47. /**
  48. * This method get the slot data for the given slot id (index).
  49. */
  50. public Any get_slot( int id ) throws InvalidSlot
  51. {
  52. // First check whether the slot is allocated
  53. // If not, raise the invalid slot exception
  54. if( id >= theSlotData.length ) {
  55. throw new InvalidSlot();
  56. }
  57. if( theSlotData[id] == null ) {
  58. theSlotData [id] = new AnyImpl(orb);
  59. }
  60. return theSlotData[ id ];
  61. }
  62. /**
  63. * This method resets all the slot data to null if dirtyFlag is set.
  64. */
  65. void resetSlots( ) {
  66. if( dirtyFlag == true ) {
  67. for( int i = 0; i < theSlotData.length; i++ ) {
  68. theSlotData[i] = null;
  69. }
  70. }
  71. }
  72. /**
  73. * This method returns the size of the allocated slots.
  74. */
  75. int getSize( ) {
  76. return theSlotData.length;
  77. }
  78. }