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.jaxrpcmapping;
18  
19  import org.apache.axis.enum.Use;
20  import org.apache.axis.wsdl.symbolTable.FaultInfo;
21  import org.apache.axis.wsdl.symbolTable.Parameter;
22  import org.apache.axis.wsdl.symbolTable.SymbolTable;
23  import org.apache.axis.wsdl.toJava.JavaClassWriter;
24  import org.apache.axis.wsdl.toJava.Utils;
25  
26  import javax.wsdl.Message;
27  import java.io.IOException;
28  import java.io.PrintWriter;
29  import java.util.Vector;
30  
31  /***
32   * This is Wsdl2java's Fault Writer.  It writes the <faultName>.java file.
33   * NOTE: This only writes simple type faults, the JavaTypeWriter emits
34   * faults that are complex types.
35   *
36   * @author Ias (iasandcb@tmax.co.kr)
37   * @deprecated no more used by J2eeGeneratorFactory
38   */
39  public class J2eeFaultWriter extends JavaClassWriter {
40      private Message faultMessage;
41      private SymbolTable symbolTable;
42      private boolean literal;
43      private String faultName;
44  
45      /***
46       * Constructor.
47       */
48      protected J2eeFaultWriter(J2eeEmitter emitter,
49                                SymbolTable symbolTable,
50                                FaultInfo faultInfo) {
51          super(emitter, Utils.getFullExceptionName(faultInfo.getMessage(),
52                  symbolTable), "fault");
53          this.literal = faultInfo.getUse().equals(Use.LITERAL);
54          this.faultMessage = faultInfo.getMessage();
55          this.symbolTable = symbolTable;
56      } // ctor
57  
58      /***
59       * Return "extends org.apache.axis.AxisFault ".
60       */
61      protected String getExtendsText() {
62          return "extends org.apache.axis.AxisFault ";
63      } // getExtendsText
64  
65      /***
66       * Write the body of the Fault file.
67       */
68      protected void writeFileBody(PrintWriter pw) throws IOException {
69          Vector params = new Vector();
70          symbolTable.getParametersFromParts(params,
71                  faultMessage.getOrderedParts(null),
72                  literal,
73                  faultName,
74                  null);
75  
76          // Write data members of the exception and getter methods for them
77          for (int i = 0; i < params.size(); i++) {
78              Parameter param = (Parameter) params.get(i);
79              String type = param.getType().getName();
80              String variable = Utils.xmlNameToJava(param.getName());
81              pw.println("    public " + type + " " + variable + ";");
82              pw.println("    public " + type + " get" + Utils.capitalizeFirstChar(variable) + "() {");
83              pw.println("        return this." + variable + ";");
84              pw.println("    }");
85          }
86  
87          // Default contructor
88          pw.println();
89          pw.println("    public " + className + "() {");
90          pw.println("    }");
91          pw.println();
92          
93          // contructor that initializes data
94          if (params.size() > 0) {
95              pw.print("      public " + className + "(");
96              for (int i = 0; i < params.size(); i++) {
97                  if (i != 0) pw.print(", ");
98                  Parameter param = (Parameter) params.get(i);
99                  String type = param.getType().getName();
100                 String variable = Utils.xmlNameToJava(param.getName());
101                 pw.print(type + " " + variable);
102             }
103             pw.println(") {");
104             for (int i = 0; i < params.size(); i++) {
105                 Parameter param = (Parameter) params.get(i);
106                 String variable = Utils.xmlNameToJava(param.getName());
107                 pw.println("        this." + variable + " = " + variable + ";");
108             }
109             pw.println("    }");
110         }
111 
112         // Method that serializes exception data (writeDetail)
113         // The QName of the element is passed in by the runtime and is found
114         // via the fault meta-data in the WSDD.
115         // NOTE: This function is also written in JavaBeanFaultWriter.java
116         pw.println();
117         pw.println("    /**");
118         pw.println("     * Writes the exception data to the faultDetails");
119         pw.println("     */");
120         pw.println("    public void writeDetails(javax.xml.namespace.QName qname, org.apache.axis.encoding.SerializationContext context) throws java.io.IOException {");
121         for (int i = 0; i < params.size(); i++) {
122             Parameter param = (Parameter) params.get(i);
123             String variable = Utils.xmlNameToJava(param.getName());
124             pw.println("        context.serialize(qname, null, " + Utils.wrapPrimitiveType(param.getType(), variable) + ");");
125         }
126         pw.println("    }");
127     } // writeFileBody
128 
129 }