1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.smartlab.web;
24
25 import java.io.Serializable;
26 import java.lang.reflect.InvocationTargetException;
27 import java.rmi.RemoteException;
28 import java.util.Collection;
29 import java.util.HashMap;
30 import java.util.Set;
31
32 import javax.ejb.EJBObject;
33 import javax.ejb.SessionBean;
34
35
36
37
38
39 public abstract class EnterpriseDomain implements SessionBean {
40
41 private static final long serialVersionUID = -2893852982428251155L;
42
43
44 public static class RequestContext implements Serializable {
45
46 private static final long serialVersionUID = 2724059707578588014L;
47
48
49
50
51 private HashMap attributes = new HashMap();
52
53
54 public boolean contains(String key) {
55 return attributes.containsKey(key);
56 }
57
58 public Set getAttributeNames() {
59 return attributes.keySet();
60 }
61
62 public Serializable setAttribute(String key, Serializable value) {
63 return (Serializable)attributes.put(key, value);
64 }
65
66 public Serializable removeAttribute(String key) {
67 return (Serializable)attributes.remove(key);
68 }
69
70 public int size() {
71 return attributes.size();
72 }
73
74 public Collection getAttributesMap() {
75 return attributes.values();
76 }
77 }
78
79
80 public Object execute(String method, Object[] arguments, String[] types, EnterpriseDomain.RequestContext context)
81 throws RemoteException, InvocationTargetException {
82 try {
83 Domain.context.set(context);
84 return this.getClass().getMethod(method, EnterpriseDomain.forNames(types)).invoke(this, arguments);
85 } catch (IllegalArgumentException iae) {
86 throw new InvocationTargetException(iae);
87 } catch (IllegalAccessException iae) {
88 throw new InvocationTargetException(iae);
89 } catch (NoSuchMethodException nsme) {
90 throw new InvocationTargetException(nsme);
91 } catch (ClassNotFoundException cnfe) {
92 throw new InvocationTargetException(cnfe);
93 } finally {
94 try {
95 BusinessObjectFactory.close();
96 } catch (DAOException daoe) {
97 throw new InvocationTargetException(daoe);
98 }
99 }
100 }
101
102 protected static RequestContext getContext() {
103 return (RequestContext)Domain.context.get();
104 }
105
106
107
108
109
110
111
112 private static Class[] forNames(String[] argTypes) throws ClassNotFoundException {
113 if (argTypes == null) {
114 return null;
115 }
116 Class[] result = new Class[argTypes.length];
117 for (int i = 0; i < argTypes.length; i++) {
118 if (EnterpriseDomainBuilder.primitives.containsKey(argTypes[i])) {
119 result[i] = (Class)EnterpriseDomainBuilder.primitives.get(argTypes[i]);
120 } else {
121 result[i] = Class.forName(argTypes[i]);
122 }
123 }
124 return result;
125 }
126
127
128
129
130
131
132 public static interface Remote extends EJBObject {
133
134
135
136
137
138
139
140
141
142
143 public Object execute(String method, Object[] arguments, String[] types,
144 EnterpriseDomain.RequestContext context) throws RemoteException;
145 }
146 }