1 /***
2 * @(#)EJBProxyServiceImpl.java
3 *
4 * JFoxSOAF, Service-Oriented Application Framework
5 *
6 * Copyright(c) JFoxSOAF Team
7 *
8 * Licensed under the GNU LGPL, Version 2.1 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.gnu.org/copyleft/lesser.html
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 * For more information, please visit:
21 * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
22 * http://www.huihoo.org/jfox/jfoxsoaf
23 */
24
25 package org.huihoo.jfox.soaf.services.ejb;
26
27 import java.lang.reflect.InvocationTargetException;
28 import java.lang.reflect.Method;
29 import java.rmi.RemoteException;
30
31 import javax.ejb.EJBException;
32 import javax.ejb.EJBHome;
33 import javax.ejb.EJBLocalHome;
34 import javax.ejb.EJBObject;
35 import javax.ejb.FinderException;
36
37 import org.huihoo.jfox.soaf.exception.ServiceLocatorException;
38
39 import com.opensymphony.util.EJBUtils;
40
41 /***
42 * <p>
43 * EJBProxyService Implementation.
44 * </p>
45 *
46 * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
47 * @version $Revision: 1.8 $ $Date: 2005/05/22 06:49:31 $
48 * @version Revision: 1.0
49 */
50
51 public class EJBProxyServiceImpl implements EJBProxyService {
52
53 private ServiceLocator serviceLocator;
54
55 public EJBProxyServiceImpl(ServiceLocator serviceLocator) {
56 this.serviceLocator = serviceLocator;
57 }
58
59 /***
60 * @see org.huihoo.jfox.soaf.services.ejb.EJBProxyService#getRemoteObject(java.lang.String)
61 */
62 public Object getRemoteObject(String jndiName) throws EJBException {
63 try {
64 EJBHome ejbHome = serviceLocator.getRemoteHome(jndiName,
65 EJBHome.class);
66
67 Method method = ejbHome.getClass().getDeclaredMethod("create",
68 new Class[0]);
69 Object obj = method.invoke(ejbHome, new Object[0]);
70 return obj;
71 } catch (ServiceLocatorException e) {
72 throw new EJBException(e);
73 } catch (SecurityException e) {
74 throw new EJBException(e);
75 } catch (IllegalArgumentException e) {
76 throw new EJBException(e);
77 } catch (NoSuchMethodException e) {
78 throw new EJBException(e);
79 } catch (IllegalAccessException e) {
80 throw new EJBException(e);
81 } catch (InvocationTargetException e) {
82 throw new EJBException(e);
83 }
84 }
85
86 /***
87 * @see org.huihoo.jfox.soaf.services.ejb.EJBProxyService#getLocalObject(java.lang.String)
88 */
89 public Object getLocalObject(String jndiName) throws EJBException {
90 Object obj;
91 try {
92 EJBLocalHome ejbLocalHome = serviceLocator.getLocalHome(jndiName);
93 Method method = ejbLocalHome.getClass().getDeclaredMethod("create",
94 new Class[0]);
95 obj = method.invoke(ejbLocalHome, new Object[0]);
96 return obj;
97 } catch (ServiceLocatorException e) {
98 throw new EJBException(e);
99 } catch (SecurityException e) {
100 throw new EJBException(e);
101 } catch (IllegalArgumentException e) {
102 throw new EJBException(e);
103 } catch (NoSuchMethodException e) {
104 throw new EJBException(e);
105 } catch (IllegalAccessException e) {
106 throw new EJBException(e);
107 } catch (InvocationTargetException e) {
108 throw new EJBException(e);
109 }
110 }
111
112 /***
113 * @see org.huihoo.jfox.soaf.services.ejb.EJBProxyService#findEntity(
114 * javax.ejb.EJBHome, java.lang.String)
115 */
116 public EJBObject findEntity(EJBHome home, String id)
117 throws RemoteException, FinderException {
118 return EJBUtils.findEntity(home, id);
119 }
120 }