Class PropertyAccessStrategy

java.lang.Object
org.axonframework.common.property.PropertyAccessStrategy
All Implemented Interfaces:
Comparable<PropertyAccessStrategy>
Direct Known Subclasses:
AbstractMethodPropertyAccessStrategy, DirectPropertyAccessStrategy

public abstract class PropertyAccessStrategy extends Object implements Comparable<PropertyAccessStrategy>
Abstract Strategy that provides access to all PropertyAccessStrategy implementations.

Application developers may provide custom PropertyAccessStrategy implementations using the ServiceLoader mechanism. To do so, place a file called org.axonframework.common.property.PropertyAccessStrategy in the META-INF/services folder. In this file, place the fully qualified class names of all available implementations.

The factory implementations must be public, non-abstract, have a default public constructor and extend the PropertyAccessStrategy class.

Note that this class is not considered public API and may undergo incompatible changes between versions.

Since:
2.0
Author:
Maxim Fedorov, Allard Buijze
See Also:
  • Constructor Details

    • PropertyAccessStrategy

      public PropertyAccessStrategy()
  • Method Details

    • register

      public static void register(PropertyAccessStrategy strategy)
      Registers a PropertyAccessStrategy implementation at runtime. Annotated handlers that have already been inspected will not be able to use the newly added strategy.
      Parameters:
      strategy - implementation to register
    • unregister

      public static void unregister(PropertyAccessStrategy strategy)
      Removes all strategies registered using the register(PropertyAccessStrategy) method.
      Parameters:
      strategy - The strategy instance to deregister.
    • getProperty

      public static <T> Property<T> getProperty(Class<? extends T> targetClass, String propertyName)
      Iterates over all known PropertyAccessStrategy implementations to create a Property instance for the given parameters. Strategies are invoked in the order they are found on the classpath. The first to provide a suitable Property instance will be used.
      Type Parameters:
      T - Thy type defining the property
      Parameters:
      targetClass - class that contains property
      propertyName - name of the property to create propertyReader for
      Returns:
      suitable Property, or null if none is found
    • compareTo

      public final int compareTo(@Nonnull PropertyAccessStrategy o)
      Specified by:
      compareTo in interface Comparable<PropertyAccessStrategy>
    • getPriority

      protected abstract int getPriority()
      The priority of this strategy. In general, implementations that have a higher certainty to provide a good Property instance for any given property name should have a higher priority. When two instances have the same priority, their relative order is undefined.

      The JavaBean Property strategy has a value of 0. To ensure evaluation before that strategy, use any value higher than that number, otherwise lower.

      Returns:
      a value reflecting relative priority, Integer.MAX_VALUE being evaluated first
    • propertyFor

      protected abstract <T> Property<T> propertyFor(Class<? extends T> targetClass, String property)
      Returns a Property instance for the given property, defined in given targetClass, or null if no such property is found on the class.
      Type Parameters:
      T - The type of class on which to find the property
      Parameters:
      targetClass - The class on which to find the property
      property - The name of the property to find
      Returns:
      the Property instance providing access to the property value, or null if property could not be found.