All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jerkar.tool.JkModelMethod Maven / Gradle / Ivy

There is a newer version: 0.7.0.RELEASE
Show newest version
package org.jerkar.tool;

import java.util.LinkedList;
import java.util.List;

import org.jerkar.api.utils.JkUtilsAssert;

/**
 * Reference to a build method (callable Jerkar from command line). A build
 * method can be defined on a build class or on a plug-in.
 * 
 * @author Jerome Angibaud
 */
public final class JkModelMethod {

    /**
     * Creates a build method defined on the build class.
     */
    public static JkModelMethod normal(String name) {
        return new JkModelMethod(name, null);
    }

    /**
     * Creates a list of build method reference defined on the build class.
     */
    public static List normals(String... names) {
        final List result = new LinkedList();
        for (final String name : names) {
            result.add(JkModelMethod.normal(name));
        }
        return result;
    }

    /**
     * Creates a build method reference that is defined on a plugin.
     */
    public static JkModelMethod pluginMethod(Class pluginClass,
            String methodName) {
        return new JkModelMethod(methodName, pluginClass);
    }

    private final String methodName;

    private final Class pluginClass;

    /**
     * Returns the name of the method.
     */
    public String name() {
        return methodName;
    }

    /**
     * Returns the plugin on which this method is defined. Returns
     * null if defined on a build class.
     */
    public Class pluginClass() {
        return pluginClass;
    }

    private JkModelMethod(String methodName, Class pluginClass) {
        super();
        JkUtilsAssert.isTrue(methodName != null && !methodName.isEmpty(),
                "PluginName can' t be null or empty");
        this.methodName = methodName;
        this.pluginClass = pluginClass;
    }

    /**
     * Returns true if this method is defined on a plug-in.
     */
    public boolean isMethodPlugin() {
        return pluginClass != null;
    }

    @Override
    public String toString() {
        if (pluginClass == null) {
            return methodName;
        }
        return pluginClass.getName() + "#" + methodName;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy