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