You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Vincent Massol <vm...@octo.com> on 2001/11/13 19:14:15 UTC

compose() method and developing with avalon pdf

Hi,

In the developing with avalon pdf, there is an example of how to implement
the compose() method :

public void compose(ComponentManager manager) throws ComponentException {
  if (this.manager == null) {
    this.manager = manager;
    myGuard = (Guardian) this.manager.lookup(Guardian.ROLE);
  }
}

I'm wondering why there is a test to verify if the manager is not null (i.e.
to verify if the compose() method has not already been called) ? I thought
that the lifecycle for composable would prevent this method being called
twice. Any reason ? If not, shouldn't we amend the doc, as most persons will
use this doc as their starting point (as I am ... :) ).

Thanks
-Vincent


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: compose() method and developing with avalon pdf

Posted by Peter Donald <do...@apache.org>.
On Wed, 14 Nov 2001 05:34, Berin Loritsch wrote:
> Vincent Massol wrote:
> > Actually, there is another example in the pdf book :
> >
> > if (initialized || disposed) {
> >   throw new IllegalStateException ("Illegal call");
> > }
> > if (null == this.manager) {
> >   this.manager = cmanager;
> > }
> >
> > Is it the recommended way or do you usually assume that the lifecycle is
> > enforced ? I have a feeling that you'll answer the following : it
> > depends. If you're using excalibur component manager then you don't need
> > these checks but if you're not using any component manager, you'd rather
> > check. maybe not ... let's see ... :)
> >
> > In any case, I'd like to have your opinion.
>
> Bottom line is this:
>
> You should ALWAYS explicitly enforce your contracts.  This leads to secure
> components that cannot be interacted with in ways you had no intention of
> allowing.

Personally I say "it depends" ;)

I think it is the containers responsibility to maintain object lifecycle (and 
thus it will never call compose multiple times). I don't think other objects 
should get access to raw object except via proxys and thus you never have to 
worry about other people calling method. (and that is pretty much how Phoenix 
operates).

-- 
Cheers,

Pete

---------------------------------
I think not; therefore I ain't...
---------------------------------

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: compose() method and developing with avalon pdf

Posted by Peter Donald <do...@apache.org>.
On Thu, 15 Nov 2001 22:03, Sylvain Wallez wrote:
> > 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) ?

I think I would still prefer something like

if( null != m_manager ) 
{ 
   throw new IllegalStateException( "manager already set");
}

Slightly more typing but far less coupling and easier to understand IMO.

-- 
Cheers,

Pete

----------------------------------------
"Liberty means responsibility. That is 
      why most men dread it." - Locke
----------------------------------------

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: compose() method and developing with avalon pdf

Posted by Peter Donald <do...@apache.org>.
On Fri, 16 Nov 2001 00:43, Berin Loritsch wrote:
> Sylvain Wallez wrote:
> >>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) ?
>
> Actually I started a ComponentUtil to assist in the process.  The
> ComponentUtil uses a long with bit flags to test if it is legal to perform
> the verious operations.
>
> It will be helpful, and I think it belongs in Framework.  What do you all
> think?


lets see it first ;)

-- 
Cheers,

Pete

--------------------------------
 These aren't the droids you're 
 looking for. Move along. 
--------------------------------

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: compose() method and developing with avalon pdf

Posted by Berin Loritsch <bl...@apache.org>.
Sylvain Wallez wrote:

> 
>>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) ?



Actually I started a ComponentUtil to assist in the process.  The ComponentUtil
uses a long with bit flags to test if it is legal to perform the verious
operations.

It will be helpful, and I think it belongs in Framework.  What do you all
think?





-- 

"Those who would trade liberty for
  temporary security deserve neither"
                 - Benjamin Franklin


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: compose() method and developing with avalon pdf

Posted by Sylvain Wallez <sy...@anyware-tech.com>.

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: compose() method and developing with avalon pdf

Posted by Berin Loritsch <bl...@apache.org>.
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()

Can we change the name?

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");




-- 

"Those who would trade liberty for
  temporary security deserve neither"
                 - Benjamin Franklin


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: compose() method and developing with avalon pdf

Posted by Sylvain Wallez <sy...@anyware-tech.com>.

