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  
17  package org.apache.geronimo.ews.ws4j2ee.toWs.wrapperWs.geronimo;
18  
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
22  import org.apache.geronimo.ews.ws4j2ee.context.SEIOperation;
23  import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
24  import org.apache.geronimo.ews.ws4j2ee.toWs.JavaClassWriter;
25  import org.apache.geronimo.ews.ws4j2ee.utils.Utils;
26  
27  import java.util.ArrayList;
28  import java.util.Iterator;
29  
30  /***
31   * @author Srinath Perera(hemapani@opensource.lk)
32   */
33  public class InternalBasedWrapperClassWriter extends JavaClassWriter {
34      protected static Log log =
35              LogFactory.getLog(InternalBasedWrapperClassWriter.class.getName());
36      protected final String seiName;
37      protected final String ejbName;
38  
39      /***
40       * @param j2eewscontext
41       * @param qulifiedName
42       * @throws GenerationFault
43       */
44      public InternalBasedWrapperClassWriter(J2EEWebServiceContext j2eewscontext)
45              throws GenerationFault {
46          super(j2eewscontext, getName(j2eewscontext) + "Impl");
47          seiName = j2eewscontext.getMiscInfo().getJaxrpcSEI();
48          ejbName = j2eewscontext.getEJBDDContext().getEjbName();
49      }
50  
51      private static String getName(J2EEWebServiceContext j2eewscontext) {
52          String name =
53                  j2eewscontext.getWSDLContext().gettargetBinding().getName();
54          if (name == null) {
55              name = j2eewscontext.getMiscInfo().getJaxrpcSEI();
56          }
57          return name;
58      }
59  
60      protected String getimplementsPart() {
61          return " implements " + j2eewscontext.getMiscInfo().getJaxrpcSEI() + "," + "org.apache.geronimo.ews.ws4j2ee.wsutils.ContextAccessible";
62      }
63  
64      protected void writeAttributes() throws GenerationFault {
65          out.write("private org.apache.axis.MessageContext msgcontext;\n");
66          out.write("\tprivate " + seiName + " bean = null;\n");
67          out.write("\tprivate org.openejb.EJBContainer container;\n");
68      }
69  
70      protected void writeConstructors() throws GenerationFault {
71          out.write("\tpublic " + classname + "(){\n");
72          out.write("\t}\n");
73      }
74  
75      protected void writeMethods() throws GenerationFault {
76          out.write("\tpublic void setMessageContext(org.apache.axis.MessageContext msgcontext){;\n");
77          out.write("\t\tthis.msgcontext = msgcontext;\n");
78          out.write("\t}\n");
79          String parmlistStr = null;
80          ArrayList operations = j2eewscontext.getMiscInfo().getSEIOperations();
81          for (int i = 0; i < operations.size(); i++) {
82              parmlistStr = "";
83              SEIOperation op = (SEIOperation) operations.get(i);
84              String returnType = op.getReturnType();
85              if (returnType == null)
86                  returnType = "void";
87              out.write("\tpublic " + returnType + " " + op.getMethodName() + "(");
88              Iterator pas = op.getParameterNames().iterator();
89              boolean first = true;
90              while (pas.hasNext()) {
91                  String name = (String) pas.next();
92                  String type = op.getParameterType(name);
93                  if (first) {
94                      first = false;
95                      out.write(type + " " + name);
96                      parmlistStr = parmlistStr + name;
97                  } else {
98                      out.write("," + type + " " + name);
99                      parmlistStr = parmlistStr + "," + name;
100                 }
101             }
102             out.write(") throws java.rmi.RemoteException");
103             ArrayList faults = op.getFaults();
104             for (int j = 0; j < faults.size(); j++) {
105                 out.write("," + (String) faults.get(i));
106             }
107             out.write("{\n");
108             out.write("\t\tString methodName = \"" + op.getMethodName() + "\";\n");
109             out.write("\t\tjava.lang.reflect.Method callMethod = Utils.getJavaMethod(\""
110                     + seiName
111                     + "\",methodName);\n");
112             out.write("\t\tClass[] classes = callMethod.getParameterTypes();\n");
113             out.write("\t\tObject[] arguments = new Object[]{");
114             pas = op.getParameterNames().iterator();
115             first = true;
116             while (pas.hasNext()) {
117                 String name = (String) pas.next();
118                 String type = op.getParameterType(name);
119                 if (first) {
120                     first = false;
121                     out.write(Utils.getParameter(type, name));
122                 } else {
123                     out.write("," + Utils.getParameter(type, name));
124                 }
125             }
126             out.write("};\n");
127             if (!"void".equals(returnType)) {
128                 out.write("\t\t\treturn "
129                         + Utils.getReturnCode(returnType, "AxisGeronimoUtils.invokeEJB(\""
130                         + ejbName
131                         + "\",methodName,classes,arguments)")
132                         + ";\n");
133             } else {
134                 out.write("\t\t\tAxisGeronimoUtils.invokeEJB(\""
135                         + ejbName
136                         + "\",methodName,classes,arguments);\n");
137             }
138             out.write("\t}\n");
139         }
140     }
141 
142     /* (non-Javadoc)
143      * @see org.apache.geronimo.ews.ws4j2ee.toWs.JavaClassWriter#writeImportStatements()
144      */
145     protected void writeImportStatements() throws GenerationFault {
146         out.write("import org.apache.geronimo.axis.AxisGeronimoUtils;\n");
147         out.write("import org.apache.geronimo.ews.ws4j2ee.utils.Utils;\n");
148     }
149 
150 }
151