com.unitesk.atp.dynattrs
Class Accessor

java.lang.Object
  extended by com.unitesk.atp.dynattrs.Accessor

public class Accessor
extends Object

This is a collection of static methods to work with different implementations of attributes.

Version:
$Id: Accessor.java,v 1.8 2006/02/09 06:30:07 all-x Exp $
Author:
Alexey Demakov, Alexander Monakhov

Constructor Summary
Accessor()
           
 
Method Summary
static String capitalize(String s)
          Converts the first char of a string to upper case.
static String decapitalize(String s)
          Converts the first char of a string to lower case.
static Object getAttribute(Object obj, String name)
          Returns value of attribute of the specified object.
static Object getAttribute(Object obj, String path, Attributed variableMap)
          Возвращает значение, на которое указывает заданная цепочка атрибутов для данного объекта.
static Object getAttribute(Object obj, String name, int index)
          Returns element of indexed attribute by index.
static Set getAttributeNames(Object obj)
          Returns the set of attribute names the specified object.
static Set getBeanClassPropertyNames(Class cls)
          Returns the set of names of bean properties for objects of the specified class.
static Object getBeanProperty(Object bean, String name)
          Returns a value of the specified bean property.
static Set getBeanPropertyNames(Object bean)
          Returns the set of names of bean properties of the specified object.
protected static Method getBeanPropertyReadMethod(Object bean, String name)
          Returns read method for the specified property of the specified bean.
protected static Method getBeanPropertyWriteMethod(Object bean, String name)
          Returns write method for the specified property of the specified bean.
static Object getIndexed(Object value, int index)
          Returns element of the specified index value.
static boolean hasAttribute(Object obj, String name)
          Checks existence of an attribute with the specified name of the specified object.
static boolean hasBeanProperty(Object bean, String name)
          Checks existence of bean property of the specified object.
static boolean isBeanPropertyIndexed(Object bean, String name)
          Checks if a value of the bean property can be indexed.
static boolean isBeanPropertyWritable(Object bean, String name)
          Checks writability of bean property of the specified object.
static boolean isID(String name)
          Checks whether the given name is a valid identifier.
static boolean isIndexed(Object value)
          Checks if value can be indexed.
static void setAttribute(Object obj, String name, int index, Object elem)
          Sets the new value of element of indexed attribute by index.
static void setAttribute(Object obj, String name, Object value)
          Sets the new value of attribute.
static void setBeanProperty(Object bean, String name, Object value)
          Sets the new value of the specified bean property.
static void setIndexed(Object value, int index, Object elem)
          Sets the new element's value of indexed value.
static int sizeAttribute(Object obj, String name)
          Returns size of indexed attribute of the specified object.
static int sizeIndexed(Object value)
          Returns the size of the indexed value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Accessor

public Accessor()
Method Detail

capitalize

public static String capitalize(String s)
Converts the first char of a string to upper case.

Parameters:
s - The string to convert.
Returns:
The parameter string with the first character converted to uppercase if possible.
Throws:
NullPointerException - when s == null.

decapitalize

public static String decapitalize(String s)
Converts the first char of a string to lower case.

Parameters:
s - The string to convert.
Returns:
The parameter string with the first character converted to lowercase if possible.
Throws:
NullPointerException - when s == null.

hasBeanProperty

public static boolean hasBeanProperty(Object bean,
                                      String name)
Checks existence of bean property of the specified object.

Parameters:
bean - The specified object.
name - The specified bean property name.
Returns:
true if there are bean property read method.
Throws:
NullPointerException - If bean is null.
AttributeException - Some possible reasons:
  • name == null
(analyze exception parameters).
See Also:
getBeanPropertyReadMethod(Object,String)

isBeanPropertyWritable

public static boolean isBeanPropertyWritable(Object bean,
                                             String name)
Checks writability of bean property of the specified object.

Parameters:
bean - The specified object.
name - The specified bean property name.
Returns:
true if there are bean property write method.
Throws:
NullPointerException - If bean is null.
AttributeException - Some possible reasons:
  • name == null
(analyze exception parameters).
See Also:
getBeanPropertyWriteMethod(Object,String)

getBeanProperty

public static Object getBeanProperty(Object bean,
                                     String name)
Returns a value of the specified bean property.

Parameters:
bean - The specified object.
name - The specified bean property name.
Returns:
The value of bean property of specified object.
Throws:
NullPointerException - If bean is null.
AttributeException - Some possible reasons:
  • name == null
  • there is no attribute with the specified name
  • there was an underlying exception
