org.nuiton.topia.persistence.util
Class EntityListUpdator<P extends TopiaEntity,E extends TopiaEntity>

java.lang.Object
  extended by org.nuiton.topia.persistence.util.EntityListUpdator<P,E>
Type Parameters:
P - type of parent of childs
E - type of child
All Implemented Interfaces:
ListUpdator<P,E>

public class EntityListUpdator<P extends TopiaEntity,E extends TopiaEntity>
extends Object
implements ListUpdator<P,E>

A implementation of ListUpdator for TopiaEntity type.

Some factory methods are defined to simplify the generic cast, prefer used them instead of the (protected) constructor.

Author:
tchemit

Field Summary
protected  Method addMethod
           
protected  PropertyDescriptor descriptor
          descriptor of the filed containing the childs
protected  Method emptyMethod
           
protected  Method getMethod
           
protected  String propertyName
          name of the field containing the childs
protected  Method removeAllMethod
           
protected  Method removeMethod
           
protected  Method sizeMethod
           
 
Constructor Summary
protected EntityListUpdator(Class<P> parentClass, Class<E> childClass, String propertyName)
           
 
Method Summary
 void addToList(P parent, E bean)
          Add a erntity to his parent
 E getChild(P parent, String topiaId)
          Obtain a child from the entity given his id.
 Collection<E> getChilds(P parent)
          Obtain the collection of childs from the entity.
 String getPropertyName()
          Obtain the name of the property containing childs.
protected static void invoke(Method m, Object bean, Object... args)
           
protected static
<V> V
invokeWithResult(Method m, Object bean, Object... args)
           
 boolean isEmpty(P parent)
          Tests if the given entity has some childs.
static
<P extends TopiaEntity,E extends TopiaEntity>
EntityListUpdator<P,E>
newEntityListUpdator(Class<P> parentClass, Class<E> childClass, String propertyName)
           
 void removeAll(P parent)
          Remove all childs of the given parent.
 void removeFromList(P parent, E bean)
          Remove from a prent entity a given child.
 void setChilds(P parent, Collection<E> childs)
          Set the childs of an entity
 int size(P parent)
          Obtain the number of childs for the given parent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

propertyName

protected String propertyName
name of the field containing the childs


descriptor

protected PropertyDescriptor descriptor
descriptor of the filed containing the childs


getMethod

protected Method getMethod

addMethod

protected Method addMethod

removeMethod

protected Method removeMethod

removeAllMethod

protected Method removeAllMethod

sizeMethod

protected Method sizeMethod

emptyMethod

protected Method emptyMethod
Constructor Detail

EntityListUpdator

protected EntityListUpdator(Class<P> parentClass,
                            Class<E> childClass,
                            String propertyName)
Method Detail

newEntityListUpdator

public static <P extends TopiaEntity,E extends TopiaEntity> EntityListUpdator<P,E> newEntityListUpdator(Class<P> parentClass,
                                                                                                        Class<E> childClass,
                                                                                                        String propertyName)

getPropertyName

public String getPropertyName()
Description copied from interface: ListUpdator
Obtain the name of the property containing childs.

Specified by:
getPropertyName in interface ListUpdator<P extends TopiaEntity,E extends TopiaEntity>
Returns:
the name of the property containing childs.

getChild

public E getChild(P parent,
                  String topiaId)
Description copied from interface: ListUpdator
Obtain a child from the entity given his id.

Specified by:
getChild in interface ListUpdator<P extends TopiaEntity,E extends TopiaEntity>
Parameters:
parent - the entity to query
topiaId - the id of the researched child entity.
Returns:
the child entity or null, if not found.

getChilds

public Collection<E> getChilds(P parent)
Description copied from interface: ListUpdator
Obtain the collection of childs from the entity.

Specified by:
getChilds in interface ListUpdator<P extends TopiaEntity,E extends TopiaEntity>
Parameters:
parent - the entity to query.
Returns:
the collection of childs

size

public int size(P parent)
Description copied from interface: ListUpdator
Obtain the number of childs for the given parent.

Specified by:
size in interface ListUpdator<P extends TopiaEntity,E extends TopiaEntity>
Parameters:
parent - the entity to query
Returns:
the number of childs for the given entity

isEmpty

public boolean isEmpty(P parent)
Description copied from interface: ListUpdator
Tests if the given entity has some childs.

Specified by:
isEmpty in interface ListUpdator<P extends TopiaEntity,E extends TopiaEntity>
Parameters:
parent - the entity to query
Returns:
true is the given parent has no child.

setChilds

public void setChilds(P parent,
                      Collection<E> childs)
Description copied from interface: ListUpdator
Set the childs of an entity

Specified by:
setChilds in interface ListUpdator<P extends TopiaEntity,E extends TopiaEntity>
Parameters:
parent - the entity to be setted
childs - the collection of childs to set.

addToList

public void addToList(P parent,
                      E bean)
               throws TopiaException
Description copied from interface: ListUpdator
Add a erntity to his parent

Specified by:
addToList in interface ListUpdator<P extends TopiaEntity,E extends TopiaEntity>
Parameters:
parent - the entity to modifiy
bean - the entity to add in parent.
Throws:
TopiaException - if any db problem while operation

removeFromList

public void removeFromList(P parent,
                           E bean)
                    throws TopiaException
Description copied from interface: ListUpdator
Remove from a prent entity a given child.

Specified by:
removeFromList in interface ListUpdator<P extends TopiaEntity,E extends TopiaEntity>
Parameters:
parent - the entity to modifiy
bean - the child to remove.
Throws:
TopiaException - if any pb while operation.

removeAll

public void removeAll(P parent)
Description copied from interface: ListUpdator
Remove all childs of the given parent.

Specified by:
removeAll in interface ListUpdator<P extends TopiaEntity,E extends TopiaEntity>
Parameters:
parent - the entity to modify

invoke

protected static void invoke(Method m,
                             Object bean,
                             Object... args)

invokeWithResult

protected static <V> V invokeWithResult(Method m,
                                        Object bean,
                                        Object... args)


Copyright © 2004-2012 CodeLutin. All Rights Reserved.