1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.ejb;
  6. import java.util.*;
  7. import java.security.Identity;
  8. import java.security.Principal;
  9. import javax.transaction.UserTransaction;
  10. /**
  11. * The EJBContext interface provides an instance with access to the
  12. * container-provided runtime context of an enterprise Bean instance.
  13. *
  14. * <p> This interface is extended by the SessionContext and EntityContext
  15. * interface to provide additional methods specific to the enterprise
  16. * Bean type.
  17. */
  18. public interface EJBContext
  19. {
  20. /**
  21. * Obtain the enterprise bean's remote home interface.
  22. *
  23. * @return The enterprise bean's remote home interface.
  24. * @exception java.lang.IllegalStateException if the enterprise bean
  25. * does not have a remote home interface.
  26. */
  27. EJBHome getEJBHome();
  28. /**
  29. * Obtain the enterprise bean's local home interface.
  30. *
  31. * @return The enterprise bean's local home interface.
  32. * @exception java.lang.IllegalStateException if the enterprise bean
  33. * does not have a local home interface.
  34. */
  35. EJBLocalHome getEJBLocalHome();
  36. /**
  37. * Obtain the enterprise bean's environment properties.
  38. *
  39. * <p><b>Note:</b> If the enterprise bean has no environment properties
  40. * this method returns an empty java.util.Properties object. This method
  41. * never returns null.
  42. *
  43. * @return The environment properties for the enterprise bean.
  44. *
  45. * @deprecated Use the JNDI naming context java:comp/env to access
  46. * enterprise bean's environment.
  47. */
  48. Properties getEnvironment();
  49. /**
  50. * Obtain the java.security.Identity of the caller.
  51. *
  52. * This method is deprecated in EJB 1.1. The Container
  53. * is allowed to return alway null from this method. The enterprise
  54. * bean should use the getCallerPrincipal method instead.
  55. *
  56. * @return The Identity object that identifies the caller.
  57. *
  58. * @deprecated Use Principal getCallerPrincipal() instead.
  59. */
  60. Identity getCallerIdentity();
  61. /**
  62. * Obtain the java.security.Principal that identifies the caller.
  63. *
  64. * @return The Principal object that identifies the caller. This
  65. * method never returns null.
  66. */
  67. Principal getCallerPrincipal();
  68. /**
  69. * Test if the caller has a given role.
  70. *
  71. * <p>This method is deprecated in EJB 1.1. The enterprise bean
  72. * should use the isCallerInRole(String roleName) method instead.
  73. *
  74. * @param role The java.security.Identity of the role to be tested.
  75. *
  76. * @return True if the caller has the specified role.
  77. *
  78. * @deprecated Use boolean isCallerInRole(String roleName) instead.
  79. */
  80. boolean isCallerInRole(Identity role);
  81. /**
  82. * Test if the caller has a given security role.
  83. *
  84. * @param roleName The name of the security role. The role must be one of
  85. * the security roles that is defined in the deployment descriptor.
  86. *
  87. * @return True if the caller has the specified role.
  88. */
  89. boolean isCallerInRole(String roleName);
  90. /**
  91. * Obtain the transaction demarcation interface.
  92. *
  93. * Only enterprise beans with bean-managed transactions are allowed to
  94. * to use the UserTransaction interface. As entity beans must always use
  95. * container-managed transactions, only session beans with bean-managed
  96. * transactions are allowed to invoke this method.
  97. *
  98. * @return The UserTransaction interface that the enterprise bean
  99. * instance can use for transaction demarcation.
  100. *
  101. * @exception IllegalStateException The Container throws the exception
  102. * if the instance is not allowed to use the UserTransaction interface
  103. * (i.e. the instance is of a bean with container-managed transactions).
  104. */
  105. UserTransaction getUserTransaction() throws IllegalStateException;
  106. /**
  107. * Mark the current transaction for rollback. The transaction will become
  108. * permanently marked for rollback. A transaction marked for rollback
  109. * can never commit.
  110. *
  111. * Only enterprise beans with container-managed transactions are allowed
  112. * to use this method.
  113. *
  114. * @exception IllegalStateException The Container throws the exception
  115. * if the instance is not allowed to use this method (i.e. the
  116. * instance is of a bean with bean-managed transactions).
  117. */
  118. void setRollbackOnly() throws IllegalStateException;
  119. /**
  120. * Test if the transaction has been marked for rollback only. An enterprise
  121. * bean instance can use this operation, for example, to test after an
  122. * exception has been caught, whether it is fruitless to continue
  123. * computation on behalf of the current transaction.
  124. *
  125. * Only enterprise beans with container-managed transactions are allowed
  126. * to use this method.
  127. *
  128. * @return True if the current transaction is marked for rollback, false
  129. * otherwise.
  130. *
  131. * @exception IllegalStateException The Container throws the exception
  132. * if the instance is not allowed to use this method (i.e. the
  133. * instance is of a bean with bean-managed transactions).
  134. */
  135. boolean getRollbackOnly() throws IllegalStateException;
  136. }