/** * Returns the field definition for the named field. Field must be a component type. * * @param clazz Class to be searched. * @param name Name of the field. * @return The corresponding field definition, or null if no matching field was found. */ private static Field findField(Class<?> clazz, String name) { try { Field result = FieldUtils.getField(clazz, name, true); return isComponent(result.getType()) ? result : null; } catch (Exception e) { return null; } }
/** * Recursively scans the controller's class and superclasses for {@literal @EventHandler} * -annotated methods. * * @param instance Controller to be wired. * @param root The root component used to resolve component names. */ public static void wire(Object instance, BaseComponent root) { Class<?> clazz = instance.getClass(); while (clazz != Object.class) { wire(instance, root, clazz); clazz = clazz.getSuperclass(); } }
Set<String> targets = asSet(annot.target()); Set<String> types = asSet(annot.value()); BaseComponent component = null; component = isComponent(clazz) ? (BaseComponent) instance : root; } else if (target.startsWith("@")) { Field field = findField(clazz, target.substring(1));
public BaseComponent() { componentDefinition = ComponentRegistry.getInstance().get(getClass()); namespace = this instanceof INamespace; EventHandlerScanner.wire(this, this); }
/** * Wires a controller's annotated components and event handlers, using this component to resolve * name references. * * @param controller The controller to wire. If a string, is assumed to be the name of the * controller's implementation class in which case an instance of that class is * created. */ @PropertySetter(value = "controller", defer = true) public void wireController(Object controller) { if (controller == null) { throw new ComponentException("Controller is null or could not be resolved."); } if (controller instanceof String) { try { controller = "self".equals(controller) ? this : Class.forName((String) controller).newInstance(); } catch (Exception e) { throw MiscUtil.toUnchecked(e); } } WiredComponentScanner.wire(controller, this); EventHandlerScanner.wire(controller, this); if (controller instanceof IAutoWired) { ((IAutoWired) controller).afterInitialized(this); } }