1 16 package org.apache.axis.wsdl.toJava; 17 18 import org.apache.axis.constants.Use; 19 import org.apache.axis.wsdl.symbolTable.FaultInfo; 20 import org.apache.axis.wsdl.symbolTable.Parameter; 21 import org.apache.axis.wsdl.symbolTable.SymbolTable; 22 23 import javax.wsdl.Message; 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import java.util.Vector ; 27 28 34 public class JavaFaultWriter extends JavaClassWriter { 35 36 37 private Message faultMessage; 38 39 40 private SymbolTable symbolTable; 41 42 43 private boolean literal; 44 45 46 private String faultName; 47 48 55 protected JavaFaultWriter(Emitter emitter, SymbolTable symbolTable, 56 FaultInfo faultInfo) { 57 58 super(emitter, 59 Utils.getFullExceptionName(faultInfo.getMessage(), symbolTable), 60 "fault"); 61 62 this.literal = faultInfo.getUse().equals(Use.LITERAL); 63 this.faultMessage = faultInfo.getMessage(); 64 this.symbolTable = symbolTable; 65 this.faultName = faultInfo.getName(); 66 } 68 73 protected String getExtendsText() { 74 return "extends org.apache.axis.AxisFault "; 75 } 77 83 protected void writeFileBody(PrintWriter pw) throws IOException { 84 85 Vector params = new Vector (); 86 87 symbolTable.getParametersFromParts(params, 88 faultMessage.getOrderedParts(null), 89 literal, faultName, null); 90 91 for (int i = 0; i < params.size(); i++) { 93 Parameter param = (Parameter) params.get(i); 94 String type = param.getType().getName(); 95 String variable = Utils.xmlNameToJava(param.getName()); 96 97 pw.println(" public " + type + " " + variable + ";"); 98 pw.println(" public " + type + " get" 99 + Utils.capitalizeFirstChar(variable) + "() {"); 100 pw.println(" return this." + variable + ";"); 101 pw.println(" }"); 102 } 103 104 pw.println(); 106 pw.println(" public " + className + "() {"); 107 pw.println(" }"); 108 pw.println(); 109 110 pw.println(" public " + className + "(java.lang.Exception target) {"); 112 pw.println(" super(target);"); 113 pw.println(" }"); 114 pw.println(); 115 pw.println(" public " + className + "(java.lang.String message, java.lang.Throwable t) {"); 116 pw.println(" super(message, t);"); 117 pw.println(" }"); 118 pw.println(); 119 120 if (params.size() > 0) { 122 pw.print(" public " + className + "("); 123 124 for (int i = 0; i < params.size(); i++) { 125 if (i != 0) { 126 pw.print(", "); 127 } 128 129 Parameter param = (Parameter) params.get(i); 130 String type = param.getType().getName(); 131 String variable = Utils.xmlNameToJava(param.getName()); 132 133 pw.print(type + " " + variable); 134 } 135 136 pw.println(") {"); 137 138 for (int i = 0; i < params.size(); i++) { 139 Parameter param = (Parameter) params.get(i); 140 String variable = Utils.xmlNameToJava(param.getName()); 141 142 pw.println(" this." + variable + " = " + variable + ";"); 143 } 144 145 pw.println(" }"); 146 } 147 148 pw.println(); 153 pw.println(" /**"); 154 pw.println(" * Writes the exception data to the faultDetails"); 155 pw.println(" */"); 156 pw.println( 157 " public void writeDetails(javax.xml.namespace.QName qname, org.apache.axis.encoding.SerializationContext context) throws java.io.IOException {"); 158 159 for (int i = 0; i < params.size(); i++) { 160 Parameter param = (Parameter) params.get(i); 161 String variable = Utils.xmlNameToJava(param.getName()); 162 163 pw.println(" context.serialize(qname, null, " 164 + Utils.wrapPrimitiveType(param.getType(), variable) 165 + ");"); 166 } 167 168 pw.println(" }"); 169 } } | Popular Tags |