org.abstracthorizon.danube.beanconsole
Class BeanHelper

java.lang.Object
  extended by org.abstracthorizon.danube.beanconsole.BeanHelper

public class BeanHelper
extends Object

Helper class for manipulation of beans.

Author:
Daniel Sendula

Field Summary
static Object[] EMPTY_ARRAY
          Empty object array
 
Constructor Summary
BeanHelper()
           
 
Method Summary
static String[] convertPath(String path)
          Converts "/" delimited string into the array
protected static String createName(String path)
          Creates name of the bean from the given path.
static String createPath(String path)
          Creates path separated with ".".
static String createResourcePath(String path)
          This method ensures that component path is or empty string or a path that starts and ends with "/"
static String getAccessType(PropertyDescriptor property)
          Returns access type as in BeanDef for the given property
static Collection<MethodDescriptor> getMethodDescriptors(BeanInfo beanInfo)
          This method returns collection of method descriptors for given beanInfo.
static Object getPropertyValue(Object bean, PropertyDescriptor property)
          Returns property's value of the given bean
static String getPropertyValueAsString(Object bean, PropertyDescriptor property)
          Returns property's value as a string.
static String getPropertyValueAsString(Object object, String propertyName)
          Returns property's value as a string.
static boolean isFollowable(Class<?> cls)
          Returns true if given class is not String and not a primitive type.
static boolean isFollowable(Object object)
          Returns true if given object is not null and its class is not String and not a primitive type.
static Object navigate(Object from, String path)
          This method navigates through objects from given root object to the object specified by path.
static void prepare(Object object, Map<String,Object> result)
          This method set model parameters needed for preseting given object.
static String stackTrace(Throwable t)
          Returns stack trace of given throwable object as a string.
static String toString(Object object)
          Presents given object as a string.
static String toTypeString(Class<?> type)
          Presetns a class as a string
static String toTypeString(Object object)
          result.toString() Presetns the object's class as a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

public static final Object[] EMPTY_ARRAY
Empty object array

Constructor Detail

BeanHelper

public BeanHelper()
Method Detail

navigate

public static Object navigate(Object from,
                              String path)
                       throws BeanAccessException
This method navigates through objects from given root object to the object specified by path.

Algorithm for navigating through objects is as following (in that order):

Each step is performed if previous returns null (or an exception that is in this case ignored).

Parameters:
from - root object
path - path
Returns:
resulted object
Throws:
BeanAccessException - if there is a problem in dereferencing

prepare

public static void prepare(Object object,
                           Map<String,Object> result)
This method set model parameters needed for preseting given object. It sets following model parameters:

toString

public static String toString(Object object)
Presents given object as a string.

Parameters:
object - object
Returns:
string representation of the object

toTypeString

public static String toTypeString(Class<?> type)
Presetns a class as a string

Parameters:
type - the class
Returns:
string representation of the class

toTypeString

public static String toTypeString(Object object)
result.toString() Presetns the object's class as a string

Parameters:
object - the class
Returns:
string representation of the object's class

createName

protected static String createName(String path)
Creates name of the bean from the given path.

Parameters:
path - the path
Returns:
name of the bean as last part of the path

createPath

public static String createPath(String path)
Creates path separated with ".". If path element contains dot then it is going to be enclosed in < and > symbols.

Parameters:
path - the path
Returns:
string representation of the path

createResourcePath

public static String createResourcePath(String path)
This method ensures that component path is or empty string or a path that starts and ends with "/"

Parameters:
path - component path
Returns:
updated path

convertPath

public static String[] convertPath(String path)
Converts "/" delimited string into the array

Parameters:
path - "/" delimited
Returns:
an array of elements

getAccessType

public static String getAccessType(PropertyDescriptor property)
Returns access type as in BeanDef for the given property

Parameters:
property - the property
Returns:
access type as in BeanDef

getPropertyValue

public static Object getPropertyValue(Object bean,
                                      PropertyDescriptor property)
Returns property's value of the given bean

Parameters:
bean - the bean
property - the property
Returns:
dereferenced property

getPropertyValueAsString

public static String getPropertyValueAsString(Object object,
                                              String propertyName)
Returns property's value as a string. It uses Object.toString() method.

Parameters:
object - the bean
property - the property
Returns:
property's value as a string

getPropertyValueAsString

public static String getPropertyValueAsString(Object bean,
                                              PropertyDescriptor property)
Returns property's value as a string. It uses Object.toString() method.

Parameters:
bean - the bean
property - the property
Returns:
property's value as a string

getMethodDescriptors

public static Collection<MethodDescriptor> getMethodDescriptors(BeanInfo beanInfo)
This method returns collection of method descriptors for given beanInfo. It filters out properties (getter and setter method) as well as methods whose parameters do not have property editors

Parameters:
beanInfo -
Returns:
collection of methods

isFollowable

public static boolean isFollowable(Class<?> cls)
Returns true if given class is not String and not a primitive type.

Parameters:
cls - the class
Returns:
true if given class is not String and not a primitive type.

isFollowable

public static boolean isFollowable(Object object)
Returns true if given object is not null and its class is not String and not a primitive type.

Parameters:
object - the object
Returns:
true if given object is not null and its class is not String and not a primitive type.

stackTrace

public static String stackTrace(Throwable t)
Returns stack trace of given throwable object as a string.

Parameters:
t - the throwable object
Returns:
stack trace of given throwable object as a string


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.