(analyze exception parameters).
See Also:
hasBeanProperty(Object,String)

isBeanPropertyIndexed

public static boolean isBeanPropertyIndexed(Object bean,
                                            String name)
Checks if a value of the bean property can be indexed. This method uses getBeanProperty(bean,name) to get property value.

Parameters:
bean - The specified object.
name - The specified bean property name.
Returns:
true if value of bean property is indexed.
Throws:
NullPointerException - If bean is null.
AttributeException - Some possible reasons:
  • name == null
  • there is no attribute with the specified name
  • attribute value is null
  • there was an underlying exception
(analyze exception parameters).
AttributeException - If bean property with the specified name doesn't exist (cause == null), or there was an underlying exception (see cause).

setBeanProperty

public static void setBeanProperty(Object bean,
                                   String name,
                                   Object value)
Sets the new value of the specified bean property.

Parameters:
bean - The specified object.
name - The specified bean property name.
value - The new value of bean property.
Throws:
NullPointerException - If bean is null.
AttributeException - Some possible reasons:
  • name == null
  • there is no attribute with the specified name
  • there was an underlying exception
(analyze exception parameters).

getBeanPropertyNames

public static Set getBeanPropertyNames(Object bean)
Returns the set of names of bean properties of the specified object.

Parameters:
bean - The specified object.
Returns:
The set that contains names of all object's bean properties.
Throws:
NullPointerException - If bean is null.

getBeanClassPropertyNames

public static Set getBeanClassPropertyNames(Class cls)
Returns the set of names of bean properties for objects of the specified class.

Parameters:
cls - The specified class.
Returns:
The set that contains names of bean properties for objects of the specified class.
Throws:
NullPointerException - If cls is null.

isIndexed

public static boolean isIndexed(Object value)
Checks if value can be indexed. A value is indexed if it is an array or instance of List. null is not indexed value.

Parameters:
value - The specified value.
Returns:
true if the specified value is array or instance of List.

sizeIndexed

public static int sizeIndexed(Object value)
Returns the size of the indexed value.

Parameters:
value - The specified indexed value.
Returns:
Size of the specified indexed value.
Throws:
NullPointerException - If the specified value is null.
ClassCastException - If the specified value is not indexed.

getIndexed

public static Object getIndexed(Object value,
                                int index)
Returns element of the specified index value.

Parameters:
value - The specified indexed value.
index - The specified index.
Returns:
An element of array or list with the specified index.
Throws:
NullPointerException - If the specified value is null.
ClassCastException - If the specified value is not indexed.
IndexOutOfBoundsException - If the specified index is out of bounds of indexed value.

setIndexed

public static void setIndexed(Object value,
                              int index,
                              Object elem)
Sets the new element's value of indexed value.

Parameters:
value - The specified indexed value.
index - The specified index.
elem - The new value of element.
Throws:
NullPointerException - If value is null.
ClassCastException - If the specified value is not indexed.
IndexOutOfBoundsException - If the specified index is out of bounds of indexed value.

hasAttribute

public static boolean hasAttribute(Object obj,
                                   String name)
Checks existence of an attribute with the specified name of the specified object.

Parameters:
obj - The specified object.
name - The specified attribute name.
Returns:
If obj implements Attributed interface use its method to get attribute value. Otherwise check existence of bean property.
Throws:
NullPointerException - If obj is null.
AttributeException - Some possible reasons:
  • name == null
  • there was an underlying exception
(analyze exception parameters).
Since:
3.6.3

getAttribute

public static Object getAttribute(Object obj,
                                  String name)
Returns value of attribute of the specified object.

Parameters:
obj - The specified object.
name - The specified attribute name.
Returns:
If obj implements Attributed interface use its method to get attribute value. Otherwise return bean property value.
Throws:
NullPointerException - If obj is null.
AttributeException - Some possible reasons:
  • name == null
  • there is no attribute with the specified name
  • there was an underlying exception
(analyze exception parameters).

sizeAttribute

public static int sizeAttribute(Object obj,
                                String name)
Returns size of indexed attribute of the specified object.

Parameters:
obj - The specified object.
name - The specified attribute name.
Returns:
If obj implements Attributed interface use its method to get attribute size. Otherwise get attribute value and return its size.
Throws:
NullPointerException - If obj is null.
AttributeException - Some possible reasons:
  • name == null
  • there is no attribute with the specified name
  • attribute value is not indexed
  • there was an underlying exception
