Exemple #1
0
 public void set(Object value)
     throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
   if (setter == null) {
     throw new IllegalStateException("can not call set() with no setter.");
   }
   boolean accessible = setter.getMethod().isAccessible();
   setter.getMethod().setAccessible(true);
   setter.getMethod().invoke(model, value);
   setter.getMethod().setAccessible(accessible);
 }
Exemple #2
0
 public Object get()
     throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
   if (getter == null) {
     throw new IllegalStateException("can not call get() with no getter.");
   }
   boolean accessible = getter.getMethod().isAccessible();
   getter.getMethod().setAccessible(true);
   Object value = getter.getMethod().invoke(model);
   getter.getMethod().setAccessible(accessible);
   return value;
 }
Exemple #3
0
 /**
  * Creates a new Mutator bound to the passed {@link BindingContext}.
  *
  * @param context the context for this {@link Mutator}
  * @param target the model and field to bind this {@link Mutator} to.
  * @return the {@link Mutator}
  * @throws IntrospectionException
  */
 public static Mutator create(BindingContext context, String target)
     throws IntrospectionException {
   final ObjectFieldMethod getter = context.findGetter(target);
   final ObjectFieldMethod setter = context.findSetter(target);
   if (getter == null && setter == null) {
     throw new IllegalArgumentException("could not find either getter/setter for " + target);
   }
   BindableModel model = null;
   BindableModel getterModel = null;
   BindableModel setterModel = null;
   if (getter != null) {
     getterModel = context.getFieldObject(getter.getField(), BindableModel.class);
     model = getterModel;
   }
   if (setter != null) {
     setterModel = context.getFieldObject(setter.getField(), BindableModel.class);
     model = setterModel;
   }
   if (getterModel != null && setterModel != null && getterModel != setterModel) {
     throw new IllegalStateException("setter and getter must be on same BindableModel.");
   }
   return new Mutator(getter, setter, model);
 }