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

JavaDefinitionWriter

public class JavaDefinitionWriter extends Object implements org.apache.axis.wsdl.gen.Generator
This is Wsdl2java's Definition Writer. It currently writes the following files: Faults as needed.

Fields Summary
protected Emitter
emitter
Field emitter
protected javax.wsdl.Definition
definition
Field definition
protected org.apache.axis.wsdl.symbolTable.SymbolTable
symbolTable
Field symbolTable
private HashSet
importedFiles
Collect all of the faults used in this definition.
Constructors Summary
public JavaDefinitionWriter(Emitter emitter, javax.wsdl.Definition definition, org.apache.axis.wsdl.symbolTable.SymbolTable symbolTable)
Constructor.

param
emitter
param
definition
param
symbolTable


        this.emitter = emitter;
        this.definition = definition;
        this.symbolTable = symbolTable;
    
Methods Summary
private voidcollectFaults(javax.wsdl.Definition def, java.util.ArrayList faults)
Method collectFaults

param
def
param
faults
throws
IOException


                        
         
              

        Map imports = def.getImports();
        Object[] importValues = imports.values().toArray();

        for (int i = 0; i < importValues.length; ++i) {
            Vector v = (Vector) importValues[i];

            for (int j = 0; j < v.size(); ++j) {
                Import imp = (Import) v.get(j);

                if (!importedFiles.contains(imp.getLocationURI())) {
                    importedFiles.add(imp.getLocationURI());

                    Definition importDef = imp.getDefinition();

                    if (importDef != null) {
                        collectFaults(importDef, faults);
                    }
                }
            }
        }

        // Traverse the bindings to find faults
        Map bindings = def.getBindings();
        Iterator bindi = bindings.values().iterator();

        while (bindi.hasNext()) {
            Binding binding = (Binding) bindi.next();
            BindingEntry entry =
                    symbolTable.getBindingEntry(binding.getQName());

            if (entry.isReferenced()) {

                // use the map of bindingOperation -> fault info
                // created in SymbolTable
                Map faultMap = entry.getFaults();
                Iterator it = faultMap.values().iterator();

                while (it.hasNext()) {
                    ArrayList list = (ArrayList) it.next();

                    // Accumulate total list of faults
                    faults.addAll(list);
                }
            }
        }
    
public voidgenerate()
Write other items from the definition as needed.

throws
IOException

        writeFaults();
    
protected voidwriteFaults()
Write all the simple type faults. The complexType Faults are automatically handled by JavaTypeWriter. The fault name is derived from the fault message name per JAX-RPC

throws
IOException


        ArrayList faults = new ArrayList();

        collectFaults(definition, faults);

        // Fault classes we're actually writing (for dup checking)
        HashSet generatedFaults = new HashSet();

        // iterate over fault list, emitting code.
        Iterator fi = faults.iterator();

        while (fi.hasNext()) {
            FaultInfo faultInfo = (FaultInfo) fi.next();
            Message message = faultInfo.getMessage();
            String name = Utils.getFullExceptionName(message,
                    symbolTable);

            if (generatedFaults.contains(name)) {
                continue;
            }

            generatedFaults.add(name);

            // Generate the 'Simple' Faults.
            // The complexType Faults are automatically handled
            // by JavaTypeWriter.
            MessageEntry me =
                    symbolTable.getMessageEntry(message.getQName());
            boolean emitSimpleFault = true;

            if (me != null) {
                Boolean complexTypeFault = (Boolean) me.getDynamicVar(
                        JavaGeneratorFactory.COMPLEX_TYPE_FAULT);

                if ((complexTypeFault != null)
                        && complexTypeFault.booleanValue()) {
                    emitSimpleFault = false;
                }
            }

            if (emitSimpleFault) {
                try {
                    JavaFaultWriter writer = new JavaFaultWriter(emitter,
                            symbolTable, faultInfo);

                    // Go write the file
                    writer.generate();
                } catch (DuplicateFileException dfe) {
                    System.err.println(Messages.getMessage("fileExistError00",
                            dfe.getFileName()));
                }
            }
        }