public class Introspection extends Object
java.beans.Introspector
that is tailored to
conversion of bean data into other forms. Uses the following rules to find
the getters and setters of an introspected class:
javax.beans.Introspector
looks at parameter type, and
attempts to match getters and setters. This method looks only at the
method name, and will return any method whose name starts with "get"
or "is".
javax.beans.Introspector
has camel-casing rules that do
not always correspond to programmer intent -- in particular, two
initial capitals are not camelcased.
String
. Driven by the use of
this introspector to translate to/from a text format.
Object
javax.beans.Introspector
allows specific control over the
parts of the class hierarchy to be introspected; by default, it will
include methods defined by Object
. We don't care about
those, but assume any other class in the hierarchy to be important.
javax.beans.Introspector
maintains its own cache of methods.
Since it is loaded by the bootstrap classloader, and thus never released,
this can wreak havoc when used by a library in an application server. We
separate introspection and caching; see IntrospectionCache
for
the latter.
setAccessible()
Introspector
to
mark each method as accessible (but then you can't run in sandboxes).
Constructor and Description |
---|
Introspection(Class<?> klass)
Introspects the specified class, per the rules above.
|
Introspection(Class<?> klass,
boolean setAccessible)
Introspects the specified class, per the rules above.
|
Modifier and Type | Method and Description |
---|---|
Method |
getter(String propName)
Returns the getter method for the named property,
null
no method is known (all properties returned by propertyNames()
must have getters, but may not have setters). |
Set<String> |
propertyNames()
Returns the property names for the specified class.
|
Method |
setter(String propName)
Returns the setter method for the named property,
null
if unable to find a method. |
Class<?> |
type(String propName)
Returns the type of the named property, taken from the return type
of the property's getter.
|
public Introspection(Class<?> klass)
IntrospectionException
- on any error (this will always wrap
an underlying exception, typically one of the checked exceptions
thrown by the reflection mechanism).public Introspection(Class<?> klass, boolean setAccessible)
public Set<String> propertyNames()
Names are processed by Introspector.decapitalize()
, so
will be consistent with the bean specification.
public Method getter(String propName)
null
no method is known (all properties returned by propertyNames()
must have getters, but may not have setters).public Method setter(String propName)
null
if unable to find a method.