001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package javax.ejb;
037:
038: import java.util.*;
039: import java.security.Identity;
040: import java.security.Principal;
041: import javax.transaction.UserTransaction;
042:
043: /**
044: * The EJBContext interface provides an instance with access to the
045: * container-provided runtime context of an enterprise Bean instance.
046: *
047: * <p> This interface is extended by the SessionContext, EntityContext,
048: * and MessageDrivenContext interfaces to provide additional methods
049: * specific to the enterprise interface Bean type.
050: *
051: */
052: public interface EJBContext {
053: /**
054: * Obtain the enterprise bean's remote home interface.
055: *
056: * @return The enterprise bean's remote home interface.
057: *
058: * @exception java.lang.IllegalStateException if the enterprise bean
059: * does not have a remote home interface.
060: */
061: EJBHome getEJBHome();
062:
063: /**
064: * Obtain the enterprise bean's local home interface.
065: *
066: * @return The enterprise bean's local home interface.
067: *
068: * @exception java.lang.IllegalStateException if the enterprise bean
069: * does not have a local home interface.
070: */
071: EJBLocalHome getEJBLocalHome();
072:
073: /**
074: * Obtain the enterprise bean's environment properties.
075: *
076: * <p><b>Note:</b> If the enterprise bean has no environment properties
077: * this method returns an empty java.util.Properties object. This method
078: * never returns null.
079: *
080: * @return The environment properties for the enterprise bean.
081: *
082: * @deprecated Use the JNDI naming context java:comp/env to access
083: * enterprise bean's environment.
084: */
085: Properties getEnvironment();
086:
087: /**
088: * Obtain the java.security.Identity of the caller.
089: *
090: * This method is deprecated in EJB 1.1. The Container
091: * is allowed to return alway null from this method. The enterprise
092: * bean should use the getCallerPrincipal method instead.
093: *
094: * @return The Identity object that identifies the caller.
095: *
096: * @deprecated Use Principal getCallerPrincipal() instead.
097: */
098: Identity getCallerIdentity();
099:
100: /**
101: * Obtain the java.security.Principal that identifies the caller.
102: *
103: * @return The Principal object that identifies the caller. This
104: * method never returns null.
105: *
106: * @exception IllegalStateException The Container throws the exception
107: * if the instance is not allowed to call this method.
108: */
109: Principal getCallerPrincipal();
110:
111: /**
112: * Test if the caller has a given role.
113: *
114: * <p>This method is deprecated in EJB 1.1. The enterprise bean
115: * should use the isCallerInRole(String roleName) method instead.
116: *
117: * @param role The java.security.Identity of the role to be tested.
118: *
119: * @return True if the caller has the specified role.
120: *
121: * @deprecated Use boolean isCallerInRole(String roleName) instead.
122: */
123: boolean isCallerInRole(Identity role);
124:
125: /**
126: * Test if the caller has a given security role.
127: *
128: * @param roleName The name of the security role. The role must be one of
129: * the security roles that is defined in the deployment descriptor.
130: *
131: * @return True if the caller has the specified role.
132: *
133: * @exception IllegalStateException The Container throws the exception
134: * if the instance is not allowed to call this method.
135: */
136: boolean isCallerInRole(String roleName);
137:
138: /**
139: * Obtain the transaction demarcation interface.
140: *
141: * Only enterprise beans with bean-managed transactions are allowed to
142: * to use the UserTransaction interface. As entity beans must always use
143: * container-managed transactions, only session beans or message-driven
144: * beans with bean-managed transactions are allowed to invoke this method.
145: *
146: * @return The UserTransaction interface that the enterprise bean
147: * instance can use for transaction demarcation.
148: *
149: * @exception IllegalStateException The Container throws the exception
150: * if the instance is not allowed to use the UserTransaction interface
151: * (i.e. the instance is of a bean with container-managed transactions).
152: */
153: UserTransaction getUserTransaction() throws IllegalStateException;
154:
155: /**
156: * Mark the current transaction for rollback. The transaction will become
157: * permanently marked for rollback. A transaction marked for rollback
158: * can never commit.
159: *
160: * Only enterprise beans with container-managed transactions are allowed
161: * to use this method.
162: *
163: * @exception IllegalStateException The Container throws the exception
164: * if the instance is not allowed to use this method (i.e. the
165: * instance is of a bean with bean-managed transactions).
166: */
167: void setRollbackOnly() throws IllegalStateException;
168:
169: /**
170: * Test if the transaction has been marked for rollback only. An enterprise
171: * bean instance can use this operation, for example, to test after an
172: * exception has been caught, whether it is fruitless to continue
173: * computation on behalf of the current transaction.
174: *
175: * Only enterprise beans with container-managed transactions are allowed
176: * to use this method.
177: *
178: * @return True if the current transaction is marked for rollback, false
179: * otherwise.
180: *
181: * @exception IllegalStateException The Container throws the exception
182: * if the instance is not allowed to use this method (i.e. the
183: * instance is of a bean with bean-managed transactions).
184: */
185: boolean getRollbackOnly() throws IllegalStateException;
186:
187: /**
188: * Get access to the EJB Timer Service.
189: *
190: * @exception IllegalStateException The Container throws the exception
191: * if the instance is not allowed to use this method (e.g. if the bean
192: * is a stateful session bean)
193: */
194: TimerService getTimerService() throws IllegalStateException;
195:
196: /**
197: * Lookup a resource within the component's private naming context.
198: *
199: * @param name Name of the entry (relative to java:comp/env).
200: *
201: * @exception IllegalArgumentException The Container throws the exception
202: * if the given name does not match an entry within the component's
203: * environment.
204: */
205: Object lookup(String name);
206:
207: }
|