1 /*******************************************************************************
2 * Copyright (c) 2005, 2006, 2007 Imola Informatica.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the LGPL License v2.1
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 *******************************************************************************/
8 package it.imolinfo.jbi4ejb.runtime.ejbproxy;
9
10 import it.imolinfo.jbi4ejb.Logger;
11 import it.imolinfo.jbi4ejb.LoggerFactory;
12 import it.imolinfo.jbi4ejb.exception.EJBInvokeException;
13
14 import java.lang.reflect.InvocationTargetException;
15 import java.lang.reflect.Method;
16
17 import org.omg.CORBA.ORB;
18
19 /**
20 * The Stateless EJBProxy.
21 *
22 * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
23 */
24 public class StatelessEJBProxy {
25
26 /** The Constant LOG. */
27 private static final Logger LOG
28 = LoggerFactory.getLogger(StatelessEJBProxy.class);
29
30 /** The remote interface class name. */
31 @SuppressWarnings("unused")
32 private String remoteInterfaceClassName = null;
33
34 /** The remote bean. */
35 private Object remoteBean = null;
36
37 /** The ejb ClassLoader. */
38 private ClassLoader ejbInvokeClassLoader = null;
39
40 /** The ejb ClassLoader. */
41 private ORB orb = null;
42
43 /** The my remote interface. */
44 @SuppressWarnings("unchecked")
45 private Class myRemoteInterface = null;
46
47 /**
48 * To avoid istantiation with no parameters.
49 */
50 @SuppressWarnings("unused")
51 private StatelessEJBProxy() {}
52
53 /**
54 * To avoid istantiation with no parameters.
55 *
56 * @param remoteInterfaceClassName
57 * The remote interface class name
58 * @param remoteBean
59 * The remote bean object
60 * @param ejbInvokeClassLoader
61 * The invocation class loader
62 * @param orb
63 * The CORBA ORB
64 */
65 public StatelessEJBProxy(String remoteInterfaceClassName, Object remoteBean, ClassLoader ejbInvokeClassLoader, ORB orb) {
66 this.remoteInterfaceClassName = remoteInterfaceClassName;
67 this.remoteBean = remoteBean;
68 this.ejbInvokeClassLoader = ejbInvokeClassLoader;
69 this.orb = orb;
70 }
71
72
73 /**
74 * Invoke method on the EJB.
75 *
76 * @param methodName
77 * The method to invoke
78 * @param params
79 * The params for the method invocation
80 *
81 * @return the object
82 *
83 * @throws EJBInvokeException
84 * If some problems occurs
85 * @throws EJBInvokeException
86 * if some problem in the EJB invocation occurs
87 * @throws InvocationTargetException
88 * If an exception is thrown in the invokation
89 * @throws IllegalAccessException
90 * If there are access problems
91 */
92 @SuppressWarnings("unchecked")
93 public Object invokeMethod(String methodName, Object[] params) throws EJBInvokeException, IllegalAccessException, InvocationTargetException {
94 if (LOG.isDebugEnabled()) {
95 StringBuffer paramsString = new StringBuffer();
96 for (int i = 0; i < params.length; i++) {
97 paramsString.append("[" + params[i] + "]");
98 }
99 String msg = "EJB Invocation: interface:[" + remoteInterfaceClassName + "], method:[" + methodName + "]"
100 +"params:" + paramsString ;
101 LOG.debug(msg);
102 }
103 return EJBProxyUtils.invokeMethod(remoteBean, methodName, params, ejbInvokeClassLoader, orb);
104 }
105
106 /**
107 * Invoke method on the EJB.
108 *
109 * @param params
110 * The params for the method invocation
111 * @param method
112 * The method to invoke
113 * @return the object
114 * The return object
115 * @throws EJBInvokeException
116 * If some problems occurs in EJB invocation
117 * @throws EJBInvokeException
118 * if some problem in the EJB invocation occurs
119 * @throws InvocationTargetException
120 * If an exception is thrown in the invokation
121 * @throws IllegalAccessException
122 * If there are access problems
123 */
124 @SuppressWarnings("unchecked")
125 public Object invokeMethod(Method method, Object[] params) throws EJBInvokeException, IllegalAccessException, InvocationTargetException {
126
127 if (LOG.isDebugEnabled()) {
128 StringBuffer paramsString = new StringBuffer();
129 for (int i = 0; i < params.length; i++) {
130 paramsString.append("[" + params[i] + "]");
131 }
132 String msg = "EJB Invocation: interface:[" + remoteInterfaceClassName + "], method:[" + method.getName() + "]"
133 +"params:" + paramsString ;
134 LOG.debug(msg);
135 }
136 return EJBProxyUtils.invokeMethod(remoteBean, method, params, ejbInvokeClassLoader, orb);
137 }
138
139 /**
140 * Gets the orb.
141 *
142 * @return the orb
143 */
144 public ORB getOrb() {
145 return orb;
146 }
147
148 /**
149 * Sets the remote interface class.
150 *
151 * @param myRemoteInterFace
152 * The remote interface
153 *
154 * @throws ClassNotFoundException
155 */
156 @SuppressWarnings("unchecked")
157 public void setRemoteInterfaceClass(Class myRemoteInterFace) {
158 this.myRemoteInterface = myRemoteInterFace;
159 }
160
161 /**
162 * Gets the remote interface class.
163 *
164 * @return the remote object interface
165 *
166 * @throws ClassNotFoundException
167 */
168 @SuppressWarnings("unchecked")
169 public Class getRemoteInterfaceClass() {
170 return myRemoteInterface;
171 }
172
173 /**
174 * Gets the remote interface class name.
175 *
176 * @return the remote interface class name
177 */
178 public String getRemoteInterfaceClassName() {
179 return remoteInterfaceClassName;
180 }
181
182 /**
183 * Gets the ejb invoke class loader.
184 *
185 * @return the ejb invoke class loader
186 */
187 public ClassLoader getEjbInvokeClassLoader() {
188 return ejbInvokeClassLoader;
189 }
190
191
192 }