public abstract class BaseObjectInspector extends Object implements DomInspector<Element>
Handles iterating over an Object for properties and actions, and supporting pluggable property and action conventions.
In general BaseObjectInspector
inspects objects, not classes. It will
return null if the object value is null, rather than returning the properties of its class. This
is generally what is expected. In particular, WidgetProcessor
s such as binding
implementations would not expect to be given a list of properties and asked to bind to a null
object.
However, there are special concessions:
BaseObjectInspector
is pointed directly at a type (ie. names ==
null), it will return properties even if the actual value is null. This is important so we can
inspect parameterized types of Collections without having to iterate over and grab the first
element in that Collection.PropertyStyle
, some support class
traversal (eg. StaticPropertyStyle
)Modifier and Type | Field and Description |
---|---|
protected LogUtils.Log |
mLog |
Modifier | Constructor and Description |
---|---|
protected |
BaseObjectInspector() |
protected |
BaseObjectInspector(BaseObjectInspectorConfig config)
Config-based constructor.
|
Modifier and Type | Method and Description |
---|---|
protected Map<String,Action> |
getActions(String type) |
protected Map<String,Property> |
getProperties(String type) |
String |
inspect(Object toInspect,
String type,
String... names)
Inspect the given Object according to the given path, and return the result as a String
conforming to inspection-result-1.0.xsd.
|
protected Map<String,String> |
inspectAction(Action action)
Inspect the given action and return a Map of attributes.
|
Element |
inspectAsDom(Object toInspect,
String type,
String... names)
Optimized verison of
inspect that avoids DOM serialization/deserialization. |
protected Map<String,String> |
inspectEntity(String declaredClass,
String actualClass)
Inspect the given entity's class (not its child properties/actions) and return a Map
of attributes.
|
protected Map<String,String> |
inspectParent(Object parentToInspect,
Property propertyInParent)
Inspect the parent property leading to the
toInspect . |
protected Map<String,String> |
inspectProperty(Property property)
Inspect the given property and return a Map of attributes.
|
protected Map<String,String> |
inspectTrait(Trait trait)
Inspect the given trait and return a Map of attributes.
|
protected void |
inspectTraits(Object toInspect,
String type,
Element toAddTo)
Inspect the
toInspect for properties and actions. |
protected boolean |
shouldInspectPropertyAsEntity(Property property)
Whether to additionally inspect each child property using
inspectEntity from its
object level. |
protected final LogUtils.Log mLog
protected BaseObjectInspector()
protected BaseObjectInspector(BaseObjectInspectorConfig config)
BaseObjectInspector-derived inspectors should generally support configuration, to allow configuring property styles and action styles.
public final String inspect(Object toInspect, String type, String... names)
This method is marked final
because most Metawidget implementations will call
inspectAsDom
directly instead. So subclasses need to override
inspectAsDom
, not inspect
.
public Element inspectAsDom(Object toInspect, String type, String... names)
DomInspector
inspect
that avoids DOM serialization/deserialization.inspectAsDom
in interface DomInspector<Element>
protected Map<String,String> inspectParent(Object parentToInspect, Property propertyInParent) throws Exception
toInspect
. Often the parent property
contains useful annotations, such as UiLookup
.
This method can be overridden by clients wishing to modify the parent inspection process.
parentToInspect
- the parent to inspect. Can be null (eg. when using static inspection). May be
useful to clients in determining the context of the subsequent
inspectTrait and inspectProperty calls (eg.
they relate to the parent, not the normal toInspect)propertyInParent
- the property in the parent that points to the original toInspectException
protected void inspectTraits(Object toInspect, String type, Element toAddTo) throws Exception
toInspect
for properties and actions.
This method can be overridden by clients wishing to modify the inspection process. Most
clients will find it easier to override one of the sub-methods, such as
inspectTrait
or inspectProperty
.
toInspect
- the object to inspect. May be nullclazz
- the class to inspect. If toInspect is not null, will be the actual class of
toInspect. If toInspect is null, will be the class to lookupException
protected Map<String,String> inspectEntity(String declaredClass, String actualClass) throws Exception
Note: for convenience, this method does not expect subclasses to deal with DOMs and Elements. Those subclasses wanting more control over these features should override methods higher in the call stack instead.
Does nothing by default. For example usage, see PropertyTypeInspector
.
declaredClass
- the class passed to inspect
, or the class declared by the Object's
parent (ie. its getter method)actualClass
- the actual class of the Object. If you are searching for annotations, generally
you should inspect actualClass rather than declaredClassException
protected Map<String,String> inspectTrait(Trait trait) throws Exception
A 'trait' is an interface common to both Property
and Action
, so
you can override this single method if your annotation is applicable to both. For example,
UiLabel
.
In the event of an overlap between the attributes set by inspectTrait
and those
set by inspectProperty
/inspectAction
, the latter will receive
precedence.
Note: for convenience, this method does not expect subclasses to deal with DOMs and Elements. Those subclasses wanting more control over these features should override methods higher in the call stack instead.
Does nothing by default.
trait
- the trait to inspectException
protected Map<String,String> inspectProperty(Property property) throws Exception
Note: for convenience, this method does not expect subclasses to deal with DOMs and Elements. Those subclasses wanting more control over these features should override methods higher in the call stack instead.
Does nothing by default.
property
- the property to inspectException
protected Map<String,String> inspectAction(Action action) throws Exception
Note: for convenience, this method does not expect subclasses to deal with DOMs and Elements. Those subclasses wanting more control over these features should override methods higher in the call stack instead.
Does nothing by default.
action
- the action to inspectException
protected boolean shouldInspectPropertyAsEntity(Property property)
inspectEntity
from its
object level.
This can be useful if the property's value defines useful class-level semantics (eg.
false
by default.
Returns false
by default. For example usage, see
PropertyTypeInspector
.
property
- the property to inspectCopyright © 2015. All Rights Reserved.