sk.baka.ambient.commons
Class Binder

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

public final class Binder
extends java.lang.Object

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

Author:
Martin Vysny

Method Summary
static java.util.Map<java.lang.Integer,java.lang.String> bindBeanMap(java.lang.Object bean, java.util.Map<java.lang.String,java.lang.Object> map, boolean beanToMap, boolean validate)
          Copies all properties annotated by Bind to a map.
static java.util.Map<java.lang.Integer,java.lang.String> bindBeanToEditor(java.lang.Object bean, android.content.SharedPreferences.Editor editor, boolean validate)
          Copies all properties annotated by Bind to an editor.
static java.util.Map<java.lang.Integer,java.lang.String> bindBeanView(java.lang.Object bean, android.view.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(java.lang.String k, V v, java.lang.Class<? extends V> type, android.content.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 java.util.Map<java.lang.Integer,java.lang.String> bindBeanMap(java.lang.Object bean,
                                                                            java.util.Map<java.lang.String,java.lang.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 java.util.Map<java.lang.Integer,java.lang.String> bindBeanToEditor(java.lang.Object bean,
                                                                                 android.content.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(java.lang.String k,
                           V v,
                           java.lang.Class<? extends V> type,
                           android.content.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 java.util.Map<java.lang.Integer,java.lang.String> bindBeanView(java.lang.Object bean,
                                                                             android.view.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-2009. All Rights Reserved.