org.jvnet.hk2.config
Annotation Type Element


@Retention(value=RUNTIME)
@Target(value={FIELD,METHOD})
public @interface Element

Indicates that this property or the field value must be injected from an XML element in a configuration file.

Author:
Kohsuke Kawaguchi
See Also:
Attribute

Optional Element Summary
 boolean key
          Indicates that this property becomes the name of the component.
 boolean reference
          Indicates that this property is a reference to another configured inhabitant.
 boolean required
          Indicates that this element is required.
 String value
          Element name.
 boolean variableExpansion
          Indicates that the variable expansion should be performed on this proeprty.
 

value

public abstract String value
Element name. See Attribute.value() for how the default value is inferred.

Default:
""

key

public abstract boolean key
Indicates that this property becomes the name of the component. There can be only one key on a class.

Default:
false

required

public abstract boolean required
Indicates that this element is required.

To specify the default value, simply use the field initializer to set it to a certain value. The field/method values are only set when the value is present.

Default:
false

reference

public abstract boolean reference
Indicates that this property is a reference to another configured inhabitant.

On XML, this is represented as a string value that points to the value of the key property of the target inhabitant. See the following example:

 @Configured
 class VirtualHost {
   @Attribute(key=true)
   String name;
 }

 @Configured
 class HttpListener {
   @Attribute(reference=true)
   VirtualHost host;
 }
 

 <virtual-host name="foo" />
 <http-listener host="foo" />
 

Default:
false

variableExpansion

public abstract boolean variableExpansion
Indicates that the variable expansion should be performed on this proeprty.

The configuration mechanism supports the Ant/Maven like variable expansion in the configuration XML out of the box. Normally this happens transparently to objects in modules, hence this property is set to true by default.

However, in a rare circumstance you might want to get values injected before the variables are expanded, in which case you can set this property to false to indicate so. Note that such property must be of type String (or its collection/array.)

Also note the inhabitants can always access the XML infoset by talking to Dom directly.

Default:
true


Copyright © 2012 Oracle Corporation. All Rights Reserved.