1 16 package org.apache.axis.wsdl.toJava; 17 18 import org.apache.axis.utils.Messages; 19 import org.apache.axis.wsdl.gen.Generator; 20 import org.apache.axis.wsdl.symbolTable.BindingEntry; 21 import org.apache.axis.wsdl.symbolTable.FaultInfo; 22 import org.apache.axis.wsdl.symbolTable.MessageEntry; 23 import org.apache.axis.wsdl.symbolTable.SymbolTable; 24 25 import javax.wsdl.Binding; 26 import javax.wsdl.Definition; 27 import javax.wsdl.Import; 28 import javax.wsdl.Message; 29 import java.io.IOException ; 30 import java.util.ArrayList ; 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.Map ; 34 import java.util.Vector ; 35 36 41 public class JavaDefinitionWriter implements Generator { 42 43 44 protected Emitter emitter; 45 46 47 protected Definition definition; 48 49 50 protected SymbolTable symbolTable; 51 52 59 public JavaDefinitionWriter(Emitter emitter, Definition definition, 60 SymbolTable symbolTable) { 61 62 this.emitter = emitter; 63 this.definition = definition; 64 this.symbolTable = symbolTable; 65 } 67 72 public void generate() throws IOException { 73 writeFaults(); 74 } 76 83 protected void writeFaults() throws IOException { 84 85 ArrayList faults = new ArrayList (); 86 87 collectFaults(definition, faults); 88 89 HashSet generatedFaults = new HashSet (); 91 92 Iterator fi = faults.iterator(); 94 95 while (fi.hasNext()) { 96 FaultInfo faultInfo = (FaultInfo) fi.next(); 97 Message message = faultInfo.getMessage(); 98 String name = Utils.getFullExceptionName(message, 99 symbolTable); 100 101 if (generatedFaults.contains(name)) { 102 continue; 103 } 104 105 generatedFaults.add(name); 106 107 MessageEntry me = 111 symbolTable.getMessageEntry(message.getQName()); 112 boolean emitSimpleFault = true; 113 114 if (me != null) { 115 Boolean complexTypeFault = (Boolean ) me.getDynamicVar( 116 JavaGeneratorFactory.COMPLEX_TYPE_FAULT); 117 118 if ((complexTypeFault != null) 119 && complexTypeFault.booleanValue()) { 120 emitSimpleFault = false; 121 } 122 } 123 124 if (emitSimpleFault) { 125 try { 126 JavaFaultWriter writer = new JavaFaultWriter(emitter, 127 symbolTable, faultInfo); 128 129 writer.generate(); 131 } catch (DuplicateFileException dfe) { 132 System.err.println(Messages.getMessage("fileExistError00", 133 dfe.getFileName())); 134 } 135 } 136 } 137 } 139 140 private HashSet importedFiles = new HashSet (); 141 142 149 private void collectFaults(Definition def, ArrayList faults) 150 throws IOException { 151 152 Map imports = def.getImports(); 153 Object [] importValues = imports.values().toArray(); 154 155 for (int i = 0; i < importValues.length; ++i) { 156 Vector v = (Vector ) importValues[i]; 157 158 for (int j = 0; j < v.size(); ++j) { 159 Import imp = (Import) v.get(j); 160 161 if (!importedFiles.contains(imp.getLocationURI())) { 162 importedFiles.add(imp.getLocationURI()); 163 164 Definition importDef = imp.getDefinition(); 165 166 if (importDef != null) { 167 collectFaults(importDef, faults); 168 } 169 } 170 } 171 } 172 173 Map bindings = def.getBindings(); 175 Iterator bindi = bindings.values().iterator(); 176 177 while (bindi.hasNext()) { 178 Binding binding = (Binding) bindi.next(); 179 BindingEntry entry = 180 symbolTable.getBindingEntry(binding.getQName()); 181 182 if (entry.isReferenced()) { 183 184 Map faultMap = entry.getFaults(); 187 Iterator it = faultMap.values().iterator(); 188 189 while (it.hasNext()) { 190 ArrayList list = (ArrayList ) it.next(); 191 192 faults.addAll(list); 194 } 195 } 196 } 197 } } | Popular Tags |