|
From: Oliver H. <Ol...@ou...> - 2005-06-16 23:15:15
|
What are the constraints you're interested in and what are you doing
with them?
Ollie
PS. I assume you've looked at using Keith's Rules package. I have an
implementation of Rules driven using annotation in the Spring Rich
sandbox (AttributesRulesSource) (given my previous post this might
surprise you :-).=20
=20
> -----Original Message-----
> From: spr...@li...=20
> [mailto:spr...@li...]
> On Behalf Of Andy Depue
> Sent: Friday, 17 June 2005 9:05 AM
> To: spr...@li...
> Subject: Re: [Springframework-developer] Annotation to=20
> validate required bean attributes
>=20
> OK, so I've had a hidden agenda all along. :) My main reason=20
> for wanting to annotate properties with their constraints is=20
> to provide "smart" handling of these in other areas of the=20
> application. There are various places in my application=20
> where having knowledge of the constraints on a property can=20
> come in handy. As it is now, this knowledge is typically=20
> coded in one lump in one method, with no way to "introspect"=20
> those constraints on a per-property basis.
>=20
> - Andy
>=20
> On Thursday 16 June 2005 03:54 pm, Oliver Hutchison wrote:
> > Are you really saving that much using annotations to=20
> validate required=20
> > bean attributes? Since the introduction of the Assert class coding=20
> > these afterPropertiesSet constraint checks has been made really=20
> > simple. What's the difference between typing
> >
> > @@RequiredDependency()
> > And
> > Assert.notNull(property);
> > ?
> >
> > Not much. Slightly less typing is required, but by using the=20
> > annotations you introduce a set of dependencies that your=20
> POJO would=20
> > never have had before. If you're only going to be creating=20
> the object=20
> > using a bean factory this is acceptable, however if you want=20
> > instantiate these annotated objects outside of a bean=20
> factory (say in=20
> > a test) your also going to have to create all=20
> infrastructure needed to=20
> > do the required validation.
> >
> > There's also the issue of how you express more complex constraints=20
> > using annotations. From Andy's example there's this=20
> (rewritten to use Assert):
> >
> >
> >=20
> Assert.true(!getBeanFactory().containsBean(getViewPrototypeBeanName())
> > , "View bean '" + getViewPrototypeBeanName() + "' must be a=20
> prototype=20
> > (singleton=3D\"false\").");
> >
> > To express this in an annotation you'd probably have to=20
> introduce some=20
> > kind of expression language (Groovy, OGNL?) for the constraint=20
> > checking and some kind of template processor for the=20
> exception message=20
> > generation
> > - suddenly something that was reasonably simple to do in Plain Old=20
> > Java is requiring a considerable amount of support code.=20
> I'd imagine=20
> > your annotation would look something like this:
> >
> > @@RequiredDependency("!
> > beanFactory.containsBean(viewPrototypeBeanName)", "View bean=20
> > '${viewPrototypeBeanName}' must be a prototype=20
> > (singleton=3D\"false\").")
> >
> > I hope I'm not giving you ideas here ;-)
> >
> > Just my 2c.
> >
> > Ollie
>=20
>=20
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration=20
> Strategies from IBM. Find simple to follow Roadmaps,=20
> straightforward articles, informative Webcasts and more! Get=20
> everything you need to get up to speed, fast.=20
> http://ads.osdn.com/?ad_id=3D7477&alloc_id=3D16492&op=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>=20
|