[seam-dev] Extending weld-extensions generic beans

Stuart Douglas stuart at baileyroberts.com.au
Mon Apr 12 09:51:43 EDT 2010


After talking with Tihomir over the last few days about the seam-drools module I think that there is base functionality that is missing that belongs in weld-extensions as it is similar to the existing generic bean code.

I will use an example from the drools module to outline the problem:

The drools module has a DroolsConfiguration object that contains configuration, this can be installed via XML and there can be multiple DroolsConfigrations per app. for every DroolsConfiguration several object need to be produced e.g. KnowledgeBase, StatefullKnowledgeSession and a KnowledgeRuntimeLogger.

currently we would need to do something like this:

< d:DroolsConfiguration>
  <app:SomeQualifier>
  ...configuration
</d:DroolsConfiguration>


<d:KnowlegdeBaseProducer>
  <d:producerMethod>
    <app:SomeQualifier>
    <s:parameters>
      <d:DroolsConfiguration>
       <s:Inject/>
       <app:SomeQualifier/>
     </d:DroolsConfiguration>
    </s:parameters>
  </d:producerMethod>
</d:KnowlegdeBaseProducer >

...same for StatefullKnowledgeSession, StatelessKnowledgeSession, KnowledgeRuntimeLogger etc.

and wire up a producer like that for every object being created from the DroolsConfiguration. This is not good. The user should be able to just wire up the configuration and the rest of the beans should be created automatically. I think we should be able to do something like this:

@Generic(DroolsConfiguration.class)
class KnowledgeBaseProducer
{
  @Produces
  @GenericQualifiers
  public KnowledgeBase producerMethod(@Inject @GenericQualifiers DroolsConfiguration config )
  {
   //do stuff
  }

}

@Generic tell the extensions to register a new KnowledgeBaseProducer bean for every DroolsConfiguration found. 
@GenericQualifiers is replaced with the qualifiers on the DroolsConfiguration object when the bean is added.

This means that all an end user has to do is wire up a single DroolsConfiguration object and everything just works.

Does this sound like a good idea? Is there anything I have overlooked?

Stuart





More information about the seam-dev mailing list