public class DefaultPojoDescriptorEnhancer extends AbstractLoggableComponent implements PojoDescriptorEnhancer
PojoDescriptorEnhancer
interface that scans all
PropertyDescriptor
s for accessing
Collection
s, Map
s or arrays. For such PojoPropertyDescriptor
s additional
accessors
that are NOT already present are created and added. name
of the PojoPropertyDescriptor
is
singularized
. If a different singular form is determined, the
accessors
of the singular-named PojoPropertyDescriptor
are copied to the
original PojoPropertyDescriptor
if such accessors do NOT already exist. accessors
that are (still) NOT present in the original
PojoPropertyDescriptor
are created and added as virtual delegates on the container-typed getter (and
according setter for array-resizing if available). This will happen for the following modes:
For example the method
List < Foo > getChildren()is available via the
PojoPropertyDescriptor
named
children
.
Further the method
void addChild(Foo child)is available via the
PojoPropertyDescriptor
named
child
.
This enhancer makes the addChild
-method also available via children
which is the plural form of
child
. Further it will add the virtual accessors
as described above so it
behaves as if the following method would also be present:
Foo getChild(int index) { return getChildren().get(index); } void setChild(int index, Foo child) { getChildren().set(index, child); } void removeChild(Foo child) { getChildren().remove(child); } int getChildCount() { return getChildren().size(); }This makes it easier for generic access and allows ultimate flexibility since the explicit methods of a POJO always overrule the virtual accessors.
Modifier and Type | Field and Description |
---|---|
private boolean |
addSingularAccessors |
private boolean |
addVirtualAccessors |
private PojoDescriptorDependencies |
dependencies |
private Singularizer |
singularizer
The singularizer.
|
Constructor and Description |
---|
DefaultPojoDescriptorEnhancer()
The constructor.
|
DefaultPojoDescriptorEnhancer(boolean addSingularAccessors,
boolean addVirtualAccessors)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
private void |
addVirtualAccessor(AbstractPojoPropertyDescriptor propertyDescriptor,
PojoPropertyAccessor accessor)
This method adds the given
accessor to the given propertyDescriptor . |
protected void |
doInitialize()
This method performs the actual
initialization . |
void |
enhanceDescriptor(AbstractPojoDescriptor<?> descriptor)
This method performs the generic enhancements on the given
descriptor . |
protected PojoDescriptorDependencies |
getDependencies()
This method gets the dependencies required for this descriptor.
|
protected Singularizer |
getSingularizer()
This method gets the
Singularizer , which is used to determine singular forms so e.g. |
void |
setDependencies(PojoDescriptorDependencies dependencies)
This method sets the
dependencies . |
void |
setSingularizer(Singularizer singularizer)
This method injects the
Singularizer . |
createLogger, getLogger
doInitialized, getInitializationState, initialize
private Singularizer singularizer
private final boolean addSingularAccessors
private final boolean addVirtualAccessors
private PojoDescriptorDependencies dependencies
public DefaultPojoDescriptorEnhancer()
public DefaultPojoDescriptorEnhancer(boolean addSingularAccessors, boolean addVirtualAccessors)
addSingularAccessors
- - if true
each getter
that points to
an array, Collection
or Map
is scanned. If it has a plural form for that the
singular form can be determined
, the PojoPropertyAccessor
s of the
singular PojoPropertyDescriptor
are copied to the plural PojoPropertyDescriptor
as long as
no such PojoPropertyAccessor
already exists.addVirtualAccessors
- - if true
for each getter
that points
to an array, Collection
or Map
according virtual PojoPropertyAccessor
s are
created and added as long as senseful and no such PojoPropertyAccessor
already exists.protected Singularizer getSingularizer()
Singularizer
, which is used to determine singular forms so e.g. getChildren
and addChild
can be matched to the same property.Singularizer
to use.public void setSingularizer(Singularizer singularizer)
Singularizer
.singularizer
- is the Singularizer
to set.protected PojoDescriptorDependencies getDependencies()
@Inject public void setDependencies(PojoDescriptorDependencies dependencies)
dependencies
.dependencies
- are the PojoDescriptorDependencies
to set.protected void doInitialize()
AbstractComponent
initialization
. It is called when AbstractComponent.initialize()
is
invoked for the first time. super.
AbstractComponent.doInitialize()
.doInitialize
in class AbstractLoggableComponent
private void addVirtualAccessor(AbstractPojoPropertyDescriptor propertyDescriptor, PojoPropertyAccessor accessor)
accessor
to the given propertyDescriptor
.propertyDescriptor
- is the descriptor of the property where to add the given accessor
.accessor
- is the (virtual) accessor to add.public void enhanceDescriptor(AbstractPojoDescriptor<?> descriptor)
PojoDescriptorEnhancer
descriptor
.enhanceDescriptor
in interface PojoDescriptorEnhancer
descriptor
- is the descriptor to enhance.Copyright © 2001–2016 mmm-Team. All rights reserved.