19 package org.turro.action;
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
25 import java.util.concurrent.locks.Lock;
26 import java.util.concurrent.locks.ReentrantLock;
27 import org.turro.string.Strings;
28 import org.turro.annotation.ElephantPlugin;
29 import org.turro.reflection.ClassNames;
30 import org.turro.reflection.Reflections;
40 private static List<IElephantPlugin> _plugins;
41 private static List<Class> _pluginClass;
42 private static final Lock lock =
new ReentrantLock();
44 public static Map<String, Object>
execute(String name, Map params) {
46 Map<String, Object> results =
new HashMap<>();
48 if(iPlugin.itsMe(name)) {
49 iPlugin.setContext(params, results);
51 if(iPlugin.stopPropagating())
break;
63 for(Class pclass : _pluginClass) {
64 if(Reflections.of(pclass).canCast(jclass)) {
65 if(Strings.isBlank(label) ||
67 return (T) Reflections.of(pclass).instance();
74 private static void loadPlugins() {
75 if(_plugins ==
null) {
78 if(_plugins ==
null) {
79 _plugins =
new ArrayList<>();
80 _pluginClass =
new ArrayList<>();
81 List<String> plugins = ClassNames.cached().byAnnotation(
ElephantPlugin.class.getName());
83 for(String plugin : plugins) {
84 Class iPluginClass = Reflections.check(plugin);
85 if(iPluginClass !=
null) {
86 _pluginClass.add(iPluginClass);
90 _plugins.add(iPlugin);
static< T > T loadImplementation(Class< T > jclass, String label)
static Map< String, Object > execute(String name, Map params)
static< T > T loadImplementation(Class< T > jclass)