Leo Sutic wrote:

>
> +1
>
>But I think:
>
>          <context>
>            <import key="my-root-dir-key"
>                 resource="avalon.home.dir"
>                  optional="false"/>
>            <!-- other assembly based directives go here -->
>          </context>
>
>Is nicer.
>

Agreed.

Based on the above - I've dropped the optional attribute because that's 
a constraint declaration that is included in the ContextDescritor - no 
need to duplicate that in the directive), which leads to the following 
example that covers all of the variants of usage that we have discussed:

   <context class="MyContextClass">
       <!-- container supplied context entries -->
       <import key="my-root-dir-key"
                 resource="avalon.home.dir"/>
       <import key="block-name"
                 resource="phoenix.block.name"/
       <!-- assembler declared context entries -->
       <entry key="name" value="Fred"/>
       <entry key="files" type="java.io.File" value="../local"/>
       <entry key="thing" type="net.osm.CustomObject">
          <parameter value="Hello World"/>
          <parameter class="int" value="1024"/>
       </entry>
   </context>

And placing some structure around this ...

    <!--
    The key identifying a context entry.
    -->
    <!ENTITY % key "key CDATA #REQUIRED">

    <!--
    A reference to a named resource provided by a container.
    -->
    <!ENTITY % resource "resource CDATA #REQUIRED">

    <!--
    The implement class of a context or entry type.  The
    default value shall be java.lang.String when used in the scope
    of an entry or parameter declaration, and
    org.apache.avalon.framework.context.DefaultContext in the scope
    of the context element.
    -->
    <!ENTITY % class "class CDATA #IMPLIED">

    <!--
    A String value of a entry.  The value will be used
    as a single parameter argument in the creation of an
    context entry.  The corresponding class attribute must
    refernce a class with a single String constructor
    (e.g. java.io.File( String path )
    -->
    <!ENTITY % value "value CDATA #IMPLIED">

    <!--
    A context creation directive.  The directive may contain
    any number of input and entry directives.  Each import directive
    references a container supplied resource.  Each entry directive
    declares the creation criteria for a single or complex object
    instance.
    -->
    <!ELEMENT context((import|entry)*) >
    <!ATTLIST context
         %class;
    >

    <!--
    An import directive is an instruction used be an assembler to
    declare to a container that a resource identified by name shall
    be supplied to the component under a context key.
    -->
    <!ELEMENT import EMPTY >
    <!ATTLIST import
        %key;
        %resource;
    >

    <!--
    An entry is a directive used to create a new instance of the the
    type declared under the class attribute, to be assigned in the
    context under the key declared by the key attribute.  If a value
    attribute is supplied, the class attribute shall refer to an
    object class with a constructor containing a single String parameter.
    If no value attribute is declared, the entry must contain one or more
    parameters, each describing a constructor parameter value that will
    be used during object instntiation.
    -->
    <!ELEMENT entry (parameter*) >
    <!ATTLIST entry
        %key;
        %class;
        %value;
    >

    <!--
    A parameter describes the value of a constructor parameter.  The
    class attribute if undeclared will default to java.lang.String. The
    value attribute must be supplied.
    -->
    <!ENTITY % param.class "class CDATA #IMPLIED">
    <!ENTITY % param.value "value CDATA #REQUIRED">
    <!ELEMENT parameter EMPTY >
    <!ATTLIST parameter
        %param.class;
        %param.value;
    >

If this looks ok I'll turn it into a real DTD and put together some 
validated examples.

Cheers, Steve.

-- 

Stephen J. McConnell

OSM SARL
digital products for a global economy
mailto:[EMAIL PROTECTED]
http://www.osm.net




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

Reply via email to