1   
2   
3   
4   
5   
6   
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.descriptor.ProviderServiceDescriptor;
13  import it.imolinfo.jbi4ejb.exception.EJBDeployException;
14  import it.imolinfo.jbi4ejb.exception.EJBInvokeException;
15  import it.imolinfo.jbi4ejb.exception.EJBWSDLGenerationException;
16  import it.imolinfo.jbi4ejb.jbi.Messages;
17  import it.imolinfo.jbi4ejb.webservice.generator.Util;
18  
19  import java.io.File;
20  import java.net.MalformedURLException;
21  import java.util.List;
22  import java.util.Properties;
23  
24  import org.omg.CORBA.ORB;
25  
26  
27  
28  
29  
30  
31  public final class StatelessEJBProxyFactory {
32  
33      
34      private static final Logger LOG
35      = LoggerFactory.getLogger(StatelessEJBProxyFactory.class);
36      private static final Messages MESSAGES
37      = Messages.getMessages(StatelessEJBProxyFactory.class);
38      
39      
40  
41  
42      private StatelessEJBProxyFactory() {}
43      
44      
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61      @SuppressWarnings("unchecked")
62      public static StatelessEJBProxy createEJBProxy(File wsdl, ProviderServiceDescriptor serviceDescriptor, File tempDir, List<String> jarFilesName) throws EJBDeployException {       
63  
64          
65          String portTypeName = serviceDescriptor.getPortTypeName().getLocalPart();
66          
67          
68          EJBClasses ejbClasses = EJBProxyUtils.createEJBClasses(wsdl, serviceDescriptor.getSerialVersionUID(), tempDir, jarFilesName, null, portTypeName);
69          
70          
71          ClassLoader ejbInvokeClassLoader;
72          try {
73              ejbInvokeClassLoader = Util.getURLClassLoader(ejbClasses.getEjbClassesPath());
74          } catch (MalformedURLException e) {
75          	String msg=MESSAGES.getString("EJB000917_Exception_creating_URL_ClassLoder", new Object[]{e.getMessage()});
76              LOG.error(msg,e);
77              throw new EJBDeployException(msg,e);
78          }
79  
80          
81          ORB orb = ORB.init(new String[]{}, serviceDescriptor.getOrbProperties());
82  
83          
84          Object remoteBean = EJBProxyUtils.createStatelessEJBFromCorbaName(serviceDescriptor.getName(), ejbClasses.getRemoteInterfaceClassName(), ejbInvokeClassLoader, orb);
85  
86          
87          StatelessEJBProxy ejbProxy = new StatelessEJBProxy(ejbClasses.getRemoteInterfaceClassName(), remoteBean, ejbInvokeClassLoader, orb);
88  
89          
90          try {
91              Class myRemoteInterface = ejbInvokeClassLoader.loadClass(ejbClasses.getRemoteInterfaceClassName());
92              ejbProxy.setRemoteInterfaceClass(myRemoteInterface);
93              
94          } catch (ClassNotFoundException e) {
95          	String msg=MESSAGES.getString("EJB000918_Exception_getting_remote_interface_class", new Object[]{e.getMessage()});
96              LOG.error(msg,e);
97              throw new EJBDeployException(msg,e);
98          }
99  
100         return ejbProxy;
101     }    
102 
103     
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123     @SuppressWarnings("unchecked")
124     public static StatelessEJBProxy getEJBFromCorbaname(String wsdlPath, String remoteInterfaceClassName, String corbaName
125             , Properties classesId, List<String> jarFilesName, Properties orbParams) throws EJBWSDLGenerationException {
126         return getEJBFromCorbaname(wsdlPath, remoteInterfaceClassName, corbaName, classesId, jarFilesName, orbParams, false);
127     }
128 
129     
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150     @SuppressWarnings("unchecked")
151     public static StatelessEJBProxy getEJBFromCorbanameUsingRMIClassloader(String wsdlPath, String remoteInterfaceClassName, String corbaName
152             , Properties classesId, List<String> jarFilesName, Properties orbParams) throws EJBWSDLGenerationException {
153         return getEJBFromCorbaname(wsdlPath, remoteInterfaceClassName, corbaName, classesId, jarFilesName, orbParams, true);
154     }
155     
156     
157 
158 
159 
160 
161 
162 
163 
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179     @SuppressWarnings("unchecked")
180     public static StatelessEJBProxy getEJBFromJNDIName(String wsdlPath, String remoteInterfaceClassName, String jndiName, Properties jndiParams,
181             Properties orbProperties, Properties classesId, List<String> jarFilesName) throws EJBWSDLGenerationException {         
182 
183         ClassLoader ejbInvokeClassLoader = null;
184         Object remoteBean = null;
185         try {               
186 
187             
188             String classesDir = EJBProxyUtils.createEJBClasses(wsdlPath, remoteInterfaceClassName, null, classesId, jarFilesName);                       
189 
190             LOG.debug("The classes are in the directory:" + classesDir);
191 
192             
193             ejbInvokeClassLoader = Util.getURLClassLoader(classesDir);
194 
195             
196             
197             ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader(); 
198             Thread.currentThread().setContextClassLoader(ejbInvokeClassLoader);
199             
200             
201             org.omg.CORBA.portable.ObjectImpl remoteHome = EJBProxyUtils.createStatelessHomeFromJNDI(jndiName, jndiParams, remoteInterfaceClassName, ejbInvokeClassLoader);
202             
203             
204             ORB orb = remoteHome._orb();               
205 
206             LOG.info("EJB000911_ORB_found", new Object[]{orb});    
207             
208             remoteBean = EJBProxyUtils.getEJBFromCorbaHomeObject(remoteHome, orb, remoteInterfaceClassName, ejbInvokeClassLoader);        
209 
210             
211             Thread.currentThread().setContextClassLoader(previousClassLoader);
212                         
213             StatelessEJBProxy ejbProxy = new StatelessEJBProxy(remoteInterfaceClassName, remoteBean, ejbInvokeClassLoader, orb);
214 
215             return ejbProxy;
216 
217         } catch (Exception ex) {
218             String msg=MESSAGES.getString("EJB000919_getEJBFromJNDIName", new Object[]{ex.getMessage()});
219             LOG.error(msg,ex);
220             throw new EJBWSDLGenerationException(msg,ex);
221         }
222     }        
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
250 @SuppressWarnings("unchecked")
251 public static StatelessEJBProxy getEJBFromCorbaname(String wsdlPath, String remoteInterfaceClassName, String corbaName
252         , Properties classesId, List<String> jarFilesName, Properties orbParams, boolean dynamicClassLoading) throws EJBWSDLGenerationException {
253 
254     ClassLoader ejbInvokeClassLoader = null;
255     Object remoteBean = null;
256     try {            
257         
258         ORB orb = null;
259         if (orbParams != null) {
260             orb = ORB.init(new String[]{}, orbParams);
261         } else {
262             orb = ORB.init(new String[]{}, new Properties());
263         }        
264 
265         if (!dynamicClassLoading) {                                           
266 
267             
268             String classesDir = EJBProxyUtils.createEJBClasses(wsdlPath, remoteInterfaceClassName, null, classesId, jarFilesName);
269 
270             LOG.debug("The ejb client classes are in the directory:" + classesDir);
271 
272             
273             ejbInvokeClassLoader = Util.getURLClassLoader(classesDir);
274 
275             
276             remoteBean = EJBProxyUtils.createStatelessEJBFromCorbaName(corbaName, remoteInterfaceClassName, ejbInvokeClassLoader, orb);            
277         } else {
278 
279             
280             LOG.debug("Dynamic invocation, classes loaded using RMI");         
281 
282             Class myRemoteInterfaceClass = EJBProxyUtils.getInterfaceClass(remoteInterfaceClassName, wsdlPath, jarFilesName);
283 
284             LOG.debug("Loaded remote interface: " + myRemoteInterfaceClass);
285 
286             remoteBean = EJBProxyUtils.createStatelessEJBUsingRMIClassLoader(corbaName, remoteInterfaceClassName, myRemoteInterfaceClass, orb);
287         }
288         StatelessEJBProxy ejbProxy = new StatelessEJBProxy(remoteInterfaceClassName, remoteBean, ejbInvokeClassLoader, orb);
289 
290         return ejbProxy;
291 
292     } catch (Exception ex) {
293         
294         
295         
296         String msg=MESSAGES.getString("EJB000920_getEJBFromCorbaname", new Object[]{ex.getMessage()});
297         LOG.error(msg,ex);
298         throw new EJBWSDLGenerationException(msg,ex);
299     }
300 }
301 
302 
303 }