SPI

Customize conversation implementations

If it's required to change or intercept the default implementation of EditableConversation, it's possible to provide a custom ConversationFactory.

Custom ConversationFactory
@Decorator
public class CustomConversationFactory implements ConversationFactory
{
    private static final long serialVersionUID = -3654734112338281151L;

    @Inject
    @Delegate
    @Any
    private ConversationFactory conversationFactory;

    public EditableConversation createConversation(ConversationKey conversationKey, ConversationConfig configuration)
    {
        EditableConversation conversation = this.conversationFactory.createConversation(conversationKey, configuration);

        //example for just changing the behaviour of the view-access scope
        if(!ViewAccessScoped.class.isAssignableFrom(conversationKey.getScope()))
        {
            return conversation;
        }

        return new InterceptedConversationImpl(conversation); //wrap the default implementation or create an instance before delegating to the wrapped ConversationFactory
    }
}
Intercepted EditableConversation
class InterceptedConversationImpl implements EditableConversation
{
    private static final long serialVersionUID = 283349344155364553L;

    private final EditableConversation wrapped;

    public InterceptedConversationImpl(EditableConversation wrapped)
    {
        this.wrapped = wrapped;
    }

    //delegate methods to this.wrapped and intercept the need methods or change the behaviour completely
}
Configuration in the std. CDI beans.xml
<beans>
    <decorators>
        <class>mypackage.CustomConversationFactory</class>
    </decorators>
</beans>
  • No labels