private void generateFunctionPrototype()

in graveyard/tools/org/apache/axis/tools/cbindings/CBindingGenerator.java [310:443]


    private void generateFunctionPrototype(FilePart fp, BufferedWriter outputFile) throws Exception 
    {
        Signature sign = null;
        if (FilePart.PROTOTYPE == fp.getType()) 
        {
            PrototypePart pp = (PrototypePart) fp;
            sign = pp.getSignature();
        } 
        else 
        {
            MethodPart mp = (MethodPart) fp;
            sign = mp.getSignature();
        }
        
        // Ignore private methods.
        if (!sign.getScope().equals("public") &&
            !sign.getScope().equals("protected"))
            return;
        
        String classname = sign.getClassName();
        if (null != classname && classname.endsWith("::"))
            classname = classname.substring(0, classname.length() - 2);
        
        String method = sign.getMethodName();
        if (Configuration.methodExcluded(classname, method))
            return;
        
        Parameter[] parms = sign.getParameters();
                
        String text = new String();

        // Look to see if this method is overloaded by another method
        // in the same class. If methods are overloaded in the same class then
        // convert the longest method prototype to C. We should really 
        // superset the parameters in the two prototypes instead of
        // picking the longest one.
        List overloads = headers.getMethods(method);
        boolean sameClass = true;
        if (overloads.size() > 1) 
        {
            Iterator it = overloads.iterator();
            while (it.hasNext()) 
            {
                Signature s = (Signature) it.next();
                if (s.getTrimClassName().equals(classname))
                {
                    int n1 = 0;
                    int n2 = 0;
                    if (null != s.getParameters())
                        n1 = s.getParameters().length;
                    if (null != sign.getParameters())
                        n2 = sign.getParameters().length;
                    if (n1 > n2)
                        return;
                }
            }
        }

        String classMapping = getClassMapping(classname);
        
        text += "AXISC_STORAGE_CLASS_INFO\n";
        if (sign.isConstructor()) 
            text += "AXISCHANDLE " + classMapping + "Create(";
        else if (sign.isDestructor()) 
        {
            text += "void " + classMapping + "Destroy(AXISCHANDLE ";
            String prettyClass = classNamePretty(classname);
            text += Character.toLowerCase(prettyClass.charAt(0));
            text += prettyClass.substring(1);
            if (null != parms)
                text += ", ";
        } 
        else 
        {
            String retType = toCType(sign.getReturnType());
            
            // OS/400 C compiler has a problem with "const xsdc__string" as return type, 
            // so just replace that with "const char *"
            if (System.getProperty("os.name").equals("OS/400"))
                retType = retType.replaceAll("const xsdc__string","const char *");

            text += retType + " ";
            text += getClassMapping(classname);
            text += Character.toUpperCase(method.charAt(0));
            text += method.substring(1);
            
            String retClass = getClassFromRetType(sign);
            if ("AXISCHANDLE".equals(retType) && -1 == method.indexOf(retClass))
                text += retClass;
            
            text += "(";

            if (null != classname && -1 == sign.getAttributes().indexOf("static")) 
            {
                text += "AXISCHANDLE ";
                String prettyClass = classNamePretty(classname);
                text += Character.toLowerCase(prettyClass.charAt(0));
                text += prettyClass.substring(1);
                if (null != parms)
                    text += ", ";
            }
        }
        
        // For now, ignore operator-type methods
        if (-1 != text.indexOf("Operator="))
            return;

        if (parms != null) 
        {
            for (int i = 0; i < parms.length; i++) 
            { 
                // Do not include prototypes with va_list...since these functions have
                // probably been added in support of C binding.
                if (parms[i].isVaListArg())
                    return;
                
                if (0 != i) 
                {
                    text += ", ";
                    // wrap long lines at 50 chars
                    if (text.length() > 50) 
                        text += "\n\t";
                }
                text += toCType(parms[i]) + " ";
                String name = parms[i].getName();
                if (null != name) // "..." has no parm name
                    text += name;
            }
        }
        text += ");";
        
        outputFile.write(text);
        outputFile.newLine();
    }