1 55 package org.jboss.axis.wsdl.toJava; 56 57 import org.jboss.axis.utils.Messages; 58 import org.jboss.axis.wsdl.gen.Generator; 59 import org.jboss.axis.wsdl.symbolTable.BindingEntry; 60 import org.jboss.axis.wsdl.symbolTable.FaultInfo; 61 import org.jboss.axis.wsdl.symbolTable.MessageEntry; 62 import org.jboss.axis.wsdl.symbolTable.SymbolTable; 63 64 import javax.wsdl.Binding; 65 import javax.wsdl.Definition; 66 import javax.wsdl.Import; 67 import javax.wsdl.Message; 68 import java.io.IOException ; 69 import java.util.ArrayList ; 70 import java.util.HashSet ; 71 import java.util.Iterator ; 72 import java.util.Map ; 73 import java.util.Vector ; 74 75 80 public class JavaDefinitionWriter implements Generator 81 { 82 protected Emitter emitter; 83 protected Definition definition; 84 protected SymbolTable symbolTable; 85 86 89 public JavaDefinitionWriter(Emitter emitter, Definition definition, 90 SymbolTable symbolTable) 91 { 92 this.emitter = emitter; 93 this.definition = definition; 94 this.symbolTable = symbolTable; 95 } 97 100 public void generate() throws IOException 101 { 102 writeFaults(); 103 } 105 110 private void writeFaults() throws IOException 111 { 112 ArrayList faults = new ArrayList (); 113 collectFaults(definition, faults); 114 115 HashSet generatedFaults = new HashSet (); 117 118 Iterator fi = faults.iterator(); 120 while (fi.hasNext()) 121 { 122 FaultInfo faultInfo = (FaultInfo)fi.next(); 123 Message message = faultInfo.getMessage(); 124 String name = Utils.getFullExceptionName(message, symbolTable); 125 if (generatedFaults.contains(name)) 126 { 127 continue; 128 } 129 generatedFaults.add(name); 130 131 MessageEntry me = symbolTable.getMessageEntry(message.getQName()); 135 boolean emitSimpleFault = true; 136 if (me != null) 137 { 138 Boolean complexTypeFault = (Boolean ) 139 me.getDynamicVar(JavaGeneratorFactory.COMPLEX_TYPE_FAULT); 140 if (complexTypeFault != null && 141 complexTypeFault.booleanValue()) 142 { 143 emitSimpleFault = false; 144 } 145 } 146 if (emitSimpleFault) 147 { 148 try 149 { 150 JavaFaultWriter writer = 151 new JavaFaultWriter(emitter, 152 symbolTable, 153 faultInfo); 154 writer.generate(); 156 } 157 catch (DuplicateFileException dfe) 158 { 159 System.err.println(Messages.getMessage("fileExistError00", dfe.getFileName())); 160 } 161 } 162 } 163 } 165 168 private HashSet importedFiles = new HashSet (); 169 170 private void collectFaults(Definition def, ArrayList faults) throws IOException 171 { 172 Map imports = def.getImports(); 173 Object [] importValues = imports.values().toArray(); 174 for (int i = 0; i < importValues.length; ++i) 175 { 176 Vector v = (Vector )importValues[i]; 177 for (int j = 0; j < v.size(); ++j) 178 { 179 Import imp = (Import)v.get(j); 180 if (!importedFiles.contains(imp.getLocationURI())) 181 { 182 importedFiles.add(imp.getLocationURI()); 183 Definition importDef = imp.getDefinition(); 184 if (importDef != null) 185 { 186 collectFaults(importDef, faults); 187 } 188 } 189 } 190 } 191 192 Map bindings = def.getBindings(); 194 Iterator bindi = bindings.values().iterator(); 195 while (bindi.hasNext()) 196 { 197 Binding binding = (Binding)bindi.next(); 198 BindingEntry entry = symbolTable.getBindingEntry(binding.getQName()); 199 if (entry.isReferenced()) 200 { 201 Map faultMap = entry.getFaults(); 204 Iterator it = faultMap.values().iterator(); 205 while (it.hasNext()) 206 { 207 ArrayList list = (ArrayList )it.next(); 208 faults.addAll(list); 210 } 211 } 212 } 213 } 215 } | Popular Tags |