|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.mmm.util.component.base.AbstractComponent
net.sf.mmm.util.component.base.AbstractLoggableComponent
net.sf.mmm.util.pojo.descriptor.impl.DefaultPojoDescriptorEnhancer
@Singleton @Named public class DefaultPojoDescriptorEnhancer
This is an implementation of the PojoDescriptorEnhancer interface
that scans all
PropertyDescriptors for accessing Collections, Map
s or arrays. For such PojoPropertyDescriptors additional
accessors that are NOT already present are
created and added.
In a first step the 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.
In a second step 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:
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.
| Field Summary | |
|---|---|
private boolean |
addSingularAccessors
|
private boolean |
addVirtualAccessors
|
private PojoDescriptorDependencies |
dependencies
|
private Singularizer |
singularizer
The singularizer. |
| Constructor Summary | |
|---|---|
DefaultPojoDescriptorEnhancer()
The constructor. |
|
DefaultPojoDescriptorEnhancer(boolean addSingularAccessors,
boolean addVirtualAccessors)
The constructor. |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent |
|---|
getLogger, setLogger |
| Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent |
|---|
doInitialized, getInitializationState, initialize |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private Singularizer singularizer
private final boolean addSingularAccessors
DefaultPojoDescriptorEnhancer(boolean, boolean)private final boolean addVirtualAccessors
DefaultPojoDescriptorEnhancer(boolean, boolean)private PojoDescriptorDependencies dependencies
getDependencies()| Constructor Detail |
|---|
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 PojoPropertyAccessors 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
PojoPropertyAccessors are created and added as long as
senseful and no such PojoPropertyAccessor already exists.| Method Detail |
|---|
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.@Inject 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()
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)
descriptor.
enhanceDescriptor in interface PojoDescriptorEnhancerdescriptor - is the descriptor to enhance.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||