avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leo Sutic <leosu...@apache.org>
Subject How to Slice Bread with Attributes (was: Re: Attributes again...)
Date Thu, 14 Aug 2003 23:43:31 GMT
Stephen wrote:
> Can you help me out here. I need to know how a container
> recognizes that an attribute must be recognized, and how
> a container establishes validity of a attribute that must
> be recognized, and how a container establishes that an
> attribute has in fact been recognized.

OK, problem definition: We have a class that may or may not be an Avalon
component, that may or may not have attributes which in turn may or may
not express a contract that the container must support in order to run the
component. What should the container do?

First, we determine if the class is indeed an Avalon component. This is
easy - all components have a special attribute (AvalonComponent or
something). We test for it and find that indeed this is an Avalon
component. if it isn't then the processing stops here.

Then we look at the set of attributes the class declares. some of them may
not have anything to do with Avalon, but part of the problem is figuring
out which ones do and which ones don't. So let's split the what happens
next into three cases:

 1. An attribute which is recognized by the container is declared by the
component:
    Easy - just do it.

 2. An attribute which is required by the container isn't declared by the
component.
    Easy - test for their existence. Failure means you can stop.

 3. An attribute is declared by the component, but the container doesn't
recognize it at all.
    This is the hard one - the question is: can the container ignore it?

>From now on I'll focus on case 3 - I believe that's the one you're asking
about.

The solution is simple - look at the attributes of the attribute. Create
an attribute that marks attributes as "Required by Avalon 4":

    public class Avalon4Requirement {}

And mark those attributes which must be supported by container with this
attribute:

    /**
     * All A4 containers must support dependencies.
     *
     * @@Avalon4Requirement
     */
    public class Dependency { ... }

So the algorithm is this:

 1. For each unknown attribute:
    a. Check if it has an attribute of type Avalon4Requirement.
       If so, stop - you can't run this component. if not, ignore
       and proceed with next attribute.


Regarding the Extension mechanism, suppose we did it this way:

 1. Define an extension attribute:

      public class Extension { ... }

 2. Don't mark it as Avalon4Required yet.

 3. When we feel like it, mark it as such.

Does this answer your question?

/LS

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


Mime
View raw message