org.axonframework.eventsourcing
Class GenericAggregateFactory<T extends EventSourcedAggregateRoot>

java.lang.Object
  extended by org.axonframework.eventsourcing.AbstractAggregateFactory<T>
      extended by org.axonframework.eventsourcing.GenericAggregateFactory<T>
Type Parameters:
T - The type of aggregate this factory creates
All Implemented Interfaces:
AggregateFactory<T>

public class GenericAggregateFactory<T extends EventSourcedAggregateRoot>
extends AbstractAggregateFactory<T>

Aggregate factory that uses a convention to create instances of aggregates. The type must declare a no-arg constructor accepting.

If the constructor is not accessible (not public), and the JVM's security setting allow it, the GenericAggregateFactory will try to make it accessible. If that doesn't succeed, an exception is thrown.

Since:
0.7
Author:
Allard Buijze

Constructor Summary
GenericAggregateFactory(Class<T> aggregateType)
          Initialize the AggregateFactory for creating instances of the given aggregateType.
GenericAggregateFactory(Class<T> aggregateType, ParameterResolverFactory parameterResolverFactory)
          Initialize the AggregateFactory for creating instances of the given aggregateType and using the given parameterResolverFactory to resolve parameters of annotated event handler methods.
 
Method Summary
protected  T doCreateAggregate(Object aggregateIdentifier, DomainEventMessage firstEvent)
          Create an uninitialized Aggregate instance with the given aggregateIdentifier.
 Class<T> getAggregateType()
          Returns the type of aggregate this factory creates.
 String getTypeIdentifier()
          Returns the type identifier for this aggregate factory.
 
Methods inherited from class org.axonframework.eventsourcing.AbstractAggregateFactory
createAggregate, postProcessInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericAggregateFactory

public GenericAggregateFactory(Class<T> aggregateType)
Initialize the AggregateFactory for creating instances of the given aggregateType.

Parameters:
aggregateType - The type of aggregate this factory creates instances of.
Throws:
IncompatibleAggregateException - if the aggregate constructor throws an exception, or if the JVM security settings prevent the GenericAggregateFactory from calling the constructor.

GenericAggregateFactory

public GenericAggregateFactory(Class<T> aggregateType,
                               ParameterResolverFactory parameterResolverFactory)
Initialize the AggregateFactory for creating instances of the given aggregateType and using the given parameterResolverFactory to resolve parameters of annotated event handler methods.

Note that the parameterResolverFactory is only used if the aggregate is an instance of org.axonframework.eventsourcing.annotation.AbstractAnnotatedAggregateRoot. In other cases, this parameter is ignored

Parameters:
aggregateType - The type of aggregate this factory creates instances of.
parameterResolverFactory - THe factory that resolves parameters of annotated event handlers
Throws:
IncompatibleAggregateException - if the aggregate constructor throws an exception, or if the JVM security settings prevent the GenericAggregateFactory from calling the constructor.
Method Detail

doCreateAggregate

protected T doCreateAggregate(Object aggregateIdentifier,
                              DomainEventMessage firstEvent)
Create an uninitialized Aggregate instance with the given aggregateIdentifier. The given firstEvent can be used to define the requirements of the aggregate to create.

The given firstEvent is never a snapshot event.

Specified by:
doCreateAggregate in class AbstractAggregateFactory<T extends EventSourcedAggregateRoot>
Parameters:
aggregateIdentifier - The identifier of the aggregate to create
firstEvent - The first event in the Event Stream of the Aggregate
Returns:
The aggregate instance to initialize with the Event Stream
Throws:
IncompatibleAggregateException - if the aggregate constructor throws an exception, or if the JVM security settings prevent the GenericAggregateFactory from calling the constructor.

getTypeIdentifier

public String getTypeIdentifier()
Description copied from interface: AggregateFactory
Returns the type identifier for this aggregate factory. The type identifier is used by the EventStore to organize data related to the same type of aggregate.

Tip: in most cases, the simple class name would be a good start.

Returns:
the type identifier of the aggregates this repository stores

getAggregateType

public Class<T> getAggregateType()
Description copied from interface: AggregateFactory
Returns the type of aggregate this factory creates. All instances created by this factory must be an instanceOf this type.

Returns:
The type of aggregate created by this factory


Copyright © 2010-2016. All Rights Reserved.