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 21:14:01 GMT
Give this a look and see what you think.  What we have isn't too far  
off.

http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/test/java/org/apache/xbean/recipe/ScratchPadTest.java?revision=768055&view=markup

In regards to argument matching, we'll need to support pure type based  
approaches to constructor, factory, and method args as well for JCDI  
(JSR-299) support as well.

-David

On Apr 23, 2009, at 11:22 AM, Guillaume Nodet wrote:

> Right, but in addition to instanceFactory, we also need to provide the
> methodFactory.
> So if we have
>
> class ColorFactory {
>   public void setFoo(String foo) { }
>   public Color createColor(String type) { }
> }
>
> class RGBColor extends Color {
>  public void setR(int r) {}
>  public void setG(int g) {}
>  public void setB(int g) {}
> }
>
> class YUVColor extends Color {
>  public void setY(int y) {}
>  public void setU(int u) {}
>  public void setV(int v) {}
> }
>
> then, we'd have:
>
> ObjectRecipe colorFactoryRecipe = new ObjectRecipe(ColorFactory.class)
> colorFactoryRecipe.setProperty("foo", "bar"); factory
>
> ObjectRecipe rgbRecipe = new ObjectRecipe();
> rgbRecipe.setInstanceFactory(colorFactoryRecipe);
> rgbRecipe.setMethodFactory("createColor");
> rgbRecipe.setProperty("type", "rgb");
> rgbRecipe.setProperty("r", "255");
> rgbRecipe.setProperty("g", "255");
> rgbRecipe.setProperty("b", "255");
>
> If we have:
>
> class ColorFactory {
>
>   public static Color createColor(String type) { }
> }
>
> then we'd have:
>
> ObjectRecipe redRecipe = new ObjectRecipe();
> redRecipe.setClassName(ColorFactory.class);
> redRecipe.setInstanceFactory(null);
> redRecipe.setMethodFactory("createColor");
> redRecipe.setProperty("r", "255");
>
>
> But Jarek is right, and we might have other problems with the way the
> arguments matching is done.
>
> On Thu, Apr 23, 2009 at 19:26, David Blevins  
> <david.blevins@visi.com> wrote:
>> [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
>>
>>
>>
>
>
>
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> ------------------------
> Open Source SOA
> http://fusesource.com
>


Mime
View raw message