Berin Loritsch a écrit :
>
> Sylvain Wallez wrote:
>
> >
> > Berin Loritsch a écrit :
> >
> >>Vincent Massol wrote:
> >
> > Agree with enforcing contracts, but IMHO it would be a safer construct
> > to throw an IllegalStateException if the manager is already set instead
> > of silently ignoring it.
>
> You have a point.
>
> > For this purpose, I have an ImmutablePropertyException (see attached
> > file) that automates this check in one line. You just have to write :
> >
> > public void Compose(ComponentManager manager)
> > {
> > ImmutableProperyException.check(this.manager, manager, "Manager
> > already set");
> > this.manager = manager;
> > }
> >
> > I'd be happy if this utility class could make its way into Avalon (but
> > where : framework, excalibur ?)
>
> Two questions:
>
> Which exception does it throw? guess: IllegalStateException()
It throws a ImmutablePropertyException which extends
IllegalStateException.
>
> Can we change the name?
Sure. It's a little bit verbose :)
> We already have an ExceptionUtil in org.apache.avalon.framework.ExceptionUtil.
> I would prefer adding a couple signatures:
>
> /** two member version will set the first variable if not set, or throw exception */
> ExceptionUtil.check(this.manager, manager, "Manager already set");
>
> /** one member version used for state checking */
> ExceptionUtil.check(this.isInitialized, "Component not initialized");
That's nice : it avoids an additional class and the associated import,
but "check" may be to imprecise in the context of "ExceptionUtil". So
what about something like "checkImmutable()" for the first one ? The
second is a simple assertion, so what about an "assertTrue()" (until the
whole world uses JDK 1.4) ?
Sylvain
--
Sylvain Wallez
Anyware Technologies - http://www.anyware-tech.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>