FileDocCategorySizeDatePackage
JavaFaultWriter.javaAPI DocApache Axis 1.45764Sat Apr 22 18:57:28 BST 2006org.apache.axis.wsdl.toJava

JavaFaultWriter

public class JavaFaultWriter extends JavaClassWriter
This is Wsdl2java's Fault Writer. It writes the .java file.

NOTE: This only writes simple type faults, the JavaTypeWriter emits faults that are complex types.

Fields Summary
private javax.wsdl.Message
faultMessage
Field faultMessage
private org.apache.axis.wsdl.symbolTable.SymbolTable
symbolTable
Field symbolTable
private boolean
literal
Field literal
private String
faultName
Field faultName
Constructors Summary
protected JavaFaultWriter(Emitter emitter, org.apache.axis.wsdl.symbolTable.SymbolTable symbolTable, org.apache.axis.wsdl.symbolTable.FaultInfo faultInfo)
Constructor.

param
emitter
param
symbolTable
param
faultInfo


        super(emitter,
                Utils.getFullExceptionName(faultInfo.getMessage(), symbolTable),
                "fault");

        this.literal = faultInfo.getUse().equals(Use.LITERAL);
        this.faultMessage = faultInfo.getMessage();
        this.symbolTable = symbolTable;
        this.faultName = faultInfo.getName();
    
Methods Summary
protected java.lang.StringgetExtendsText()
Return "extends org.apache.axis.AxisFault ".

return

        return "extends org.apache.axis.AxisFault ";
    
protected voidwriteFileBody(java.io.PrintWriter pw)
Write the body of the Fault file.

param
pw
throws
IOException


        Vector params = new Vector();

        symbolTable.getParametersFromParts(params,
                faultMessage.getOrderedParts(null),
                literal, faultName, null);

        // Write data members of the exception and getter methods for them
        for (int i = 0; i < params.size(); i++) {
            Parameter param = (Parameter) params.get(i);
            String type = param.getType().getName();
            String variable = Utils.xmlNameToJava(param.getName());

            pw.println("    public " + type + " " + variable + ";");
            pw.println("    public " + type + " get"
                    + Utils.capitalizeFirstChar(variable) + "() {");
            pw.println("        return this." + variable + ";");
            pw.println("    }");
        }

        // Default contructor
        pw.println();
        pw.println("    public " + className + "() {");
        pw.println("    }");
        pw.println();

        // Additional contructors
        pw.println("    public " + className + "(java.lang.Exception target) {");
        pw.println("        super(target);");
        pw.println("    }");
        pw.println();
        pw.println("    public " + className + "(java.lang.String message, java.lang.Throwable t) {");
        pw.println("        super(message, t);");
        pw.println("    }");
        pw.println();

        // contructor that initializes data
        if (params.size() > 0) {
            pw.print("      public " + className + "(");

            for (int i = 0; i < params.size(); i++) {
                if (i != 0) {
                    pw.print(", ");
                }

                Parameter param = (Parameter) params.get(i);
                String type = param.getType().getName();
                String variable = Utils.xmlNameToJava(param.getName());

                pw.print(type + " " + variable);
            }

            pw.println(") {");

            for (int i = 0; i < params.size(); i++) {
                Parameter param = (Parameter) params.get(i);
                String variable = Utils.xmlNameToJava(param.getName());

                pw.println("        this." + variable + " = " + variable + ";");
            }

            pw.println("    }");
        }

        // Method that serializes exception data (writeDetail)
        // The QName of the element is passed in by the runtime and is found
        // via the fault meta-data in the WSDD.
        // NOTE: This function is also written in JavaBeanFaultWriter.java
        pw.println();
        pw.println("    /**");
        pw.println("     * Writes the exception data to the faultDetails");
        pw.println("     */");
        pw.println(
                "    public void writeDetails(javax.xml.namespace.QName qname, org.apache.axis.encoding.SerializationContext context) throws java.io.IOException {");

        for (int i = 0; i < params.size(); i++) {
            Parameter param = (Parameter) params.get(i);
            String variable = Utils.xmlNameToJava(param.getName());

            pw.println("        context.serialize(qname, null, "
                    + Utils.wrapPrimitiveType(param.getType(), variable)
                    + ");");
        }

        pw.println("    }");