Class AnchorBean<F>
- Type Parameters:
F- family-type, the type returned theduplicateBean()method is called
- Direct Known Subclasses:
Define,DefineAdderBean,DoubleList,DoubleSet,InitializableBean,IntegerList,IntegerSet,PermuteProperty,SequenceInteger,StringList,StringSet
public abstract class AnchorBean<F> extends Object
The family-type exists as a templated parameter <F> to return a sensibly-typed object
when duplicateBean() is called. Typically, this is either the type of the class itself, or
an abstract base class representing a family of similar classes. A bean must always be assignable
from (i.e. be equal to or inherit from) the family-type it is associated with.
- Author:
- Owen Feehan
-
Constructor Summary
Constructors Constructor Description AnchorBean() -
Method Summary
Modifier and Type Method Description voidcheckMisconfigured(BeanInstanceMap defaultInstances)Checks that a bean's properties conform to expectations.StringdescribeBean()A (maybe longer) description identifying the bean and perhaps its key parameters.protected StringdescribeChildren()Generates a string describing the children of the current bean.FduplicateBean()Creates a new bean that deep-copies every property value.List<Field>fields()A list of all bean-fields that are associated with this bean directly (fields of children are not checked).<T extends AnchorBean<?>>
List<T>findFieldsOfClass(Class<?> match)Finds all bean-fields that are instances of a certain class.StringgetBeanName()A short-name identifying a bean (by default the name of the class associated with the bean).Optional<Path>getLocalPath()A local path on the file-system, optionally associated with this bean.voidlocalise(Path path)Called once after the bean is created, localising the bean to a path on the filesystem.StringtoString()By default, we usedescribeBean()as the string representation of the bean.
-
Constructor Details
-
AnchorBean
public AnchorBean()
-
-
Method Details
-
getBeanName
A short-name identifying a bean (by default the name of the class associated with the bean).- Returns:
- the short-name of the bean
-
describeBean
A (maybe longer) description identifying the bean and perhaps its key parameters.By default, it returns the same as
getBeanName()but beans can optionally override it- Returns:
- either the short-name of the bean, or a longer description
-
getLocalPath
A local path on the file-system, optionally associated with this bean.The association is usually established when a bean is loaded (deserialized) from a file.
- Returns:
- the local-path, if defined.
-
toString
By default, we usedescribeBean()as the string representation of the bean. -
localise
Called once after the bean is created, localising the bean to a path on the filesystem.It is sometimes useful to override this method so as to include other files.
- Parameters:
path- a path on the filesystem which is associated with the bean (can be null, indicating no localization)- Throws:
BeanMisconfiguredException- if a relative-path is passed
-
checkMisconfigured
Checks that a bean's properties conform to expectations.- Parameters:
defaultInstances- all available default instances if theDefaultInstanceannotation is used- Throws:
BeanMisconfiguredException- if the bean has not been configured properly as XML
-
duplicateBean
Creates a new bean that deep-copies every property value.Any state that is not a
BeanFieldis ignored.- Returns:
- the newly created bean
-
describeChildren
Generates a string describing the children of the current bean.- Returns:
- a string describing the children.
-
findFieldsOfClass
public <T extends AnchorBean<?>> List<T> findFieldsOfClass(Class<?> match) throws BeanMisconfiguredExceptionFinds all bean-fields that are instances of a certain class.All immediate children are checked, and any items in immediate lists.
- Type Parameters:
T- the type of bean returned in the list- Parameters:
match- the class that a field must be assignable from (equal to or inherit from)- Returns:
- a list of all bean-fields that match the criteria
- Throws:
BeanMisconfiguredException- if we discover the bean has been misconfigured
-
fields
A list of all bean-fields that are associated with this bean directly (fields of children are not checked).This operation is cached as the necessary reflection calls are costly.
- Returns:
- a list of bean-fields associated with the current bean
-