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.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
21  import org.apache.geronimo.ews.ws4j2ee.context.SEIOperation;
22  import org.apache.geronimo.ews.ws4j2ee.context.j2eeDD.WebContext;
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.toWs.UnrecoverableGenerationFault;
26  
27  import java.util.ArrayList;
28  import java.util.Iterator;
29  
30  /***
31   * <h4>WebEndpoint Based Serivce Implementation Bean</h4>
32   * <p>The Service Implementation Bean must follow the Service Developer requirements outlined in the JAX-RPC specification and are listed below except as noted.</p>
33   * <ol>
34   * <li>?The Service Implementation Bean must have a default public constructor.</li>
35   * <li>?The Service Implementation Bean may implement the Service Endpoint
36   * Interface as defined by the JAX-RPC Servlet model. The bean must implement
37   * all the method signatures of the SEI. In addition, a Service Implementation
38   * Bean may be implemented that does not implement the SEI. This additional
39   * requirement provides the same SEI implementation flexibility as provided by
40   * EJB service endpoints. The business methods of the bean must be public and
41   * must not be static.</li>
42   * <li>If the Service Implementation Bean does not implement the SEI, the
43   * business methods must not be final. The Service Implementation Bean
44   * may implement other methods in addition to those defined by the SEI,
45   * but only the SEI methods are exposed to the client.  </li>
46   * <li>?A Service Implementation must be a stateless object. A Service
47   * Implementation Bean must not save client specific state across method
48   * calls either within the bean instance???s data members or external to
49   * the instance. A container may use any bean instance to service a request.</li>
50   * <li>?The class must be public, must not be final and must not be abstract.</li>
51   * <li>?The class must not define the finalize() method.</li>
52   * </ol>
53   *
54   * @author Srinath Perera(hemapani@opensource.lk)
55   */
56  public class WebEndpointWrapperClassWriter extends JavaClassWriter {
57      protected static Log log =
58              LogFactory.getLog(WrapperWsGenerator.class.getName());
59      protected String seiName = null;
60      private String implBean = null;
61  
62      /***
63       * @param j2eewscontext
64       * @param qulifiedName
65       * @throws GenerationFault
66       */
67      public WebEndpointWrapperClassWriter(J2EEWebServiceContext j2eewscontext)
68              throws GenerationFault {
69          super(j2eewscontext, getName(j2eewscontext) + "Impl");
70          seiName = j2eewscontext.getMiscInfo().getJaxrpcSEI();
71          WebContext webcontext = j2eewscontext.getWebDDContext();
72          if (webcontext == null) {
73              throw new UnrecoverableGenerationFault("for webbased Impl" +
74                      " the WebDDContext must not be null");
75          }
76          implBean = webcontext.getServletClass();
77      }
78  
79      private static String getName(J2EEWebServiceContext j2eewscontext) {
80          String name = j2eewscontext.getWSDLContext().gettargetBinding().getName();
81          if (name == null) {
82              name = j2eewscontext.getMiscInfo().getJaxrpcSEI();
83          }
84          return name;
85      }
86  
87      protected String getimplementsPart() {
88          return " implements "
89                  + j2eewscontext.getMiscInfo().getJaxrpcSEI() + ",org.apache.geronimo.ews.ws4j2ee.wsutils.ContextAccessible";
90      }
91  
92      protected void writeAttributes() throws GenerationFault {
93          out.write("private " + implBean + " bean = null;\n");
94          out.write("private org.apache.axis.MessageContext msgcontext;\n");
95      }
96  
97      protected void writeConstructors() throws GenerationFault {
98          out.write("\tpublic " + classname + "()throws org.apache.axis.AxisFault{\n");
99          out.write("\t\tbean = (" + implBean + ")org.apache.geronimo.ews.ws4j2ee.wsutils.ImplBeanPool.getImplBean(\""
100                 + implBean + "\");\n");
101         out.write("\t}\n");
102     }
103 
104     /* (non-Javadoc)
105      * @see org.apache.geronimo.ews.ws4j2ee.toWs.JavaClassWriter#writeMethods()
106      */
107     protected void writeMethods() throws GenerationFault {
108         out.write("\tpublic void setMessageContext(org.apache.axis.MessageContext msgcontext){;\n");
109         out.write("\t\tthis.msgcontext = msgcontext;\n");
110         out.write("\t}\n");
111         String parmlistStr = null;
112         ArrayList operations = j2eewscontext.getMiscInfo().getSEIOperations();
113         for (int i = 0; i < operations.size(); i++) {
114             parmlistStr = "";
115             SEIOperation op = (SEIOperation) operations.get(i);
116             String returnType = op.getReturnType();
117             if (returnType == null)
118                 returnType = "void";
119             out.write("\tpublic " + returnType + " " + op.getMethodName() + "(");
120             Iterator pas = op.getParameterNames().iterator();
121             boolean first = true;
122             while (pas.hasNext()) {
123                 String name = (String) pas.next();
124                 String type = op.getParameterType(name);
125                 if (first) {
126                     first = false;
127                     out.write(type + " " + name);
128                     parmlistStr = parmlistStr + name;
129                 } else {
130                     out.write("," + type + " " + name);
131                     parmlistStr = parmlistStr + "," + name;
132                 }
133             }
134             out.write(") throws java.rmi.RemoteException");
135             ArrayList faults = op.getFaults();
136             for (int j = 0; j < faults.size(); j++) {
137                 out.write("," + (String) faults.get(j));
138             }
139             out.write("{\n");
140             if (!"void".equals(returnType))
141                 out.write("\t\treturn bean." + op.getMethodName() + "(" + parmlistStr + ");\n");
142             else
143                 out.write("\t\tbean." + op.getMethodName() + "(" + parmlistStr + ");\n");
144             out.write("\t}\n");
145         }
146     }
147 
148 }