KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > containers > MessageBeanContextImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.ejb.containers;
24
25 import java.rmi.RemoteException JavaDoc;
26 import java.security.Principal JavaDoc;
27
28 import javax.ejb.*;
29 import javax.jms.*;
30
31 import javax.transaction.UserTransaction JavaDoc;
32
33 import com.sun.ejb.*;
34 import com.sun.enterprise.*;
35 import com.sun.enterprise.log.Log;
36 import java.util.logging.*;
37 import com.sun.logging.*;
38
39 /**
40  * Implementation of EJBContext for message-driven beans
41  *
42  * @author Kenneth Saks
43  */

44
45 public final class MessageBeanContextImpl extends EJBContextImpl implements MessageDrivenContext
46 {
47     private static Logger _logger=null;
48     static{
49        _logger=LogDomains.getLogger(LogDomains.MDB_LOGGER);
50         }
51
52     private boolean afterSetContext = false;
53
54     MessageBeanContextImpl(Object JavaDoc ejb, BaseContainer container)
55     {
56         super(ejb, container);
57     }
58
59     void setEJBStub(EJBObject ejbStub)
60     {
61     throw new RuntimeException JavaDoc("No stubs for Message-driven beans");
62     }
63
64     void setEJBObjectImpl(EJBObjectImpl ejbo)
65     {
66     throw new RuntimeException JavaDoc("No EJB Object for Message-driven beans");
67     }
68
69     EJBObjectImpl getEJBObjectImpl()
70     {
71     throw new RuntimeException JavaDoc("No EJB Object for Message-driven beans");
72     }
73
74     public void setContextCalled() {
75         this.afterSetContext = true;
76     }
77
78     /*****************************************************************
79      * The following are implementations of EJBContext methods.
80      ******************************************************************/

81
82     /**
83      *
84      */

85     public UserTransaction JavaDoc getUserTransaction()
86     throws java.lang.IllegalStateException JavaDoc
87     {
88     // The state check ensures that an exception is thrown if this
89
// was called from the constructor or setMessageDrivenContext.
90
// The remaining checks are performed by the container.
91
if ( !this.afterSetContext ) {
92         throw new java.lang.IllegalStateException JavaDoc("Operation not allowed");
93         }
94
95     return ((BaseContainer)getContainer()).getUserTransaction();
96     }
97
98     /*
99      * Doesn't make any sense to get EJBHome object for
100      * a message-driven ejb.
101      */

102     public EJBHome getEJBHome()
103     {
104         RuntimeException JavaDoc exception = new java.lang.IllegalStateException JavaDoc
105             ("getEJBHome not allowed for message-driven beans");
106         throw exception;
107     }
108
109     public boolean isCallerInRole(String JavaDoc roleRef)
110     {
111         throw new java.lang.IllegalStateException JavaDoc("isCallerInRole() is not defined for message-driven ejbs");
112     }
113
114     protected void checkAccessToCallerSecurity()
115         throws java.lang.IllegalStateException JavaDoc
116     {
117         // A message-driven ejb's state transitions past UNINITIALIZED
118
// AFTER ejbCreate
119
if ( isUnitialized() || isInEjbRemove() ) {
120             throw new java.lang.IllegalStateException JavaDoc("Operation not allowed");
121         }
122
123     }
124     
125     public TimerService getTimerService()
126         throws java.lang.IllegalStateException JavaDoc {
127
128         if( !afterSetContext ) {
129             throw new java.lang.IllegalStateException JavaDoc("Operation not allowed");
130         }
131
132         ContainerFactoryImpl cf = (ContainerFactoryImpl)
133             Switch.getSwitch().getContainerFactory();
134         EJBTimerService timerService = cf.getEJBTimerService();
135         if( timerService == null ) {
136             throw new EJBException("EJB Timer service not available");
137         }
138         return new EJBTimerServiceWrapper(timerService, this);
139     }
140
141     public void checkTimerServiceMethodAccess()
142         throws java.lang.IllegalStateException JavaDoc {
143
144         // A message-driven ejb's state transitions past UNINITIALIZED
145
// AFTER ejbCreate
146
if ( isUnitialized() || isInEjbRemove() ) {
147             throw new java.lang.IllegalStateException JavaDoc
148                 ("EJB Timer Service method calls cannot be called in " +
149                  " this context");
150         }
151     }
152
153 }
154
Popular Tags