sk.baka.ambient.commons
Class Binder

java.lang.Object
  extended by sk.baka.ambient.commons.Binder

public final class Binder
extends Object

Binds a POJO bean to a view. Currently only public fields are supported - no getters/setters.

Author:
Martin Vysny

Method Summary
static Map<Integer,String> bindBeanMap(Object bean, Map<String,Object> map, boolean beanToMap, boolean validate)
          Copies all properties annotated by Bind to a map.
static Map<Integer,String> bindBeanToEditor(Object bean, SharedPreferences.Editor editor, boolean validate)
          Copies all properties annotated by Bind to an editor.
static Map<Integer,String> bindBeanView(Object bean, View parent, boolean beanToView, boolean validate)
          Copies all properties annotated by Bind to the view.
static
<T> void
copy(T from, T to)
          Copies all bindable properties from given bean to given bean.
static
<V> void
put(String k, V v, Class<? extends V> type, SharedPreferences.Editor editor)
          Puts given object into an editor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

bindBeanMap

public static Map<Integer,String> bindBeanMap(Object bean,
                                              Map<String,Object> map,
                                              boolean beanToMap,
                                              boolean validate)
Copies all properties annotated by Bind to a map.

Parameters:
bean - the bean to copy from/to
map - the map to use
beanToMap - if true then data from the bean are copied into the map. If false then map's data will be copied into the bean.
validate - if true then validation constraints are checked.
Returns:
an empty map if no validation constraints were violated; a map of view id to an error message if violation occured.

bindBeanToEditor

public static Map<Integer,String> bindBeanToEditor(Object bean,
                                                   SharedPreferences.Editor editor,
                                                   boolean validate)
Copies all properties annotated by Bind to an editor.

Parameters:
bean - the bean to copy from
editor - the map to use
validate - if true then validation constraints are checked.
Returns:
an empty map if no validation constraints were violated; a map of view id to an error message if violation occured.

put

public static <V> void put(String k,
                           V v,
                           Class<? extends V> type,
                           SharedPreferences.Editor editor)
Puts given object into an editor.

Type Parameters:
V - the value type
Parameters:
k - key name
v - value
type - the value class
editor - the editor.

bindBeanView

public static Map<Integer,String> bindBeanView(Object bean,
                                               View parent,
                                               boolean beanToView,
                                               boolean validate)
Copies all properties annotated by Bind to the view.

Parameters:
bean - the bean to copy from/to
parent - the view to use for performing View lookup.
beanToView - if true then data from the bean are copied into the view. If false then view's data will be copied into the bean.
validate - if true then validation constraints are checked.
Returns:
an empty map if no validation constraints were violated; a map of view id to an error message if violation occurred.

copy

public static <T> void copy(T from,
                            T to)
Copies all bindable properties from given bean to given bean.

Type Parameters:
T - the bean type
Parameters:
from - source bean
to - target bean


Copyright © 2007-2008. All Rights Reserved.