Berin Loritsch a �crit :
> 
> Vincent Massol wrote:
> 
> > Actually, there is another example in the pdf book :
> >
> > if (initialized || disposed) {
> >   throw new IllegalStateException ("Illegal call");
> > }
> > if (null == this.manager) {
> >   this.manager = cmanager;
> > }
> >
> > Is it the recommended way or do you usually assume that the lifecycle is
> > enforced ? I have a feeling that you'll answer the following : it depends.
> > If you're using excalibur component manager then you don't need these checks
> > but if you're not using any component manager, you'd rather check. maybe not
> > ... let's see ... :)
> >
> > In any case, I'd like to have your opinion.
> 
> Bottom line is this:
> 
> You should ALWAYS explicitly enforce your contracts.  This leads to secure
> components that cannot be interacted with in ways you had no intention of
> allowing.

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.

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 ?)

Sylvain.

-- 
Sylvain Wallez
Anyware Technologies - http://www.anyware-tech.com

Re: compose() method and developing with avalon pdf

Posted by Berin Loritsch <bl...@apache.org>.
Vincent Massol wrote:

> Actually, there is another example in the pdf book :
> 
> if (initialized || disposed) {
>   throw new IllegalStateException ("Illegal call");
> }
> if (null == this.manager) {
>   this.manager = cmanager;
> }
> 
> Is it the recommended way or do you usually assume that the lifecycle is
> enforced ? I have a feeling that you'll answer the following : it depends.
> If you're using excalibur component manager then you don't need these checks
> but if you're not using any component manager, you'd rather check. maybe not
> ... let's see ... :)
> 
> In any case, I'd like to have your opinion.


Bottom line is this:

You should ALWAYS explicitly enforce your contracts.  This leads to secure
components that cannot be interacted with in ways you had no intention of
allowing.


> 
> -Vincent
> 
> ----- Original Message -----
> From: "Vincent Massol" <vm...@octo.com>
> To: <av...@jakarta.apache.org>
> Sent: Tuesday, November 13, 2001 6:14 PM
> Subject: compose() method and developing with avalon pdf
> 
> 
> 
>>Hi,
>>
>>In the developing with avalon pdf, there is an example of how to implement
>>the compose() method :
>>
>>public void compose(ComponentManager manager) throws ComponentException {
>>  if (this.manager == null) {
>>    this.manager = manager;
>>    myGuard = (Guardian) this.manager.lookup(Guardian.ROLE);
>>  }
>>}
>>
>>I'm wondering why there is a test to verify if the manager is not null
>>
> (i.e.
> 
>>to verify if the compose() method has not already been called) ? I thought
>>that the lifecycle for composable would prevent this method being called
>>twice. Any reason ? If not, shouldn't we amend the doc, as most persons
>>
> will
> 
>>use this doc as their starting point (as I am ... :) ).
>>
>>Thanks
>>-Vincent
>>
>>
>>--
>>To unsubscribe, e-mail:
>>
> <ma...@jakarta.apache.org>
> 
>>For additional commands, e-mail:
>>
> <ma...@jakarta.apache.org>
> 
>>
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> .
> 
> 



-- 

"Those who would trade liberty for
  temporary security deserve neither"
                 - Benjamin Franklin


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: compose() method and developing with avalon pdf

Posted by Vincent Massol <vm...@octo.com>.
Actually, there is another example in the pdf book :

if (initialized || disposed) {
  throw new IllegalStateException ("Illegal call");
}
if (null == this.manager) {
  this.manager = cmanager;
}

Is it the recommended way or do you usually assume that the lifecycle is
enforced ? I have a feeling that you'll answer the following : it depends.
If you're using excalibur component manager then you don't need these checks
but if you're not using any component manager, you'd rather check. maybe not
... let's see ... :)

In any case, I'd like to have your opinion.

-Vincent

----- Original Message -----
From: "Vincent Massol" <vm...@octo.com>
To: <av...@jakarta.apache.org>
Sent: Tuesday, November 13, 2001 6:14 PM
Subject: compose() method and developing with avalon pdf


> Hi,
>
> In the developing with avalon pdf, there is an example of how to implement
> the compose() method :
>
> public void compose(ComponentManager manager) throws ComponentException {
>   if (this.manager == null) {
>     this.manager = manager;
>     myGuard = (Guardian) this.manager.lookup(Guardian.ROLE);
>   }
> }
>
> I'm wondering why there is a test to verify if the manager is not null
(i.e.
> to verify if the compose() method has not already been called) ? I thought
> that the lifecycle for composable would prevent this method being called
> twice. Any reason ? If not, shouldn't we amend the doc, as most persons
will
> use this doc as their starting point (as I am ... :) ).
>
> Thanks
> -Vincent
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>