Edit me

What is an AnchorBean?

  1. It is a JavaBean, subject to all the official conventions.
  2. It inherits form the class AnchorBean
  3. The fields which define bean properties are additionally annotated with @BeanField.
  4. Serveral additional annotations are possible: @Optional @NonEmpty etc.

Why use AnchorBeans?

  1. To separate the implementation of algorithms/components from their parameterization.
  2. To allow for easy serialization of configuration back and forth to XML.
  3. For a core-object model with certain repeated functionality (initialization, duplication).
  4. To remember parameters and algorithms for scientific record-keeping.
  5. 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

  1. Read the bean-class from the config-class attribute
  2. The relevant source-code repository can be inferred from the root package namespace (see Source Repositories).
  3. Follow the maven structure of src/main/java/org/anchoranalysis/ etc. backwards along the package namespace to eventually locate the class.