public Collection<Binding> wire(final BindingContext context) { final List<ObjectFieldMethod> methods = context.getAnnotatedParameterlessMethods(CallOnUpdate.class); final List<Binding> bindings = Lists.newArrayList(); for (final ObjectFieldMethod method : methods) { final CallOnUpdate callOnUpdate = method.getMethod().getAnnotation(CallOnUpdate.class); bindings.addAll(wire(callOnUpdate, context, method)); } return bindings; }
private static Collection<Binding> wire(final CallOnUpdate callOnUpdate, final BindingContext context, final ObjectFieldMethod method) { final String to = callOnUpdate.model(); final BindableModel model; if (Strings.isNullOrEmpty(to)) { Set<BindableModel> models = context.getBindableModels(); if (models.size() != 1) { throw new BindingException("more than one bindable model for empty 'to'"); //$NON-NLS-1$ } model = models.iterator().next(); } else { model = context.getBindableModel(to); if (model == null) { throw new BindingException("can't find method to bind to: " + to); //$NON-NLS-1$ } } final String[] ons = callOnUpdate.on(); List<Object> onObjects = BindingContext.getOnObjects(ons, model); Binding binding = makeBinding(method, onObjects); model.bind(binding); return ImmutableList.of(binding); }