Leo Sutic wrote:
Stephen wrote:

I need to know how a container
recognizes that an attribute must be recognized

<snip/>

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.

this is a real nice example of the power of .Net-style attributes and how it makes life easier if you solve the generic problem.


Steve also asked:
>> how
>>a container establishes validity of a attribute that must
>>be recognized,

answer:

since in the generic model an attribute is modeled by a class, you can implement the validity checking in the class / and/or expose the neccessary information for validity checking in the class:

     /**
      * All A4 containers must support dependencies.
      *
      * @@Avalon4Requirement
      */
     public class Dependency {
       private String m_name;

       public Dependency( String name )
       {
         Asserts.assertNotNull( name ); // throw exception
         m_name = name;
       }

       public String getName() { return m_name; }
     }

I've yet to look at the API Leo wrote for the attribute tool, but probably something like the code below:

public class VerificationUtil
{
  public static verifyDependencies( Class componentClass )
  {
  try
  {
    Dependency[] deps = (Dependency[])AttributeUtil.getAttributes(
        componentClass,
        Dependency.class );

    for( int i = 0; i < deps.length; i++ )
    {
      String depName = deps[i].getName();
      if( !assembly.canProvideImplementionFor( depName ) )
        throw new UnsupportedTypeException(
          new DependencyException( componentClass, depName ) );
    }
  }
  catch( Exception e )
  { /* the assertNotNull() failed; the attribute looked like
     *
     * @@Dependency( null )
     *
     * which is not acceptable.
     */
    throw new UnsupportedTypeException( e );
  }
}

is how a container establishes validity.

>> and how a container establishes that an
>>attribute has in fact been recognized.

ehm, the container should always know that it has recognized an attribute when it recognizes the attribute, right? I guess I don't parse the sentence properly :D

cheers,

- Leo



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to