[TransWarp] Component hierarchy traversal

Radek Kanovsky rk at dat.cz
Fri Oct 10 13:03:48 EDT 2003

On Fri, Oct 10, 2003 at 12:11:19PM -0400, Phillip J. Eby wrote:

> >Bellow is my solution of problem with special command invocation
> >without hierarchy traversal.
> Please note that it's a bad idea to subclass ConfigurationRoot, as it makes 
> it more difficult for others to use your components as part of a larger 
> application.  And, there isn't any need for you to, in order to implement 
> what you did.  There's no reason the "root" application object can't simply:
>     _me = binding.Obtain('.', offerAs=[ICommandRoot])
> ...or something similar, for all the children to be able to access 
> it.  Your 'registerCommand' binding could then simply do this:
>     root = binding.lookupComponent(ICommandRoot)

I have noticed that warning in peak.config.config_components module
but there were some problem with binding evaluation order and this
was a quick solution. Additionaly I planned to add some functionality
to this root (parsing parameters from XML configuration files).

What is the problem: `binding.lookupComponent(ICommandRoot)' does not find
ICommandRoot because `_me = binding.Obtain('.',offerAs=[ICommandRoot])'
is evaluated later I guess. Even if uponAssembly is True.

Looking at peak.binding.component:Component.__parentComponent method
it seems that bindings with uponAssembly set are evaluated before binding
`__parentComponent = Make(__parentComponent, suggestParent=False)' finish.
So my registration routines are invoked before instance config.makeRoot()
is set up as parent of my application and lookupComponent(ICommandRoot)
fails with exception peak.exceptions.InvalidRoot because my Application
instance is supposed to be root at that time.

> So, there's no reason to make it a configuration root, and hardcode its 
> location.  Doing it this way instead, will allow your apps to be invoked as 
> 'peak import:whatever.Application' if you derive the application class from 
> peak.running.commands.AbstractCommand.

peak.running is terra inkognita in the meanwhile :-) I will try.


Radek K

More information about the PEAK mailing list