|
From: Heino M. <mag...@lm...> - 2005-06-16 10:31:25
|
http://opensource.atlassian.com/projects/spring/browse/SPR-1047 Good/bad idea? Has someone else done a better implementation thats already integrated that I have missed? Comments please. -- /Magnus Heino |
|
From: Seth L. <set...@gm...> - 2005-06-16 18:04:34
|
On 6/16/05, Heino Magnus <mag...@lm...> wrote: >=20 > http://opensource.atlassian.com/projects/spring/browse/SPR-1047 >=20 > Good/bad idea? Has someone else done a better implementation thats alread= y > integrated that I have missed? I think it's a great idea. Of course, I'm biased, as I also wrote an implementation of this concept. http://opensource.atlassian.com/projects/spring/browse/SPR-774 Two major differences between 774 and 1047: My impl uses the attributes facade, so that pre 1.5 installs can use this functionality. It also can handle primitives. That is, it can check if the value of a primitive was not set in the bean definition. My favorite part about this idea is it gets rid of all that code inside afterPropertiesSet(), where many beans check if their dependencies are set. Each bean shouldn't have to do that, IMHO. Seth |
|
From: Andy D. <an...@ma...> - 2005-06-16 18:29:58
|
This is awesome stuff! How flexible is it? Take a look at this
"afterPropertiesSet()":
-----
public final void afterPropertiesSet() throws Exception
{
if(getViewPrototypeBeanName() == null) {
throw new IllegalArgumentException("viewPrototypeBeanName property must
be set.");
}
if(getBeanFactory() == null) {
throw new IllegalArgumentException("beanFactory property must be set.");
}
if(!getBeanFactory().containsBean(getViewPrototypeBeanName())) {
throw new IllegalArgumentException("There is no bean in the bean factory
with the given name '" + getViewPrototypeBeanName() + "'");
}
if(getBeanFactory().isSingleton(getViewPrototypeBeanName())) {
throw new IllegalArgumentException("View bean '" +
getViewPrototypeBeanName() + "' must be a prototype (singleton=\"false\").");
}
if(!View.class.isAssignableFrom(getBeanFactory().getType(getViewPrototypeBeanName())))
{
throw new IllegalArgumentException("Prototype View bean '" +
getViewPrototypeBeanName() + "' does not implement the View interface.");
}
}
-----
I would love to do away with this method entirely by just annotating the
class.
- Andy
On Thursday 16 June 2005 11:04 am, Seth Ladd wrote:
> On 6/16/05, Heino Magnus <mag...@lm...> wrote:
> > http://opensource.atlassian.com/projects/spring/browse/SPR-1047
> >
> > Good/bad idea? Has someone else done a better implementation thats
> > already integrated that I have missed?
>
> I think it's a great idea. Of course, I'm biased, as I also wrote an
> implementation of this concept.
>
> http://opensource.atlassian.com/projects/spring/browse/SPR-774
>
> Two major differences between 774 and 1047:
>
> My impl uses the attributes facade, so that pre 1.5 installs can use
> this functionality.
>
> It also can handle primitives. That is, it can check if the value of
> a primitive was not set in the bean definition.
>
> My favorite part about this idea is it gets rid of all that code
> inside afterPropertiesSet(), where many beans check if their
> dependencies are set. Each bean shouldn't have to do that, IMHO.
>
> Seth
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=Click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: Seth L. <set...@gm...> - 2005-06-16 18:55:47
|
On 6/16/05, Andy Depue <an...@ma...> wrote:
> This is awesome stuff! How flexible is it? Take a look at this
> "afterPropertiesSet()":
Well, it's only written to check that a property has been set. And
'set' is defined as:
- if property is an object, make sure it's not null
- if property is a primitive, make sure it's value isn't either the
default unset value, or the specified unset value
Your checks to see if something is a prototype aren't handled by this
code. But, it could easily be handled with something like
@@RequiredDependency(singleton=3D"false")
Which would have the semantics you want here. Of course, this would
be an optional check. That is, omitting it would not check that
singleton =3D true.
Seth
>=20
> -----
> public final void afterPropertiesSet() throws Exception
> {
> if(getViewPrototypeBeanName() =3D=3D null) {
> throw new IllegalArgumentException("viewPrototypeBeanName property =
must
> be set.");
> }
> if(getBeanFactory() =3D=3D null) {
> throw new IllegalArgumentException("beanFactory property must be se=
t.");
> }
> if(!getBeanFactory().containsBean(getViewPrototypeBeanName())) {
> throw new IllegalArgumentException("There is no bean in the bean fa=
ctory
> with the given name '" + getViewPrototypeBeanName() + "'");
> }
> if(getBeanFactory().isSingleton(getViewPrototypeBeanName())) {
> throw new IllegalArgumentException("View bean '" +
> getViewPrototypeBeanName() + "' must be a prototype (singleton=3D\"false\=
").");
> }
> if(!View.class.isAssignableFrom(getBeanFactory().getType(getViewProto=
typeBeanName())))
> {
> throw new IllegalArgumentException("Prototype View bean '" +
> getViewPrototypeBeanName() + "' does not implement the View interface.");
> }
> }
> -----
>=20
> I would love to do away with this method entirely by just annotating the
> class.
>=20
> - Andy
>
|