KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > ejb > support > AbstractMessageDrivenBean


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.ejb.support;
18
19 import javax.ejb.MessageDrivenBean JavaDoc;
20 import javax.ejb.MessageDrivenContext JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 /**
26  * Convenient superclass for MDBs.
27  * Doesn't require JMS, as EJB 2.1 MDBs are no longer JMS-specific;
28  * see the {@link AbstractJmsMessageDrivenBean} subclass.
29  *
30  * <p>This class ensures that subclasses have access to the
31  * MessageDrivenContext provided by the EJB container, and implement
32  * a no-arg <code>ejbCreate()</code> method as required by the EJB
33  * specification. This <code>ejbCreate()</code> method loads a BeanFactory,
34  * before invoking the <code>onEjbCreate()</code> method, which is
35  * supposed to contain subclass-specific initialization.
36  *
37  * <p>NB: We cannot use final methods to implement EJB API methods,
38  * as this violates the EJB specification. However, there should be
39  * no need to override the <code>setMessageDrivenContext</code> or
40  * <code>ejbCreate()</code> methods.
41  *
42  * @author Rod Johnson
43  */

44 public abstract class AbstractMessageDrivenBean extends AbstractEnterpriseBean
45     implements MessageDrivenBean JavaDoc {
46     
47     /** Logger available to subclasses */
48     protected final Log logger = LogFactory.getLog(getClass());
49
50     private MessageDrivenContext JavaDoc messageDrivenContext;
51
52
53     /**
54      * Required lifecycle method. Sets the MessageDriven context.
55      * @param messageDrivenContext MessageDrivenContext
56      */

57     public void setMessageDrivenContext(MessageDrivenContext JavaDoc messageDrivenContext) {
58         this.messageDrivenContext = messageDrivenContext;
59     }
60
61     /**
62      * Convenience method for subclasses to use.
63      * @return the MessageDrivenContext passed to this EJB by the EJB container
64      */

65     protected final MessageDrivenContext JavaDoc getMessageDrivenContext() {
66         return this.messageDrivenContext;
67     }
68
69     /**
70      * Lifecycle method required by the EJB specification but not the
71      * MessageDrivenBean interface. This implementation loads the BeanFactory.
72      * <p>Don't override it (although it can't be made final): code initialization
73      * in onEjbCreate(), which is called when the BeanFactory is available.
74      * <p>Unfortunately we can't load the BeanFactory in setSessionContext(),
75      * as resource manager access isn't permitted and the BeanFactory may require it.
76      */

77     public void ejbCreate() {
78         loadBeanFactory();
79         onEjbCreate();
80     }
81
82     /**
83      * Subclasses must implement this method to do any initialization they would
84      * otherwise have done in an <code>ejbCreate()</code> method. In contrast
85      * to <code>ejbCreate()</code>, the BeanFactory will have been loaded here.
86      * <p>The same restrictions apply to the work of this method as
87      * to an <code>ejbCreate()</code> method.
88      */

89     protected abstract void onEjbCreate();
90
91 }
92
Popular Tags