KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > container > mdb > MDBFactory


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: MDBFactory.java 1121 2006-09-27 08:51:06Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.container.mdb;
27
28 import org.objectweb.easybeans.api.EZBContainer;
29 import org.objectweb.easybeans.api.FactoryException;
30 import org.objectweb.easybeans.api.bean.EasyBeansMDB;
31 import org.objectweb.easybeans.api.bean.info.IBeanInfo;
32 import org.objectweb.easybeans.api.pool.PoolException;
33 import org.objectweb.easybeans.container.AbsFactory;
34 import org.objectweb.easybeans.container.info.MessageDrivenInfo;
35 import org.objectweb.easybeans.log.JLog;
36 import org.objectweb.easybeans.log.JLogFactory;
37 import org.objectweb.easybeans.pool.JPool;
38 import org.objectweb.easybeans.pool.PoolEntryStatistics;
39 import org.objectweb.easybeans.pool.PoolFactory;
40 import org.objectweb.easybeans.rpc.api.EJBRequest;
41 import org.objectweb.easybeans.rpc.api.EJBResponse;
42
43 /**
44  * This classes is reponsible to manage the MDB objects.<br />
45  * Each MDB object (EasyBeansMDB) has a link to a MessageEndPoint object. The
46  * internal message endpoint object is used by the resource adapter with the
47  * help of the message end point factory.
48  * @author Florent Benoit
49  */

50 public class MDBFactory extends AbsFactory<EasyBeansMDB> implements PoolFactory<EasyBeansMDB, Long JavaDoc> {
51
52     /**
53      * Logger.
54      */

55     private static JLog logger = JLogFactory.getLog(MDBFactory.class);
56
57     /**
58      * Runtime information about the session bean.
59      */

60     private MessageDrivenInfo messageDrivenInfo = null;
61
62     /**
63      * Builds a new MDB factory with a given name and its container.
64      * @param className name of this factory (name of class that is managed)
65      * @param container the root component of this factory.
66      * @throws FactoryException if class can't be loaded.
67      */

68     public MDBFactory(final String JavaDoc className, final EZBContainer container) throws FactoryException {
69         super(className, container);
70         setPool(new JPool<EasyBeansMDB, Long JavaDoc>(this));
71     }
72
73     /**
74      * A request comes to the bean factory and needs to be handled.<br>
75      * A response is done which contains the answer.
76      * @param request the EJB request.
77      * @return a response that have been processed by the factory.
78      */

79     @Override JavaDoc
80     public EJBResponse rpcInvoke(final EJBRequest request) {
81         // Not used by MDB : Invocation is done by Resource Adapter on Message
82
// End Point
83
return null;
84     }
85
86     /**
87      * Do a local call on a method of this factory.
88      * @param hash the hash of the method to execute.
89      * @param methodArgs the arguments of the method
90      * @param beanId the id of the bean that we want (stateful).
91      * @return response container new id (if any) and value.
92      */

93     public EJBResponse localCall(final long hash, final Object JavaDoc[] methodArgs, final Long JavaDoc beanId) {
94         // Not used by MDB : Invocation is done by Resource Adapter on Message
95
// End Point
96
return null;
97     }
98
99     /**
100      * Stops the factory.
101      */

102     public void stop() {
103         // remove pool
104
try {
105             getPool().stop();
106         } catch (PoolException e) {
107             logger.error("Problem when stopping the factory", e);
108         }
109     }
110
111     /**
112      * @return information of the current bean.
113      */

114     public IBeanInfo getBeanInfo() {
115         return messageDrivenInfo;
116     }
117
118     /**
119      * @return information of the current bean.
120      */

121     public MessageDrivenInfo getMessageDrivenInfo() {
122         return messageDrivenInfo;
123     }
124
125     /**
126      * Sets the information object for a session bean.
127      * @param messageDrivenInfo information on the bean.
128      */

129     public void setMessageDrivenInfo(final MessageDrivenInfo messageDrivenInfo) {
130         this.messageDrivenInfo = messageDrivenInfo;
131     }
132
133     /**
134      * Creates an instance with the given hint.
135      * @param clue a clue given by the Pool. Could be null.
136      * @throws PoolException if instance cannot be created.
137      * @return the created instance.
138      */

139     public EasyBeansMDB create(final Long JavaDoc clue) throws PoolException {
140         EasyBeansMDB instance = null;
141         try {
142             instance = getBeanClass().newInstance();
143         } catch (InstantiationException JavaDoc e) {
144             throw new PoolException("Cannot create a new instance", e);
145         } catch (IllegalAccessException JavaDoc e) {
146             throw new PoolException("Cannot create a new instance", e);
147         }
148
149         // Set the factory
150
instance.setEasyBeansFactory(this);
151
152         // Init the MDB context
153
EasyBeansMDBContext mdbContext = new EasyBeansMDBContext(instance);
154         instance.setEasyBeansContext(mdbContext);
155
156         ClassLoader JavaDoc oldClassLoader = Thread.currentThread().getContextClassLoader();
157         Thread.currentThread().setContextClassLoader(getContainer().getClassLoader());
158         try {
159             // Call injection
160
injectResources(instance);
161
162             // post construct callback
163
instance.postConstructEasyBeansLifeCycle();
164         } finally {
165             Thread.currentThread().setContextClassLoader(oldClassLoader);
166         }
167
168         return instance;
169     }
170
171     /**
172      * Checks if the given object with the given clue is matching.
173      * @param object given object against which the check should be done.
174      * @param clue the object used as clue to check the matching.
175      * @return true if it is matching, else false.
176      */

177     public boolean isMatching(final EasyBeansMDB object, final Long JavaDoc clue) {
178         // all instances are matching.
179
// But we shouldn't go here as we can use any instance.
180
return true;
181     }
182
183     /**
184      * Validate an instance by giving some statistics.
185      * @param object the instance to validate
186      * @param stats some statistics to help in the validating process.
187      * @return true if the element is valid, else false.
188      */

189     public boolean validate(final EasyBeansMDB object, final PoolEntryStatistics stats) {
190         return true;
191     }
192
193
194 }
195
Popular Tags