Package com.abiquo.hypervisor.plugin.internal

Source Code of com.abiquo.hypervisor.plugin.internal.GenerateSupported

/**
* Copyright (C) 2008 - Abiquo Holdings S.L. All rights reserved.
*
* Please see /opt/abiquo/tomcat/webapps/legal/ on Abiquo server
* or contact contact@abiquo.com for licensing information.
*/
package com.abiquo.hypervisor.plugin.internal;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.fuin.srcgen4javassist.SgArgument;
import org.fuin.srcgen4javassist.SgClass;
import org.fuin.srcgen4javassist.SgClassPool;
import org.fuin.srcgen4javassist.SgMethod;

/**
* @author <a href="mailto:serafin.sedano@gmail.com">Serafin Sedano</a>
*/
public class GenerateSupported
{
    /** If in the project folder, creates a java file. */
    public static void main(final String[] args)
    {
        SgClass sgClass = generateClass();
        casFile(sgClass);
    }

    private static void casFile(final SgClass sgClass)
    {
        String classname = sgClass.getName();
        String filename =
            "src/main/java" + File.separatorChar + classname.replace('.', File.separatorChar)
                + ".java";
        int pos = filename.lastIndexOf(File.separatorChar);
        if (pos > 0)
        {
            String dir = filename.substring(0, pos);
            if (!dir.equals("."))
            {
                new File(dir).mkdirs();
            }
        }
        File file = new File(filename);

        try (FileWriter out = new FileWriter(file);)
        {
            file.createNewFile();
            out.write(sgClass.toString());
            out.flush();
        }
        catch (IOException e)
        {
            System.err.println("Couldn't create IsSupported file!");
        }
    }

    private static SgClass generateClass()
    {
        SgClassPool sgPool = new SgClassPool();
        SgClass sgClass =
            new SgClass("public",
                GenerateSupported.class.getPackage().getName(),
                "IsSupported",
                true,
                null);
        SgClass sgPlugin = SgClass.create(sgPool, Plugin.class);
        for (SgClass i : sgPlugin.getInterfaces())
        {
            for (SgMethod m : i.getMethods())
            {
                new SgMethod(sgClass, m.getModifiers(), SgClass.BOOLEAN, m.getName());
                SgMethod sgMethodString =
                    new SgMethod(sgClass, m.getModifiers(), SgClass.BOOLEAN, m.getName());
                new SgArgument(sgMethodString, SgClass.create(sgPool, String.class), "region");
            }
        }
        return sgClass;
    }
}
TOP

Related Classes of com.abiquo.hypervisor.plugin.internal.GenerateSupported

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.