1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.geronimo.ews.ws4j2ee.toWs.wrapperWs;
17
18 import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
19 import org.apache.geronimo.ews.ws4j2ee.context.SEIOperation;
20 import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
21
22 import java.util.ArrayList;
23 import java.util.Iterator;
24
25 /***
26 * @author Srinath Perera(hemapani@opensource.lk)
27 */
28 public abstract class SimpleRemoteInterfaceBasedWrapperClassWriter extends EJBBasedWrapperClassWriter {
29
30 /***
31 * @param j2eewscontext
32 * @throws GenerationFault
33 */
34 public SimpleRemoteInterfaceBasedWrapperClassWriter(J2EEWebServiceContext j2eewscontext)
35 throws GenerationFault {
36 super(j2eewscontext);
37 seiName = context.getEjbRemoteInterface();
38 }
39
40 protected abstract String getJNDIInitialContextFactory();
41
42 protected abstract String getJNDIHostAndPort();
43
44 protected String getimplementsPart() {
45 return " implements org.apache.geronimo.ews.ws4j2ee.wsutils.ContextAccessible";
46 }
47
48 protected void writeMethods() throws GenerationFault {
49 out.write("\tpublic void setMessageContext(org.apache.axis.MessageContext msgcontext){;\n");
50 out.write("\t\tthis.msgcontext = msgcontext;\n");
51 out.write("\t}\n");
52 writeGetRemoteRef(classname);
53 String parmlistStr = null;
54 ArrayList operations = j2eewscontext.getMiscInfo().getSEIOperations();
55 for (int i = 0; i < operations.size(); i++) {
56 parmlistStr = "";
57 SEIOperation op = (SEIOperation) operations.get(i);
58 String returnType = op.getReturnType();
59 if (returnType == null)
60 returnType = "void";
61 out.write("\tpublic " + returnType + " " + op.getMethodName() + "(");
62 Iterator pas = op.getParameterNames().iterator();
63 boolean first = true;
64 while (pas.hasNext()) {
65 String name = (String) pas.next();
66 String type = op.getParameterType(name);
67 if (first) {
68 first = false;
69 out.write(type + " " + name);
70 parmlistStr = parmlistStr + name;
71 } else {
72 out.write("," + type + " " + name);
73 parmlistStr = parmlistStr + "," + name;
74 }
75 }
76 out.write(") throws java.rmi.RemoteException");
77 ArrayList faults = op.getFaults();
78 for (int j = 0; j < faults.size(); j++) {
79 out.write("," + (String) faults.get(j));
80 }
81 out.write("{\n");
82 out.write("\t\tif(ejb == null)\n");
83 out.write("\t\t\tejb = getRemoteRef();\n");
84 if (!"void".equals(returnType))
85 out.write("\t\treturn ejb." + op.getMethodName() + "(" + parmlistStr + ");\n");
86 else
87 out.write("\t\tejb." + op.getMethodName() + "(" + parmlistStr + ");\n");
88 out.write("\t}\n");
89 }
90
91 }
92
93 private void writeGetRemoteRef(String classname) {
94 out.write("\tpublic " + seiName + " getRemoteRef()throws org.apache.axis.AxisFault{\n");
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 out.write("\t\ttry{\n");
124
125
126
127
128 out.write("\t\t\tjava.util.Properties env = new java.util.Properties();\n");
129 out.write("\t\t\tenv.load(getClass().getClassLoader().getResourceAsStream(\"jndi.properties\"));\n");
130
131
132
133
134
135 out.write("\t\t\tjavax.naming.Context initial = new javax.naming.InitialContext(env);\n");
136
137 String ejbname = j2eewscontext.getWSCFContext().getWscfport().getServiceImplBean().getEjblink();
138 out.write("\t\t\tObject objref = initial.lookup(\"ejb/" + ejbname + "\");\n");
139 String ejbhome = j2eewscontext.getEJBDDContext().getEjbhomeInterface();
140 out.write("\t\t\t" + ejbhome + " home = \n\t\t\t\t(" + ejbhome
141 + ")javax.rmi.PortableRemoteObject.narrow(objref," + ejbhome + ".class);\n");
142 out.write("\t\t\treturn home.create();\n");
143 out.write("\t\t}catch (Exception e) {\n");
144 out.write("\t\t throw org.apache.axis.AxisFault.makeFault(e);\n");
145 out.write("\t\t}\n");
146 out.write("\t}\n");
147 }
148 }