View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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          //out.write("}\n");	
83      }
84  
85      private void writeGetRemoteRef(String classname) {
86  //	   out.write("\tpublic "+seiName+" getRemoteRef()throws org.apache.axis.AxisFault{\n");
87  //	   out.write("\t\ttry {\n");
88  //	   out.write("\t\t    javax.security.auth.callback.CallbackHandler handler\n");
89  //	   out.write("\t\t        = org.apache.geronimo.ews.ws4j2ee.wsutils.security.jaasmodules.\n");
90  //	   out.write("\t\t            AutenticationCallbackHandlerFactory.createCallbackHandler(msgcontext);\n");
91  //	   out.write("\t\t    if(handler != null){\n");
92  //	   out.write("\t\t        javax.security.auth.login.LoginContext lc\n"); 
93  //	   out.write("\t\t            = new javax.security.auth.login.LoginContext(\"TestClient\", handler);\n");
94  //	   out.write("\t\t        lc.login();\n");
95  //	   out.write("\t\t    }\n");
96  //	   out.write("\t\t}catch (javax.security.auth.login.LoginException e) {\n");
97  //	   out.write("\t\t     e.printStackTrace();\n");
98  //	   out.write("\t\t     throw org.apache.axis.AxisFault.makeFault(e);\n");
99  //	   out.write("\t\t}\n");
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 }