|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object texsoft.java.object.XsClassInspector
Inspects reflection for class/interface and its properties.
Given a class via reflection retrieve properties' types, classes, getters and setters.
Using the getPropertyType(), set() and get() methods it's easy to use reflection to manipulate instance of the class managed by the inspector.
The inspector manage only public setters and getter of the class. If a property has no setter it's considered readonly, if it has no getter it's considered writeonly. If a property has more than one setter for a property only the setter with an argument that exactly match the return type of the getter for that property is considered. The class type of a property is always determined by the return type ot the getter for that property.
This is the core class of the whole texsoft.java.object package.
Creation date: (26/11/2000 19.00.19)
Constructor Summary | |
XsClassInspector(java.lang.Class type)
Create a new inspector for class type. |
|
XsClassInspector(java.lang.Object obj)
Create a new inspector for class to which object obj belongs. |
|
XsClassInspector(java.lang.String name)
Creates a new inspector for class which name is name. |
Method Summary | |
java.lang.Object |
get(java.lang.Object obj,
java.lang.String prop)
Returns the value of the property prop of the object obj. |
java.lang.Class |
getClassType()
Returns the Class object for the class type handled by the inspector. |
java.lang.String[] |
getProperties()
Returns an array of the properties' names. |
int |
getPropertiesCount()
Returns the number of properties of the class inspected. |
java.lang.Class |
getPropertyType(java.lang.String prop)
Returns the class of the property named prop. |
java.lang.Class[] |
getSuperClasses()
Returns an array of the base classes of the class being inspected. |
boolean |
isReadable(java.lang.String prop)
Returns true if the property is readable, and can be get. |
boolean |
isWriteable(java.lang.String prop)
Returns true if the property is writeable, and can be set. |
java.lang.Object |
newInstance()
Create and returns a new instance for the class beeing inspected. |
void |
set(java.lang.Object obj,
java.lang.String prop,
boolean v)
Wrapper method that it's usefull to set a property from a primitive Java type. |
void |
set(java.lang.Object obj,
java.lang.String prop,
byte v)
Wrapper method that it's usefull to set a property from a primitive Java type. |
void |
set(java.lang.Object obj,
java.lang.String prop,
char v)
Wrapper method that it's usefull to set a property from a primitive Java type. |
void |
set(java.lang.Object obj,
java.lang.String prop,
double v)
Wrapper method that it's usefull to set a property from a primitive Java type. |
void |
set(java.lang.Object obj,
java.lang.String prop,
float v)
Wrapper method that it's usefull to set a property from a primitive Java type. |
void |
set(java.lang.Object obj,
java.lang.String prop,
int v)
Wrapper method that it's usefull to set a property from a primitive Java type. |
void |
set(java.lang.Object obj,
java.lang.String prop,
long v)
Wrapper method that it's usefull to set a property from a primitive Java type. |
void |
set(java.lang.Object obj,
java.lang.String prop,
java.lang.Object value)
Set the value of the property prop of the object obj to value. |
void |
set(java.lang.Object obj,
java.lang.String prop,
short v)
Wrapper method that it's usefull to set a property from a primitive Java type. |
java.lang.String |
toString()
Returns a string showing the properties of the inspected class (name, type, access). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public XsClassInspector(java.lang.Class type)
type
- class to be inspected.public XsClassInspector(java.lang.Object obj)
obj
- object whose class type has to be inspected.public XsClassInspector(java.lang.String name) throws java.lang.ClassNotFoundException
This constructor should not be used, the others that use a Class or an Object to initialize the inspector must be prefered.
name
- Name of the class to be inspected.
java.lang.ClassNotFoundException
- The exception is thrown if a class with the passed name does not exists.Method Detail |
public java.lang.Class getClassType()
public int getPropertiesCount()
public java.lang.String[] getProperties()
public final java.lang.Class getPropertyType(java.lang.String prop) throws XsObjectException
prop
- name of the property.
XsObjectException
- thrown if the property name passed does not match any class' property.public java.lang.Object newInstance() throws XsObjectException
XsObjectException
- thrown if a reflection error occurs creating the new instance.public java.lang.Object get(java.lang.Object obj, java.lang.String prop) throws XsObjectException
The object obj must be an instace of the class handled by the inspector or an instance of a class that extends the class handled by the inspector.
If the property prop does not esxist or can't be accessed for reading (because it's not public, or has no public getter) an exception will be thrown.
obj
- object whose property has to be read.prop
- name of the property to be read.
XsObjectException
- thrown if a reflection exception occurs getting the property value, if the
object being read is not or does not extends the inspected class, if the
inspected class has not a property with the given name, or if the property can't
be read (because it has not a getter or has a not public one).public void set(java.lang.Object obj, java.lang.String prop, java.lang.Object value) throws XsObjectException
The object obj must be an instace of the class handled by the inspector or an instance of a class that extends the class handled by the inspector.
If the property prop does not esxist or can't be accessed for writing (because it's not public, or has no public setter) an exception will be thrown.
This function correctly handle null
value, even when the
prop is a primitive type: numeric are set to 0, char to '\0' and
boolean to false
.
If obj is a String and the property type is not a String, the function try to do a conversion from String to the type of the property, using a conversion to primitive type or using constructor with String argument. This allows easy setting of property from String rapresentation of values.
obj
- object whose property has to be set.prop
- name of the property to be set.value
- specified the value to be set to the property, can be null
.
XsObjectException
- thrown if a reflection exception occurs setting the property value, if the
object being set is not or does not extends the inspected class, if the
inspected class has not a property with the given name, or if the property can't
be set (because it has not a setter or has a not public one).public void set(java.lang.Object obj, java.lang.String prop, byte v) throws XsObjectException
obj
- object whose property has to be set.prop
- name of the property to set.v
- value to be assigned to the property.
XsObjectException
- thrown if a reflection exception occurs setting the property value.set(Object, String, Object)
public void set(java.lang.Object obj, java.lang.String prop, short v) throws XsObjectException
obj
- object whose property has to be set.prop
- name of the property to set.v
- value to be assigned to the property.
XsObjectException
- thrown if a reflection exception occurs setting the property value.set(Object, String, Object)
public void set(java.lang.Object obj, java.lang.String prop, int v) throws XsObjectException
obj
- object whose property has to be set.prop
- name of the property to set.v
- value to be assigned to the property.
XsObjectException
- thrown if a reflection exception occurs setting the property value.set(Object, String, Object)
public void set(java.lang.Object obj, java.lang.String prop, long v) throws XsObjectException
obj
- object whose property has to be set.prop
- name of the property to set.v
- value to be assigned to the property.
XsObjectException
- thrown if a reflection exception occurs setting the property value.set(Object, String, Object)
public void set(java.lang.Object obj, java.lang.String prop, float v) throws XsObjectException
obj
- object whose property has to be set.prop
- name of the property to set.v
- value to be assigned to the property.
XsObjectException
- thrown if a reflection exception occurs setting the property value.set(Object, String, Object)
public void set(java.lang.Object obj, java.lang.String prop, double v) throws XsObjectException
obj
- object whose property has to be set.prop
- name of the property to set.v
- value to be assigned to the property.
XsObjectException
- thrown if a reflection exception occurs setting the property value.set(Object, String, Object)
public void set(java.lang.Object obj, java.lang.String prop, char v) throws XsObjectException
obj
- object whose property has to be set.prop
- name of the property to set.v
- value to be assigned to the property.
XsObjectException
- thrown if a reflection exception occurs setting the property value.set(Object, String, Object)
public void set(java.lang.Object obj, java.lang.String prop, boolean v) throws XsObjectException
obj
- object whose property has to be set.prop
- name of the property to set.v
- value to be assigned to the property.
XsObjectException
- thrown if a reflection exception occurs setting the property value.set(Object, String, Object)
public boolean isReadable(java.lang.String prop) throws XsObjectException
prop
- name of the property.
true
if the property is readable, and can be get.
XsObjectException
- thrown if the property does not exists for the inspected class.public boolean isWriteable(java.lang.String prop) throws XsObjectException
prop
- name of the property.
true
if the property is writeable, and can be set.
XsObjectException
- thrown if the property does not exists for the inspected class.public java.lang.Class[] getSuperClasses()
The classes into the array are ordered from the direct superclass of the class (index 0) to the Object class (last element of the array).
public java.lang.String toString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |