Return-Path: Delivered-To: apmail-geronimo-dev-archive@www.apache.org Received: (qmail 7731 invoked from network); 24 Apr 2009 06:15:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Apr 2009 06:15:26 -0000 Received: (qmail 99189 invoked by uid 500); 24 Apr 2009 06:15:26 -0000 Delivered-To: apmail-geronimo-dev-archive@geronimo.apache.org Received: (qmail 99087 invoked by uid 500); 24 Apr 2009 06:15:26 -0000 Mailing-List: contact dev-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list dev@geronimo.apache.org Received: (qmail 99077 invoked by uid 99); 24 Apr 2009 06:15:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Apr 2009 06:15:25 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of gnodet@gmail.com designates 209.85.218.163 as permitted sender) Received: from [209.85.218.163] (HELO mail-bw0-f163.google.com) (209.85.218.163) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Apr 2009 06:15:17 +0000 Received: by bwz7 with SMTP id 7so949994bwz.19 for ; Thu, 23 Apr 2009 23:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=D2siIZ9gMv5rzeBfod75241pjY7B/+XT/jyOML+vcZE=; b=CHIpFBw/phC9o9LAUpopIFb+Wasg6nXz/ClU1sI+eTVWy1WBhC1MJnTRRR2txVVNg1 t7LJHvgRKkJvhxxG2sgvtJBlHW4UnyuvdNUhbT+2YgERMhkX2ypil8bnFcjcE9sjnL6i Z+Nywbx0tLd3XXk5fafMpsOya5AzG0cfV96Lg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=GcakU58FOTaeUz1DdVRNMOyNbxVUfb0UtKUgIsq8/PdpXjIoOAYCgcRukj7uuqyzBI /T2sDEWfuKAcTqHNE3B+EfNUMfTQ8KdPeGnjRSs5pPsb1M9Sc+egIR8/wj0lvT024Kel SZEy8rLAtrkd0tO59GlwrDU3v9xe4s30lQoA4= MIME-Version: 1.0 Received: by 10.223.104.19 with SMTP id m19mr553001fao.58.1240553695646; Thu, 23 Apr 2009 23:14:55 -0700 (PDT) In-Reply-To: References: <48445DB8-C720-4BBC-9FF6-4A48C1C133A1@visi.com> Date: Fri, 24 Apr 2009 08:14:55 +0200 Message-ID: Subject: Re: [bluprint + xbean-reflect] Use of factories From: Guillaume Nodet To: xbean-dev@geronimo.apache.org Cc: dev@geronimo.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Thanks, looks like we can already do a lot. I now remember seeing this PassThroughInterface in gbean code. Anyway, I think we're still missing on construct, even in you not supported yet use cases: in the testReusableInstanceFactory() example, we need to allow the color recipe to be created by using the factoryRecipe instead of the build factory, so that the graph construction will take that into account. So it should not be : ObjectRecipe factoryRecipe =3D new ObjectRecipe(ColorInstanceFactory.class); factoryRecipe.setProperty("foo", "bar"); ColorInstanceFactory colorInstanceFactory =3D (ColorInstanceFactory) factoryRecipe.create(); ObjectRecipe recipe =3D new ObjectRecipe(colorInstanceFactory); recipe.setFactoryMethod("createColor"); but rather ObjectRecipe factoryRecipe =3D new ObjectRecipe(ColorInstanceFactory.class); factoryRecipe.setProperty("foo", "bar"); ObjectRecipe recipe =3D new ObjectRecipe(factoryRecipe); recipe.setFactoryMethod("createColor"); On Thu, Apr 23, 2009 at 23:14, David Blevins wrote= : > Give this a look and see what you think. =A0What we have isn't too far of= f. > > http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/test/= java/org/apache/xbean/recipe/ScratchPadTest.java?revision=3D768055&view=3Dm= arkup > > 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 { >> =A0public void setFoo(String foo) { } >> =A0public Color createColor(String type) { } >> } >> >> class RGBColor extends Color { >> =A0public void setR(int r) {} >> =A0public void setG(int g) {} >> =A0public void setB(int g) {} >> } >> >> class YUVColor extends Color { >> =A0public void setY(int y) {} >> =A0public void setU(int u) {} >> =A0public void setV(int v) {} >> } >> >> then, we'd have: >> >> ObjectRecipe colorFactoryRecipe =3D new ObjectRecipe(ColorFactory.class) >> colorFactoryRecipe.setProperty("foo", "bar"); factory >> >> ObjectRecipe rgbRecipe =3D 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 { >> >> =A0public static Color createColor(String type) { } >> } >> >> then we'd have: >> >> ObjectRecipe redRecipe =3D 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 >> wrote: >>> >>> [cc'ing the xbean-dev@geronimo.a.o list] >>> >>> On Apr 23, 2009, at 9:56 AM, Guillaume Nodet wrote: >>> >>>>>> >>>>>> =A0In 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 a= ny >>>>> >>>>> Not sure what "used as a reference" means. =A0Also not sure what "usi= ng >>>>> arguments" means. =A0Are the arguments somehow different than the >>>>> properties >>>>> in a recipe? =A0Where 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: >>>> =A0* call the factory method >>>> =A0* 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 her= e) >>> >>> =A0ObjectRecipe colorFactoryRecipe =3D new ObjectRecipe(ColorFactory.cl= ass) >>> =A0colorFactoryRecipe.setProperty("foo", "bar"); // set the properties = for >>> the >>> factory >>> >>> =A0ColorFactory colorFactory =3D (ColorFactory) factoryRecipe.create(); >>> >>> =A0ObjectRecipe redRecipe =3D new ObjectRecipe(); >>> =A0redRecipe.setInstanceFactory(colorFactory); >>> =A0redRecipe.setProperty("r", "255"); >>> =A0redRecipe.setProperty("g", "0"); >>> =A0redRecipe.setProperty("b", "0"); >>> >>> =A0Color red =3D (Color) redRecipe.create(); >>> >>> =A0ObjectRecipe blueRecipe =3D new ObjectRecipe(); >>> =A0blueRecipe.setInstanceFactory(colorFactory); >>> =A0blueRecipe.setProperty("r", "0"); >>> =A0blueRecipe.setProperty("g", "0"); >>> =A0blueRecipe.setProperty("b", "255"); >>> >>> =A0Color blue =3D (Color) redRecipe.create(); >>> >>> That the basic idea? >>> >>> -David >>> >>> >>> >> >> >> >> -- >> Cheers, >> Guillaume Nodet >> ------------------------ >> Blog: http://gnodet.blogspot.com/ >> ------------------------ >> Open Source SOA >> http://fusesource.com >> > > --=20 Cheers, Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ ------------------------ Open Source SOA http://fusesource.com