Errata, I forgot the return this; on the myprop() builder method
2014-06-24 12:30 GMT+02:00 Charlie Mordant <[email protected]>: > Hi, > > Here's a bp compliant builder (and one many of builder devs do it...). > > public class MyBean { > private Object myprop; > public void setMyProp(Object prop) { > myprop = prop; > } > public void getMyProp {return myprop;} > public MyBeanBuilder { > private MyBean mybean; > public MyBeanBuilder() {mybean = new Mybean();} > public MyBeanBuilder myProp(Object prop) { > mybean.setMyProp(prop); > } > public MyBean build() { > return mybean; > } > } > > You can also use lombok (provides getters, setter and builder annotation) > if you want to get rid of boilerplate code. > > Regards, > > > > > 2014-06-24 12:20 GMT+02:00 CLEMENT Jean-Philippe < > [email protected]>: > > A builder usually returns itself to cumulates changes via Java. It could >> be good to use the same method either from Java or Blueprint. From a >> language perspective there is nothing which prevents this as a method is >> identified via its name and arguments; it is not tied to its return type. >> >> Is the return type really prohibited from the Blueprint spec or is it >> left unspecified? >> >> JP >> >> >> -----Message d'origine----- >> De : Jean-Baptiste Onofré [mailto:[email protected]] >> Envoyé : lundi 23 juin 2014 17:49 >> À : [email protected] >> Objet : Re: Troubles when creating a builder with blueprint. >> >> Hi Christophe, >> >> in JavaBeans (following by Blueprint), a setter is void, and a getter >> doesn't have argument. >> So it should be: >> >> public void setMaxValue(float maxValue) { >> this.maxValue=maxValue; >> } >> public float getMaxValue() { >> return this.maxValue; >> } >> >> Regards >> JB >> >> On 06/23/2014 05:34 PM, Lasserre Christophe wrote: >> > Hello, >> > >> > I wrote a builder containing the following setter which does not >> > return void (see following sample). >> > >> > /** >> > >> > * @param maxValue >> > >> > * Maximal value for compression law attributes >> > >> > * @return the builder. >> > >> > */ >> > >> > public CompressionLawBuilder setMaxValue(final float maxValue) { >> > >> > this.maxValue = maxValue; >> > >> > return this; >> > >> > } >> > >> > When I try to create the builder via blueprint, the runtime returns me >> > the following error message; "Caused by: >> > org.osgi.service.blueprint.container.ComponentDefinitionException: No >> > setter for maxValue property" >> > >> > If I change the setter and make it return void, everything works >> > perfectly, so is it normal that the return type of the setter has an >> > impact on the application behavior ? >> > >> > Chris. >> > >> > [@@ OPEN @@] >> > >> >> -- >> Jean-Baptiste Onofré >> [email protected] >> http://blog.nanthrax.net >> Talend - http://www.talend.com >> > > > > -- > Charlie Mordant > > Full OSGI/EE stack made with Karaf: > https://github.com/OsgiliathEnterprise/net.osgiliath.parent > -- Charlie Mordant Full OSGI/EE stack made with Karaf: https://github.com/OsgiliathEnterprise/net.osgiliath.parent
