1 16 package org.apache.axis.wsdl.toJava; 17 18 import org.apache.axis.wsdl.symbolTable.BindingEntry; 19 import org.apache.axis.wsdl.symbolTable.Parameter; 20 import org.apache.axis.wsdl.symbolTable.Parameters; 21 import org.apache.axis.wsdl.symbolTable.SymbolTable; 22 import org.apache.axis.wsdl.symbolTable.TypeEntry; 23 24 import javax.wsdl.Binding; 25 import javax.wsdl.BindingOperation; 26 import javax.wsdl.Operation; 27 import javax.wsdl.OperationType; 28 import javax.xml.rpc.holders.BooleanHolder ; 29 import java.io.IOException ; 30 import java.io.PrintWriter ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 34 38 public class JavaImplWriter extends JavaClassWriter { 39 40 41 protected Binding binding; 42 43 44 protected SymbolTable symbolTable; 45 46 47 protected BindingEntry bEntry; 48 49 56 protected JavaImplWriter(Emitter emitter, BindingEntry bEntry, 57 SymbolTable symbolTable) 58 { 59 super(emitter, ( emitter.getImplementationClassName() == null ? 60 bEntry.getName() + "Impl" : 61 emitter.getImplementationClassName()), "templateImpl"); 62 63 this.binding = bEntry.getBinding(); 64 this.symbolTable = symbolTable; 65 this.bEntry = bEntry; 66 } 68 74 protected void writeFileBody(PrintWriter pw) throws IOException { 75 76 List operations = binding.getBindingOperations(); 77 78 for (int i = 0; i < operations.size(); ++i) { 79 BindingOperation operation = (BindingOperation) operations.get(i); 80 Operation ptOperation = operation.getOperation(); 81 OperationType type = ptOperation.getStyle(); 82 Parameters parameters = 83 bEntry.getParameters(operation.getOperation()); 84 85 if ((OperationType.NOTIFICATION.equals(type)) 88 || (OperationType.SOLICIT_RESPONSE.equals(type))) { 89 pw.println(parameters.signature); 90 pw.println(); 91 } else { 92 writeOperation(pw, parameters); 93 } 94 } 95 } 97 102 protected String getImplementsText() { 103 104 String portTypeName = 105 (String ) bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME); 106 String implementsText = "implements " + portTypeName; 107 108 return implementsText; 109 } 110 111 118 protected void writeOperation(PrintWriter pw, Parameters parms) 119 throws IOException { 120 121 pw.println(parms.signature + " {"); 122 123 Iterator iparam = parms.list.iterator(); 125 126 while (iparam.hasNext()) { 127 Parameter param = (Parameter) iparam.next(); 128 129 if (param.getMode() == Parameter.OUT) { 130 131 BooleanHolder bThrow = new BooleanHolder (false); 133 String constructorString = 134 Utils.getConstructorForParam(param, symbolTable, bThrow); 135 136 if (bThrow.value) { 137 pw.println(" try {"); 138 } 139 140 pw.println(" " + Utils.xmlNameToJava(param.getName()) 141 + ".value = " + constructorString + ";"); 142 143 if (bThrow.value) { 144 pw.println(" } catch (Exception e) {"); 145 pw.println(" }"); 146 } 147 } 148 } 149 150 Parameter returnParam = parms.returnParam; 152 if (returnParam != null) { 153 TypeEntry returnType = returnParam.getType(); 154 155 pw.print(" return "); 156 157 if (!returnParam.isOmittable() && 158 Utils.isPrimitiveType(returnType)) { 159 String returnString = returnType.getName(); 160 161 if ("boolean".equals(returnString)) { 162 pw.println("false;"); 163 } else if ("byte".equals(returnString)) { 164 pw.println("(byte)-3;"); 165 } else if ("short".equals(returnString)) { 166 pw.println("(short)-3;"); 167 } else { 168 pw.println("-3;"); 169 } 170 } else { 171 pw.println("null;"); 172 } 173 } 174 175 pw.println(" }"); 176 pw.println(); 177 } } | Popular Tags |