protected void writePreprocessorStatements()

in src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/ParmHeaderFileWriter.java [387:476]


    protected void writePreprocessorStatements() throws WrapperFault
    {
        try
        {
            c_writer.write("#include <axis/Axis.h>\n");
            c_writer.write("#include <axis/GDefine.h>\n");
            c_writer.write("#include <axis/AxisUserAPI.h>\n");
            c_writer.write("#include <axis/SoapEnvVersions.h>\n");
            c_writer.write("#include <axis/WSDDDefines.h>\n");
            c_writer.write("#include <axis/TypeMapping.h>\n");

            if (this.type.isFault())
                c_writer.write("#include <axis/SoapFaultException.h>\n");
            
            HashSet typeSet = new HashSet();
            for (int i = 0; i < attribs.length; i++)
            {
                String basicType = attribs[i].getTypeName();
                Type theType = attribs[i].getType();

                if (theType.isRestriction() && !CUtils.isPrimitiveType(basicType))
                    typeSet.add(CUtils.sanitizeString(basicType));
                else if (!attribs[i].isSimpleType() && !attribs[i].isAnyElement())
                {
                    if ((attribs[i].isArray()) && !theType.isSimpleType())
                        typeSet.add(CUtils.sanitizeString(CUtils.getArrayNameForType(basicType)));
    
                    typeSet.add(CUtils.sanitizeString(basicType));
                }
            }
            
            // TODO we really do not support xsd:extension correctly or completely!
            if (extensionBaseAttrib != null 
                    && getCorrectParmNameConsideringArraysAndComplexTypes(extensionBaseAttrib) != null)
            {
                String extBaseType = getCorrectParmNameConsideringArraysAndComplexTypes(extensionBaseAttrib);
                
                // TODO following is hack till we really support xsd:extension correctly
                if (extBaseType.lastIndexOf("*") > -1)
                    extBaseType = extBaseType.substring(0, extBaseType.lastIndexOf("*"));

                if (!CUtils.isPrimitiveType(extBaseType))
                    typeSet.add(CUtils.sanitizeString(extBaseType));
            }            
            
            Iterator itr = typeSet.iterator();
            if (itr.hasNext())
                c_writer.write("\n");    
            
            while (itr.hasNext())
            {
                // Do not want to include the header file we are generating!
                String includeFile = itr.next().toString();
                if (!includeFile.equals(c_classname))
                   c_writer.write("#include \"" + includeFile + CUtils.getHeaderFileExtension() + "\"\n");
            }

            c_writer.write("\n");
            //Local name and the URI for the type
            c_writer.write("/* Local name and the URI for the type */\n");
            c_writer.write("static const char Axis_URI_" + c_classname + "[] = \""
                    + type.getName().getNamespaceURI() + "\";\n");
            c_writer.write("static const char Axis_TypeName_" + c_classname
                    + "[] = \"" + type.getName().getLocalPart() + "\";\n\n");
            
            // Define struct to avoid compilation issues (cycle in includes).
            // This is a must for complex wsdl files.
            typeSet = new HashSet();
            for (int i = 0; i < attribs.length; i++)
            {
                if (!attribs[i].isArray() && 
                        !(attribs[i].isSimpleType() || attribs[i].getType().isSimpleType())
                        && !attribs[i].isAnyElement())
                {
                    typeSet.add(CUtils.sanitizeString(attribs[i].getTypeName()));
                } 
            }
            
            itr = typeSet.iterator();
            while (itr.hasNext())
            {
                String t = itr.next().toString();
                c_writer.write("typedef struct " + t + "Tag " + t + ";\n");
            }
        }
        catch (IOException e)
        {
            throw new WrapperFault(e);
        }
    }