KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > server > ejbd > ClientObjectFactory


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "OpenEJB" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of The OpenEJB Group. For written permission,
18  * please contact dev@openejb.org.
19  *
20  * 4. Products derived from this Software may not be called "OpenEJB"
21  * nor may "OpenEJB" appear in their names without prior written
22  * permission of The OpenEJB Group. OpenEJB is a registered
23  * trademark of The OpenEJB Group.
24  *
25  * 5. Due credit should be given to the OpenEJB Project
26  * (http://www.openejb.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
42  *
43  * $Id: ClientObjectFactory.java 2475 2006-02-21 00:18:55Z dblevins $
44  */

45 package org.openejb.server.ejbd;
46
47 import java.net.URI JavaDoc;
48
49 import org.openejb.DeploymentInfo;
50 import org.openejb.ProxyInfo;
51 import org.openejb.client.ClientMetaData;
52 import org.openejb.client.EJBHomeHandle;
53 import org.openejb.client.EJBHomeHandler;
54 import org.openejb.client.EJBMetaDataImpl;
55 import org.openejb.client.EJBObjectHandle;
56 import org.openejb.client.EJBObjectHandler;
57 import org.openejb.client.ServerMetaData;
58
59
60 /**
61  * The implementation of ApplicationServer used to create all client-side
62  * implementations of the javax.ejb.* interaces as
63  *
64  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
65  */

66 class ClientObjectFactory implements org.openejb.spi.ApplicationServer {
67     private final EjbDaemon daemon;
68
69     protected ServerMetaData sMetaData;
70
71     public ClientObjectFactory(EjbDaemon daemon) {
72
73         try {
74             this.sMetaData = new ServerMetaData(new URI JavaDoc("foo://"+"127.0.0.1" +":"+4201));
75         } catch (Exception JavaDoc e) {
76
77             e.printStackTrace();
78         }
79         this.daemon = daemon;
80     }
81
82     public javax.ejb.EJBMetaData JavaDoc getEJBMetaData(ProxyInfo info) {
83         CallContext call = CallContext.getCallContext();
84         return _getEJBMetaData(call, info);
85     }
86
87     /**
88      * Creates a Handle object that can be serialized and
89      * sent to the client.
90      *
91      * @param info
92      *
93      * @return Handle
94      */

95     public javax.ejb.Handle JavaDoc getHandle(ProxyInfo info) {
96         CallContext call = CallContext.getCallContext();
97         return _getHandle(call, info);
98     }
99
100     /**
101      * Creates a HomeHandle object that can be serialized and
102      * sent to the client.
103      *
104      * @param info
105      *
106      * @return HomeHandle
107      */

108     public javax.ejb.HomeHandle JavaDoc getHomeHandle(ProxyInfo info) {
109         CallContext call = CallContext.getCallContext();
110         return _getHomeHandle(call, info);
111     }
112
113     /**
114      * Creates an EJBObject object that can be serialized and
115      * sent to the client.
116      *
117      * @param info
118      *
119      * @return EJBObject
120      */

121     public javax.ejb.EJBObject JavaDoc getEJBObject(ProxyInfo info) {
122         CallContext call = CallContext.getCallContext();
123         return _getEJBObject(call, info);
124     }
125
126     /**
127      * Creates an EJBHome object that can be serialized and
128      * sent to the client.
129      *
130      * @param info
131      *
132      * @return EJBHome
133      */

134     public javax.ejb.EJBHome JavaDoc getEJBHome(ProxyInfo info) {
135         CallContext call = CallContext.getCallContext();
136         return _getEJBHome(call, info);
137     }
138
139     /**
140      * Creates an EJBMetaDataImpl object that can be serialized and
141      * sent to the client.
142      *
143      * @param call
144      * @param info
145      *
146      * @return EJBMetaData
147      * @see org.openejb.client.EJBMetaDataImpl
148      */

149     protected javax.ejb.EJBMetaData JavaDoc _getEJBMetaData(CallContext call, ProxyInfo info) {
150
151         DeploymentInfo deployment = info.getDeploymentInfo();
152         int idCode = this.daemon.deploymentIndex.getDeploymentIndex(deployment);
153
154         EJBMetaDataImpl metaData = new EJBMetaDataImpl(deployment.getHomeInterface(),
155                                                        deployment.getRemoteInterface(),
156                                                        deployment.getPrimaryKeyClass(),
157                                                        deployment.getComponentType(),
158                                                        deployment.getDeploymentID().toString(),
159                                                        idCode);
160         return metaData;
161     }
162
163     /**
164      * Creates an EJBMetaDataImpl object that can be serialized and
165      * sent to the client.
166      *
167      * @param call
168      * @param info
169      *
170      * @return Handle
171      * @see org.openejb.client.EJBObjectHandle
172      */

173     protected javax.ejb.Handle JavaDoc _getHandle(CallContext call, ProxyInfo info) {
174         DeploymentInfo deployment = info.getDeploymentInfo();
175
176         int idCode = this.daemon.deploymentIndex.getDeploymentIndex(deployment);
177
178         Object JavaDoc securityIdentity = null;
179         try {
180             securityIdentity = call.getEJBRequest().getClientIdentity();
181         } catch (Exception JavaDoc e) {
182             //e.printStackTrace(); not needed
183
}
184         ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
185         EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(deployment.getHomeInterface(),
186                                                         deployment.getRemoteInterface(),
187                                                         deployment.getPrimaryKeyClass(),
188                                                         deployment.getComponentType(),
189                                                         deployment.getDeploymentID().toString(),
190                                                         idCode);
191         Object JavaDoc primKey = info.getPrimaryKey();
192
193         EJBObjectHandler hanlder = EJBObjectHandler.createEJBObjectHandler(eMetaData,sMetaData,cMetaData,primKey);
194
195         return new EJBObjectHandle( hanlder.createEJBObjectProxy() );
196     }
197
198     /**
199      * Creates an EJBHomeHandle object that can be serialized and
200      * sent to the client.
201      *
202      * @param call
203      * @param info
204      *
205      * @return HomeHandle
206      * @see org.openejb.client.EJBHomeHandle
207      */

208     protected javax.ejb.HomeHandle JavaDoc _getHomeHandle(CallContext call, ProxyInfo info) {
209         DeploymentInfo deployment = info.getDeploymentInfo();
210
211         int idCode = this.daemon.deploymentIndex.getDeploymentIndex(deployment);
212
213         Object JavaDoc securityIdentity = null;
214         try {
215             securityIdentity = call.getEJBRequest().getClientIdentity();
216         } catch (Exception JavaDoc e) {
217             e.printStackTrace();
218         }
219         ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
220         EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(deployment.getHomeInterface(),
221                                                         deployment.getRemoteInterface(),
222                                                         deployment.getPrimaryKeyClass(),
223                                                         deployment.getComponentType(),
224                                                         deployment.getDeploymentID().toString(),
225                                                         idCode);
226
227         EJBHomeHandler hanlder = EJBHomeHandler.createEJBHomeHandler(eMetaData,sMetaData,cMetaData);
228
229         return new EJBHomeHandle( hanlder.createEJBHomeProxy() );
230     }
231
232     /**
233      * Creates an EJBObjectHandler and EJBObject proxy object that can
234      * be serialized and sent to the client.
235      *
236      * @param call
237      * @param info
238      *
239      * @return EJBObject
240      * @see org.openejb.client.EJBObjectHandler
241      */

242     protected javax.ejb.EJBObject JavaDoc _getEJBObject(CallContext call, ProxyInfo info) {
243         DeploymentInfo deployment = info.getDeploymentInfo();
244
245         int idCode = this.daemon.deploymentIndex.getDeploymentIndex(deployment);
246
247         Object JavaDoc securityIdentity = null;
248         try {
249             securityIdentity = call.getEJBRequest().getClientIdentity();
250         } catch (Exception JavaDoc e) {
251             e.printStackTrace();
252         }
253         ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
254         EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(deployment.getHomeInterface(),
255                                                         deployment.getRemoteInterface(),
256                                                         deployment.getPrimaryKeyClass(),
257                                                         deployment.getComponentType(),
258                                                         deployment.getDeploymentID().toString(),
259                                                         idCode);
260         Object JavaDoc primKey = info.getPrimaryKey();
261
262         EJBObjectHandler hanlder = EJBObjectHandler.createEJBObjectHandler(eMetaData,sMetaData,cMetaData,primKey);
263
264         return hanlder.createEJBObjectProxy();
265     }
266
267     /**
268      * Creates an EJBHomeHandler and EJBHome proxy object that can
269      * be serialized and sent to the client.
270      *
271      * @param call
272      * @param info
273      *
274      * @return EJBHome
275      * @see org.openejb.client.EJBHomeHandler
276      */

277     protected javax.ejb.EJBHome JavaDoc _getEJBHome(CallContext call, ProxyInfo info) {
278         DeploymentInfo deployment = info.getDeploymentInfo();
279
280         int idCode = this.daemon.deploymentIndex.getDeploymentIndex(deployment);
281
282         Object JavaDoc securityIdentity = null;
283         try {
284             securityIdentity = call.getEJBRequest().getClientIdentity();
285         } catch (Exception JavaDoc e) {
286             e.printStackTrace();
287         }
288         ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
289         EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(deployment.getHomeInterface(),
290                                                         deployment.getRemoteInterface(),
291                                                         deployment.getPrimaryKeyClass(),
292                                                         deployment.getComponentType(),
293                                                         deployment.getDeploymentID().toString(),
294                                                         idCode);
295
296         EJBHomeHandler hanlder = EJBHomeHandler.createEJBHomeHandler(eMetaData,sMetaData,cMetaData);
297
298         //EJBHomeProxyHandle handle = new EJBHomeProxyHandle( hanlder );
299

300         return hanlder.createEJBHomeProxy();
301     }
302 }
Popular Tags