View Javadoc

1   /*** 
2    * JFoxSOAF, Service-Oriented Application Framework
3    * 
4    * Copyright (C) www.huihoo.org
5    *
6    * Distributable under GNU LGPL
7    * 
8    * For more information, please visit: http://www.huihoo.org/jfox/jfoxsoaf
9    */
10  
11  package org.huihoo.jfox.soaf.services.ejb;
12  
13  import java.lang.reflect.InvocationTargetException;
14  import java.lang.reflect.Method;
15  
16  import javax.ejb.EJBException;
17  import javax.ejb.EJBHome;
18  import javax.ejb.EJBLocalHome;
19  
20  import org.huihoo.jfox.soaf.exception.ServiceLocatorException;
21  
22  /***
23   * <p>
24   * EJBProxyService Implementation.
25   * </p>
26   * 
27   * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
28   * @version $Revision: 1.2 $ $Date: 2004/11/22 15:19:08 $
29   * @version Revision: 1.0
30   */
31  
32  public class EJBProxyServiceImpl implements EJBProxyService {
33  
34      private ServiceLocator serviceLocator;
35  
36      public EJBProxyServiceImpl(ServiceLocator serviceLocator) {
37          this.serviceLocator = serviceLocator;
38      }
39  
40      /***
41       * @see org.huihoo.jfox.soaf.services.ejb.EJBProxyService#getRemoteObject(java.lang.String)
42       */
43      public Object getRemoteObject(String jndiName) throws EJBException {
44          try {
45              EJBHome ejbHome = serviceLocator.getRemoteHome(jndiName,
46                      EJBHome.class);
47              //get the method of create
48              Method method = ejbHome.getClass().getDeclaredMethod("create",
49                      new Class[0]);
50              Object obj = method.invoke(ejbHome, new Object[0]);
51              return obj;
52          } catch (ServiceLocatorException e) {
53              throw new EJBException(e);
54          } catch (SecurityException e) {
55              throw new EJBException(e);
56          } catch (IllegalArgumentException e) {
57              throw new EJBException(e);
58          } catch (NoSuchMethodException e) {
59              throw new EJBException(e);
60          } catch (IllegalAccessException e) {
61              throw new EJBException(e);
62          } catch (InvocationTargetException e) {
63              throw new EJBException(e);
64          }
65      }
66  
67      /***
68       * @see org.huihoo.jfox.soaf.services.ejb.EJBProxyService#getLocalObject(java.lang.String)
69       */
70      public Object getLocalObject(String jndiName) throws EJBException {
71          Object obj;
72          try {
73              EJBLocalHome ejbLocalHome = serviceLocator.getLocalHome(jndiName);
74              Method method = ejbLocalHome.getClass().getDeclaredMethod("create",
75                      new Class[0]);
76              obj = method.invoke(ejbLocalHome, new Object[0]);
77              return obj;
78          } catch (ServiceLocatorException e) {
79              throw new EJBException(e);
80          } catch (SecurityException e) {
81              throw new EJBException(e);
82          } catch (IllegalArgumentException e) {
83              throw new EJBException(e);
84          } catch (NoSuchMethodException e) {
85              throw new EJBException(e);
86          } catch (IllegalAccessException e) {
87              throw new EJBException(e);
88          } catch (InvocationTargetException e) {
89              throw new EJBException(e);
90          }
91      }
92  
93  }