(analyze exception parameters).

getAttribute

public static Object getAttribute(Object obj,
                                  String name,
                                  int index)
Returns element of indexed attribute by index.

Parameters:
obj - The specified object.
name - The specified attribute name.
index - The specified index.
Returns:
If obj implements Attributed interface use its method to get attribute element. Otherwise get attribute value and return its element by index.
Throws:
NullPointerException - If obj is null.
AttributeException - Some possible reasons:
  • name == null
  • there is no attribute with the specified name
  • attribute value is not indexed
  • there was an underlying exception
(analyze exception parameters).

setAttribute

public static void setAttribute(Object obj,
                                String name,
                                Object value)
Sets the new value of attribute. If obj implements Attributed interface use its method to set attribute. Otherwise tries to set bean property

Parameters:
obj - The specified object.
name - The specified attribute name.
value - The new value of attribute.
Throws:
AttributeException - Some possible reasons:
  • name == null
  • there is no attribute with the specified name
  • attribute is not writable
  • attribute element type is not compatible with elem
  • there was an underlying exception
(analyze exception parameters).
Since:
3.5.3

setAttribute

public static void setAttribute(Object obj,
                                String name,
                                int index,
                                Object elem)
Sets the new value of element of indexed attribute by index. If obj implements Attributed interface use its method to set attribute element. Otherwise get attribute value and set its element by index.

Parameters:
obj - The specified object.
name - The specified attribute name.
index - The specified index.
elem - The new value of element.
Throws:
AttributeException - Some possible reasons:
  • name == null
  • there is no attribute with the specified name
  • attribute is not writable
  • attribute is not indexed
  • attribute index is out of bounds
  • attribute element type is not compatible with elem
  • there was an underlying exception
(analyze exception parameters).

getAttributeNames

public static Set getAttributeNames(Object obj)
Returns the set of attribute names the specified object.

Parameters:
obj - The specified object.
Returns:
If obj implements Attributed interface use its method to get attribute names. Otherwise get bean property names.

isID

public static boolean isID(String name)
Checks whether the given name is a valid identifier. This method uses Character.isUnicodeIdentifierStart(char) and Character.isUnicodeIdentifierPart(char) methods.

Parameters:
name - the name to check
Returns:
true if the given name is a valid identifier, false otherwise.

getAttribute

public static Object getAttribute(Object obj,
                                  String path,
                                  Attributed variableMap)
Возвращает значение, на которое указывает заданная цепочка атрибутов для данного объекта. Цепочка атрибутов имеет следующий вид:

path ::= attribute ( "." attribute )* ;
attribute ::= <attr_name:ID> ( "[" index "]" )? ;
index ::= <index_var:ID> | number ;
number ::= ( "-" )? ( <DIGIT> )+ ;

Каждый элемент цепочки является либо именем атрибута, либо именем списочного атрибута с указанным в скобках индексом элемента. Индекс может быть задан именем переменной index_var, значение которой берется из variable_map как значение соответствующего атрибута, или целочисленным литералом number. Отрицательному индексу -i соответствует элемент списка с индексом L-i, где L - длина списка.

Значение, на которое указывает цепочка атрибутов, определяется рекурсивно:

Parameters:
obj - The specified object.
path - The chain of attribute names.
variableMap - Defined variables.
Returns:
The value pointed by path of attributes.
See Also:
getAttribute(Object,String), getAttribute(Object, String, int)

getBeanPropertyReadMethod

protected static Method getBeanPropertyReadMethod(Object bean,
                                                  String name)
Returns read method for the specified property of the specified bean.

Parameters:
bean - Object to get read method from.
name - Property name.
Returns:
Read method or null if object has no property with such name.
Throws:
NullPointerException - If bean is null.
AttributeException - Some possible reasons:
  • name == null
(analyze exception parameters).

getBeanPropertyWriteMethod

protected static Method getBeanPropertyWriteMethod(Object bean,
                                                   String name)
Returns write method for the specified property of the specified bean.

Parameters:
bean - Object to get write method from.
name - Property name.
Returns:
Write method or null if object has no property with such name.
Throws:
NullPointerException - If bean is null.
AttributeException - Some possible reasons:
  • name == null
(analyze exception parameters).


Copyright © 2001-2006 ISP RAS, RedVerst Group. All Rights Reserved.