BDO
- target typepublic abstract class Composite<BDO extends DataObject,X> extends java.lang.Object implements Contexed, TableStructureContributer<BDO>
Composite
adds behaviour to a DataObjectFactory
by composition but persisted to the same database table.
It is a TableStructureContributer
so specifies additional fields for the
Repository
and methods to customise the forms and may be extended to add
functionality based on those fields.
For this class to affect the table specification it needs to be registered before the
DataObjectFactory.setContext(uk.ac.ed.epcc.webapp.AppContext, String)
method is called.
The easiest way to do this is to specify them as configuration parameters.
You can create the composite during field initialisation. If you do this you MUST
call the setContext method from the constructor body in the same class not recurse to the superclass constructor that calls setContext.
This is because superclass constructors run before field initialisation but local constructor bodies run afterwards.
Composite
s that have a public constructor that takes the
DataObjectFactory
as the argument (optionally followed by a String), can be added to a factory
by setting a (comma separated) list of classdef or property class names in the parameter factory-tag.composites
and these will be added in the DataObjectFactory.setContext(uk.ac.ed.epcc.webapp.AppContext, String)
method and can therefore
modify the table specification. If the constructor takes the String parameter the construction tag of the composite will be passed.
The areas that Composite
s can customise can be extended by having a factory check all composites for specific interfaces for example
TableStructureDataObjectFactory
checks the composites for TransitionSource
If you find yourself testing for the existence of multiple composites at the same location consider extracting an interface for
that all the contributing composites can implement.
Each Composite
provides a type Class
that it is registered under. It should itself be assignable to that type. A factory cannot contain two Composite
s registered under the same class.
Any functionality that should only be included once (but has many implementations) should use the same registration class (which should be an interface or abstract supertype representing the operation)
and can be retrieved by the registration type. Otherwise composites usually register under their own type. This does mean that if you want to add several copies of the same composite you need to introduce
trivial sub-classes.
Composites augment a DataObjectFactory
so it is easiest to add behaviour to the factory rather than the DataObject
.
To add behaviour to DataObject
is easier if the object is an inner class or contains a reference to its factory.
You can also introduce additional handler classes that wrap the repository these can have the same relation to the Composite
as DataObject
has to the DataObjectFactory
.
Modifier and Type | Field and Description |
---|---|
protected DataObjectFactory<BDO> |
fac |
Modifier | Constructor and Description |
---|---|
protected |
Composite(DataObjectFactory<BDO> fac) |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
addDefaults(java.util.Map<java.lang.String,java.lang.Object> defaults)
Generate a set of default property values.
|
java.util.Map<java.lang.String,java.lang.String> |
addFieldHelp(java.util.Map<java.lang.String,java.lang.String> help)
return a default set of tooltip help text for form fields.
|
java.util.Set<java.lang.String> |
addOptional(java.util.Set<java.lang.String> optional)
generate the set of optional fields to be used to provide class specific defaults
in form creation/update.
|
java.util.Map<java.lang.String,Selector> |
addSelectors(java.util.Map<java.lang.String,Selector> selectors)
Get a Map of selectors to use for forms of this type.
|
java.util.Set<java.lang.String> |
addSuppress(java.util.Set<java.lang.String> suppress)
generate the class specific set of suppressed fields to be used in form creation/update
The individual forms can override these so you usually use this method to define fields that should
be suppressed in all forms.
|
java.util.Map<java.lang.String,java.lang.String> |
addTranslations(java.util.Map<java.lang.String,java.lang.String> translations)
return a default set of translation between field names and text labels.
|
void |
customiseForm(Form f)
Extension hook to allow additional Form customisation generic to all
types of Form (create and update) For example adding a FormValidator .
|
void |
customiseUpdateForm(Form f,
BDO target,
SessionService operator)
Extension hook to allow additional Form customisation specific to the update
of an existing object.
|
AppContext |
getContext() |
DataObjectFactory<BDO> |
getFactory()
return the
DataObjectFactory the Composite is registered with. |
protected Logger |
getLogger()
get a
Logger for this class |
protected Repository.Record |
getRecord(BDO data)
method to allow sub-classes to retrieve the
Repository.Record from
a target DataObject . |
protected Repository |
getRepository()
method to allow sub-classes to retrieve the
Repository . |
protected abstract java.lang.Class<? super X> |
getType()
Returns the type the composite should be registered under.
|
TableSpecification |
modifyDefaultTableSpecification(TableSpecification spec,
java.lang.String table)
Modify the
TableSpecification of the target factory. |
void |
postUpdate(BDO o,
Form f,
java.util.Map<java.lang.String,java.lang.Object> orig,
boolean changed)
perform side effects after a formupdate
|
protected void |
preRegister()
extension point called before the composite is registered.
|
protected void |
release()
perform extra clean-up when factory is released
|
java.lang.String |
toString()
used to list composites on table structure page.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addFieldConstraints, addFormFields
protected final DataObjectFactory<BDO extends DataObject> fac
protected Composite(DataObjectFactory<BDO> fac)
protected void preRegister()
protected abstract java.lang.Class<? super X> getType()
public TableSpecification modifyDefaultTableSpecification(TableSpecification spec, java.lang.String table)
TableStructureContributer
TableSpecification
of the target factory.modifyDefaultTableSpecification
in interface TableStructureContributer<BDO extends DataObject>
public java.util.Set<java.lang.String> addOptional(java.util.Set<java.lang.String> optional)
TableStructureContributer
addOptional
in interface TableStructureContributer<BDO extends DataObject>
Set
public java.util.Map<java.lang.String,java.lang.Object> addDefaults(java.util.Map<java.lang.String,java.lang.Object> defaults)
TableStructureContributer
addDefaults
in interface TableStructureContributer<BDO extends DataObject>
Map
of default valuespublic java.util.Map<java.lang.String,java.lang.String> addTranslations(java.util.Map<java.lang.String,java.lang.String> translations)
TableStructureContributer
addTranslations
in interface TableStructureContributer<BDO extends DataObject>
Map
public java.util.Map<java.lang.String,java.lang.String> addFieldHelp(java.util.Map<java.lang.String,java.lang.String> help)
TableStructureContributer
addFieldHelp
in interface TableStructureContributer<BDO extends DataObject>
Map
public java.util.Map<java.lang.String,Selector> addSelectors(java.util.Map<java.lang.String,Selector> selectors)
TableStructureContributer
addSelectors
in interface TableStructureContributer<BDO extends DataObject>
Map
of modified selectors/inputspublic java.util.Set<java.lang.String> addSuppress(java.util.Set<java.lang.String> suppress)
TableStructureContributer
addSuppress
in interface TableStructureContributer<BDO extends DataObject>
Set
of fields to suppress in forms.public void customiseForm(Form f)
TableStructureContributer
TableStructureContributer.customiseUpdateForm(Form, DataObject, SessionService)
customiseForm
in interface TableStructureContributer<BDO extends DataObject>
f
- Form to modifypublic void postUpdate(BDO o, Form f, java.util.Map<java.lang.String,java.lang.Object> orig, boolean changed) throws DataException
TableStructureContributer
postUpdate
in interface TableStructureContributer<BDO extends DataObject>
DataException
protected final Repository.Record getRecord(BDO data)
Repository.Record
from
a target DataObject
. This allows composite functionality to be added
to these as well as to the factory.data
- protected final Repository getRepository()
Repository
.public final DataObjectFactory<BDO> getFactory()
DataObjectFactory
the Composite
is registered with.public final AppContext getContext()
getContext
in interface Contexed
public void customiseUpdateForm(Form f, BDO target, SessionService operator)
TableStructureContributer
TableStructureContributer.customiseForm(Form)
customiseUpdateForm
in interface TableStructureContributer<BDO extends DataObject>
protected void release()
public java.lang.String toString()
toString
in class java.lang.Object