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

src.main.java.com.vincomobile.fw.basic.hooks.HookManager Maven / Gradle / Ivy

There is a newer version: 5.1.0-RELEASE
Show newest version
package com.vincomobile.fw.basic.hooks;

import com.vincomobile.fw.basic.tools.Converter;

import java.util.HashMap;
import java.util.Map;

public class HookManager {

    private static Map hooks = new HashMap<>();

    /**
     * Register a Hook
     *
     * @param hook Hook
     */
    public static void registerHook(Hook hook) {
        if (!Converter.isEmpty(hook.name)) {
            HookList list = hooks.get(hook.name);
            if (list == null) {
                list = new HookList();
                hooks.put(hook.name, list);
            }
            list.add(hook);
        }
    }

    /**
     * Execute all registered hooks
     *
     * @param name Hook name
     * @param arguments Hook arguments
     * @return Execution result
     */
    public static HookResult executeHook(String name, Object... arguments) {
        HookList list = hooks.get(name);
        HookResult result = new HookResult();
        if (list != null) {
            for (Hook hook: list.hooks) {
                hook.execute(result, arguments);
                if (!result.success)
                    break;
            }
        }
        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy