What is an AnchorBean?
- It is a JavaBean, subject to all the official conventions.
- It inherits form the class AnchorBean
- The fields which define bean properties are additionally annotated with
@BeanField
. - Serveral additional annotations are possible:
@Optional
@NonEmpty
etc.
Why use AnchorBeans?
- To separate the implementation of algorithms/components from their parameterization.
- To allow for easy serialization of configuration back and forth to XML.
- For a core-object model with certain repeated functionality (initialization, duplication).
- To remember parameters and algorithms for scientific record-keeping.
- To facilitate rapid ongoing development: low cost to add prototypes.
We implement principles of Dependency Injection and Inversion of Control (IoC) (similarly to the Spring Framework).
Anchor BeanXML
BeanXML is a basic XML standard for defining AnchorBeans, which just uses the Apache Commons Configuration framework for serializing JavaBeans to/from XML.
Additional Anchor-specific aspects are added to standard BeanXML. e.g. duplication occurs not only on the bean itself, but recursively on all its child properties, thus giving a deep copy.
Important prior step before usage in code
Code must always first call RegisterBeanFactories.registerAllPackageBeanFactories()
before loading any beans. This registers the additional-factories, and a replacement default factory (AnchorDefaultBeanFactory).
Initializable beans
Certain types of beans require initialization-parameters before they can be used. These beans should derive from InitializableBean, which provides helpful methods for recursively initializating a bean and all its nested children.
The type of parameter is application-dependent, and typically another abstract-base-class will subclass InitializableBean and specify both the parameter-type and some further interfaces.
Package namespaces in JARs
By convention, Anchor beans are always stored with bean
in the root package namespace of the JAR e.g.
- org.anchoranalysis.image.bean.threshold.ThresholderGlobal
- org.anchoranalysis.bean.StringSet
- org.anchoranalysis.image.bean.unitvalue.distance.UnitValueDistanceVoxels
The namespace to the left of bean is the root package namespace.
Locating source-code for a particular bean
- Read the bean-class from the
config-class
attribute - The relevant source-code repository can be inferred from the root package namespace (see Source Repositories).
- Follow the maven structure of
src/main/java/org/anchoranalysis/
etc. backwards along the package namespace to eventually locate the class.