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 class SimpleLocalInterfaceBasedWrapperClassWriter extends EJBBasedWrapperClassWriter {
29
30 /***
31 * @param j2eewscontext
32 * @throws GenerationFault
33 */
34 public SimpleLocalInterfaceBasedWrapperClassWriter(J2EEWebServiceContext j2eewscontext)
35 throws GenerationFault {
36 super(j2eewscontext);
37 seiName = context.getEjbLocalInterface();
38 }
39
40 protected void writeMethods() throws GenerationFault {
41 out.write("\tpublic void setMessageContext(org.apache.axis.MessageContext msgcontext){;\n");
42 out.write("\t\tthis.msgcontext = msgcontext;\n");
43 out.write("\t}\n");
44 writeGetRemoteRef(classname);
45 String parmlistStr = null;
46 ArrayList operations = j2eewscontext.getMiscInfo().getSEIOperations();
47 for (int i = 0; i < operations.size(); i++) {
48 parmlistStr = "";
49 SEIOperation op = (SEIOperation) operations.get(i);
50 String returnType = op.getReturnType();
51 if (returnType == null)
52 returnType = "void";
53 out.write("\tpublic " + returnType + " " + op.getMethodName() + "(");
54 Iterator pas = op.getParameterNames().iterator();
55 boolean first = true;
56 while (pas.hasNext()) {
57 String name = (String) pas.next();
58 String type = op.getParameterType(name);
59 if (first) {
60 first = false;
61 out.write(type + " " + name);
62 parmlistStr = parmlistStr + name;
63 } else {
64 out.write("," + type + " " + name);
65 parmlistStr = parmlistStr + "," + name;
66 }
67 }
68 out.write(") throws java.rmi.RemoteException");
69 ArrayList faults = op.getFaults();
70 for (int j = 0; j < faults.size(); j++) {
71 out.write("," + (String) faults.get(i));
72 }
73 out.write("{\n");
74 out.write("\t\tif(ejb == null)\n");
75 out.write("\t\t\tejb = getRemoteRef();\n");
76 if (!"void".equals(returnType))
77 out.write("\t\treturn ejb." + op.getMethodName() + "(" + parmlistStr + ");\n");
78 else
79 out.write("\t\tejb." + op.getMethodName() + "(" + parmlistStr + ");\n");
80 out.write("\t}\n");
81 }
82
83 }
84
85 private void writeGetRemoteRef(String classname) {
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 out.write("\t\ttry{\n");
102 String ejbname = j2eewscontext.getWSDLContext().getTargetPortType().getName().toLowerCase();
103 int index = ejbname.lastIndexOf(".");
104 if (index > 0) {
105 ejbname = ejbname.substring(index + 1);
106 }
107 out.write("\t\t\tjavax.naming.Context initial = new javax.naming.InitialContext();\n");
108 out.write("\t\t\tObject objref = jndiContext.lookup(\"java:comp/env/ejb/\"" + ejbname + ");\n");
109 String ejbhome = j2eewscontext.getEJBDDContext().getEjbhomeInterface();
110 out.write("\t\t\t" + ejbhome + " home = (" + ejbhome + ")objref;\n");
111 out.write("\t\t\treturn home.create();\n");
112 out.write("\t\t}catch (Exception e) {\n");
113 out.write("\t\t throw org.apache.axis.AxisFault.makeFault(e);\n");
114 out.write("\t\t}\n");
115 out.write("\t}\n");
116 }
117 }