The entry tag declares a context entry required by a component. The component is supplied the context entry via a context argument as part of the contextualization lifecycle stage. Context entries my declare a object type or array of object types. If the type is not declared java.lang.String is assumed. Context entries may also be declared as optional and/or volatile. The default behaviour is to assume that a context entry is required (not optional) is is non-volatile.
Attribute | Required | Description |
---|---|---|
key | yes |
The context entry lookup key. |
alias | no |
Declaration of an alternative name that the component may use to lookup the entry. |
type | no |
The classname of the context entry that the component may cast the component to. If not declared, java.lang.String is assumed. |
volatile | no |
A value of true or false - if true a new instance of the context entry value shall be created and retured to the component per request. If false (the default) a container context implementation may safely cache context entry values. |
optional | no |
Declares the context entry as optional in which case the supply of the context entry is at the discretion of a container. |
package org.apache.avalon.playground; /** * Example of a component declaring a context entry dependencies. * * @avalon.component version="1.0" name="demo" */ public class Primary implements Contextualizable { /** * @avalon.entry key="home" type="java.io.File" optional="true" * @avalon.entry key="time" type="java.util.Date" volatile="true" * @avalon.entry key="table" type="java.lang.Object[]" * @avalon.entry key="urn:avalon:name" alias="block.name" */ public void contextualize( Context context ) throws ContextException { String name = (String) context.get( "name" ); Object[] array = (Object[]) context.get( "table" ); try { File home = (File) context.get( "home" ); ... } catch( ContextException ce ) { // it's optional } } }
Generated meta-info type descriptor:
<type> <info> <version>1.3.0</version> <name>primary-component</name> </info> <context> <entry key="home" type="java.io.File" optional="true"/> <entry key="time" type="java.util.Date" volatile="true"/> <entry key="table" type="java.lang.Object[]"/> <entry key="urn:avalon:name" alias="block.name"> </context> </type>