private static Engine getEngineForName(String engineClass) throws Exception { try { Class<Engine> engineCls = ReflectionUtil.loadServiceClass(engineClass, Engine.class); return getEngineByClass(engineCls); } catch (Exception e) { throw new Exception(String.format("Engine instance %s cannot be created.", engineClass), e); } }
private <T extends LimbusPlugin> T getPluginFromRegistry(String classname, Class<T> expectedType) throws LimbusClasspathException { LimbusPlugin plugin = pluginRegistry.get(classname); try { return ReflectionUtil.getAsExpectedType(plugin, expectedType); } catch (IllegalTypeException e) { throw new LimbusClasspathException( String.format("Requested plugin does not have the expected type.\nExpected type: %s\nActual type:%s", expectedType.getName(), plugin.getClass() .getName())); } }
@SuppressWarnings("unchecked") protected I createMulticasterProxy(Class<I> subscriberInterface, InvocationHandler handler) { ClassLoader classLoader = ReflectionUtil.getClassLoader(getClass()); Object proxy = Proxy.newProxyInstance(classLoader, new Class[] { subscriberInterface }, handler); return (I) proxy; }
/** * Creates an {@link EventMulticaster} for the specified subscriber type. The {@link EventMulticaster} created will * forward thrown exceptions from subscribers. <b>Note: An exception aborts the notifaction of further * subscribers.</b> * * @param subscriberType * The subscriber interface. * * @return Returns the {@link EventMulticaster}. */ public static <I> EventMulticaster<I> create(Class<I> subscriberType) { Lang.denyNull("subscriber type", subscriberType); ReflectionUtil.denyNotInterface(subscriberType); MulticastHandler<I> handler = new MulticastHandler<I>(subscriberType); return handler; }
/** * Loads a class of type {@link Action} from a given classname. * * @param classname * the classname * @return the action class * @throws ActionException * Thrown, if class could not be found. */ protected Class<?> loadActionClass(String classname) throws ActionException { try { Class<?> actionClass = ReflectionUtil.loadServiceClass(classname, IInitializable.class, LimbusActionService.class.getClassLoader()); return actionClass; } catch (Exception e) { throw new ActionException(String.format("The action class \'%s\' was not found.", classname), e); } }
private <T extends LimbusPlugin> T createPlugin(String classname, Class<T> expectedType) throws LimbusClasspathException { // schuettec - 06.10.2016 : Class loading without running plugin code, no LimbusContextAction needed. denyClassNotFound(getClassloader(), classname); // schuettec - 06.10.2016 : Class loading without running plugin code, no LimbusContextAction needed. boolean isPlugin = isLimbusPlugin(getClassloader(), classname); if (isPlugin) { // schuettec - 06.10.2016 : LimbusContextAction is used internally in the following method. LimbusPlugin limbusPlugin = getLimbusPlugin(classname); return ReflectionUtil.getAsExpectedType(limbusPlugin, expectedType); } else { throw new LimbusClasspathException(String.format("The class %s is not a Limbus plugin.", classname)); } }
Class<Permission> permissionType = ReflectionUtil.loadServiceClass(permissionClass, Permission.class, classLoader); Constructor<Permission> constructor = permissionType.getConstructor(String.class, String.class);