geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: [bluprint + xbean-reflect] Use of factories
Date Thu, 23 Apr 2009 17:26:00 GMT
[cc'ing the xbean-dev@geronimo.a.o list]

On Apr 23, 2009, at 9:56 AM, Guillaume Nodet wrote:

>>>
>>>   In blueprint, there is a notion of factory
>>> component, which should be built by its own recipe
>>
>> With you so far.
>>
>>> , then used as a reference to create the object using arguments if  
>>> any
>>
>> Not sure what "used as a reference" means.  Also not sure what "using
>> arguments" means.  Are the arguments somehow different than the  
>> properties
>> in a recipe?  Where do they come from?
>
> Just meaning that the factory is itself a bean usually created with
> its own recipe.
> So the properties on the recipe that uses the factory will be used to:
>  * call the factory method
>  * populate the created beans with properties
>
>>> , then populating the created beans using properties.
>>
>> So the factory is allowed to create several beans and I guess is  
>> kept around
>> and the resulting beans should be injected with it's own set of  
>> properties?
>
> Right

So is this basically what you're talking about? (making up some api  
here)

   ObjectRecipe colorFactoryRecipe = new  
ObjectRecipe(ColorFactory.class)
   colorFactoryRecipe.setProperty("foo", "bar"); // set the properties  
for the factory

   ColorFactory colorFactory = (ColorFactory) factoryRecipe.create();

   ObjectRecipe redRecipe = new ObjectRecipe();
   redRecipe.setInstanceFactory(colorFactory);
   redRecipe.setProperty("r", "255");
   redRecipe.setProperty("g", "0");
   redRecipe.setProperty("b", "0");

   Color red = (Color) redRecipe.create();

   ObjectRecipe blueRecipe = new ObjectRecipe();
   blueRecipe.setInstanceFactory(colorFactory);
   blueRecipe.setProperty("r", "0");
   blueRecipe.setProperty("g", "0");
   blueRecipe.setProperty("b", "255");

   Color blue = (Color) redRecipe.create();

That the basic idea?

-David



Mime
View raw message