Source code: com/prolifics/ejb/UCIEJBHelper.java
1 /* @(#)UCIEJBHelper.java 77.5 00/05/01 19:27:29" */
2
3 /*************************************************/
4 /* Copyright (c) 2000 */
5 /* by */
6 /* JYACC, Inc., New York NY USA */
7 /* and contributors. */
8 /* Use of this program is governed by the */
9 /* JYACC Public License Version 1.0, a copy of */
10 /* which can be obtained at */
11 /* http://www.possl.org/jyacc-license.html */
12 /*************************************************/
13
14 package com.prolifics.ejb;
15
16 import java.lang.reflect.*;
17 import java.util.*;
18 import java.rmi.*;
19 import javax.ejb.*;
20 import javax.naming.*;
21 import javax.rmi.*;
22 import com.prolifics.jni.*;
23
24 public class UCIEJBHelper extends UCIHelper implements Constants
25 {
26 public Object createEJB(String name, String where) throws Throwable
27 {
28 debug("createEJB(" + name + ", " + where + ")");
29 Properties p = new Properties();
30 p.put(Context.INITIAL_CONTEXT_FACTORY,
31 "com.ibm.ejs.ns.jndi.CNInitialContextFactory");
32 if (where != null)
33 p.put(Context.PROVIDER_URL, where);
34
35 Context ic = new InitialContext(p);
36 Object o;
37 Class c;
38 try {
39 o = ic.lookup(name);
40 } catch (NameNotFoundException e) {
41 new Error(PR_E_OBJ_TYPE, JV_NOCLASS, name);
42 return null;
43 }
44 try {
45 c = o.getClass();
46 } catch (NoClassDefFoundError e) {
47 new Error(PR_E_OBJ_TYPE, JV_NOCLASS, name);
48 return null;
49 }
50 debug("got class " + c);
51 Method m;
52 try {
53 m = c.getDeclaredMethod("create", new Class[0]);
54 } catch (NoSuchMethodException e) {
55 new Error(PR_E_OBJ_TYPE, JV_NO_CREATE, name);
56 return null;
57 }
58 debug("got create method " + m);
59 try {
60 o = m.invoke(o, new Object[0]);
61 } catch (InvocationTargetException e) {
62 throw e.getTargetException();
63 }
64 String s = m.getReturnType().getName() + "Helper";
65 try {
66 debug("constructing helper");
67 return c.forName(s).
68 getDeclaredConstructor(
69 new Class[] { m.getReturnType() }).
70 newInstance(new Object[] { o });
71 } catch (ClassNotFoundException e) {
72 debug("failed. ClassNotFound");
73 return o;
74 } catch (NoSuchMethodException e) {
75 debug("failed. NoSuchMethod");
76 return o;
77 }
78 }
79 };