com.cc.framework.util
Class Util

java.lang.Object
  extended bycom.cc.framework.util.Util

public abstract class Util
extends java.lang.Object

Utility class to compare/sort objects

Since:
1.0
Version:
$Revision: 1.28 $
Author:
Harald Schulz

Constructor Summary
private Util()
          Constructor
 
Method Summary
static void check(java.lang.Object bean, java.lang.String property, boolean checked)
          checks a property
static java.lang.Object getProperty(java.lang.Object bean, java.lang.String name)
          Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.
static java.lang.Class getPropertyType(java.lang.Object bean, java.lang.String name)
          Return the Java Class representing the property type of the specified property, or null if there is no such property for the specified bean.
static java.lang.Object getSafeProperty(java.lang.Object bean, java.lang.String name)
          Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.
static boolean isValidProperty(java.lang.Object bean, java.lang.String name)
          Checks if the current iteration element has the given property
static java.lang.Object max(java.lang.Comparable a, java.lang.Comparable b)
          Compares to objects for order
static java.lang.Object min(java.lang.Comparable a, java.lang.Comparable b)
          Compares two objects for order
static java.lang.Object min(java.lang.Comparable a, java.lang.Comparable b, java.lang.Comparable c)
          Compares three objects for order
static void setProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value)
           Set the specified property value, performing type conversions as required to conform to the type of the destination property.
static java.lang.Boolean toBoolean(java.lang.Object obj)
          Converts an object to a boolean if possible
static java.lang.Boolean toBoolean(java.lang.String str)
          Parses a string an returns a boolean value.
static void uncheck(java.lang.Object bean, java.lang.String property)
          Unchecks a checked property
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

private Util()
Constructor

Method Detail

max

public static java.lang.Object max(java.lang.Comparable a,
                                   java.lang.Comparable b)
Compares to objects for order

Parameters:
a - the Object1 to be compared.
b - the Object2 to be compared.
Returns:
Object

min

public static java.lang.Object min(java.lang.Comparable a,
                                   java.lang.Comparable b)
Compares two objects for order

Parameters:
a - the Object1 to be compared.
b - the Object2 to be compared.
Returns:
Object

min

public static java.lang.Object min(java.lang.Comparable a,
                                   java.lang.Comparable b,
                                   java.lang.Comparable c)
Compares three objects for order

Parameters:
a - the Object1 to be compared.
b - the Object2 to be compared.
c - the Object3 to be compared.
Returns:
Object

toBoolean

public static java.lang.Boolean toBoolean(java.lang.Object obj)
Converts an object to a boolean if possible

Parameters:
obj - The object to convert
Returns:
The boolean value

toBoolean

public static java.lang.Boolean toBoolean(java.lang.String str)
Parses a string an returns a boolean value.

Parameters:
str - The string to parse
Returns:
The boolean value

uncheck

public static void uncheck(java.lang.Object bean,
                           java.lang.String property)
                    throws java.lang.IllegalAccessException,
                           java.lang.NoSuchMethodException,
                           java.lang.reflect.InvocationTargetException
Unchecks a checked property

Parameters:
bean - the bean
property - The check property
Throws:
java.lang.IllegalAccessException - Property Setter is not accessible
java.lang.NoSuchMethodException - Property Setter is not available
java.lang.reflect.InvocationTargetException - Property Setter could not be called

check

public static void check(java.lang.Object bean,
                         java.lang.String property,
                         boolean checked)
                  throws java.lang.IllegalAccessException,
                         java.lang.NoSuchMethodException,
                         java.lang.reflect.InvocationTargetException
checks a property

Parameters:
bean - the bean
property - The check property
checked - check state
Throws:
java.lang.IllegalAccessException - Property Setter is not accessible
java.lang.NoSuchMethodException - Property Setter is not available
java.lang.reflect.InvocationTargetException - Property Setter could not be called

getPropertyType

public static java.lang.Class getPropertyType(java.lang.Object bean,
                                              java.lang.String name)
                                       throws java.lang.IllegalAccessException,
                                              java.lang.reflect.InvocationTargetException,
                                              java.lang.NoSuchMethodException
Return the Java Class representing the property type of the specified property, or null if there is no such property for the specified bean. This method follows the same name resolution rules used by getPropertyDescriptor(), so if the last element of a name reference is indexed, the type of the property itself will be returned. If the last (or only) element has no property with the specified name, null is returned.

Parameters:
bean - Bean for which a property descriptor is requested
name - Possibly indexed and/or nested name of the property for which a property descriptor is requested
Returns:
property type
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception
java.lang.NoSuchMethodException - if an accessor method for this property cannot be found

getProperty

public static java.lang.Object getProperty(java.lang.Object bean,
                                           java.lang.String name)
                                    throws java.lang.IllegalAccessException,
                                           java.lang.reflect.InvocationTargetException,
                                           java.lang.NoSuchMethodException
Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.

Parameters:
bean - Bean whose property is to be extracted
name - Possibly indexed and/or nested name of the property to be extracted
Returns:
property value
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception
java.lang.NoSuchMethodException - if an accessor method for this property cannot be found

isValidProperty

public static boolean isValidProperty(java.lang.Object bean,
                                      java.lang.String name)
Checks if the current iteration element has the given property

Parameters:
bean - Bean whose property is to be extracted
name - Possibly indexed and/or nested name of the property to be extracted
Returns:
true if the current bean possesses a matching property

getSafeProperty

public static java.lang.Object getSafeProperty(java.lang.Object bean,
                                               java.lang.String name)
Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.

Parameters:
bean - Bean whose property is to be extracted
name - Possibly indexed and/or nested name of the property to be extracted
Returns:
property value or null

setProperty

public static void setProperty(java.lang.Object bean,
                               java.lang.String name,
                               java.lang.Object value)
                        throws java.lang.IllegalAccessException,
                               java.lang.reflect.InvocationTargetException

Set the specified property value, performing type conversions as required to conform to the type of the destination property.

If the property is read only then the method returns without throwing an exception.

If null is passed into a property expecting a primitive value, then this will be converted as if it were a null string.

WARNING - The logic of this method is customized to meet the needs of populate(), and is probably not what you want for general property copying with type conversion. For that purpose, check out the copyProperty() method instead.

WARNING - PLEASE do not modify the behavior of this method without consulting with the Struts developer community. There are some subtleties to its functionality that are not documented in the Javadoc description above, yet are vital to the way that Struts utilizes this method.

Parameters:
bean - Bean on which setting is to be performed
name - Property name (can be nested/indexed/mapped/combo)
value - Value to be set
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception


Copyright © 2000-2005 SCC Informationssysteme GmbH. All Rights Reserved.