Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Component properties are the primary mechanism for adding configuration to an application. By default, property values are Property values can be defined in a composite file . In some cases, it may be necessary to externalize property values so that they can be changed without modifying or DSL. However, in many cases, property values need to be modified without opening a contribution archive. Fabric3  Fabric3 supports the ability to define property values in external XML files that are deployed separately from external to the contribution that references them.

Defining External Property Values with Annotations

External property values are specified in a composite using an XPath expression that points to a value in an XML file. With Java annotations, this is done using the Source annotation:

Code Block
languagejava
@Component(namespaces = {@Namespace(prefix = "foo", uri = "urn:foo")})
public class ComponentImpl implements ... {
    
	@Property
    @Source("$app//foo:configuration/@installation.id")
    protected String installationId;

}

The Source annotation defines a configuration file, app.xml, located in the runtime's config directory  (<image>/runtimes/<name>/config) that contains the value for the installationId property. The app.xml file could be similar to the following:

Code Block
languagexml
<configuration xmlns:foo="urn:foo" installationId="test id">
   
</configuration> 

The XPath expression can also point to arbitrarily nested elements in a configuration file. Also note the use of namespaces. The Namespace attribute on the Component annotation is used to define a namespace to use when applying the XPath expression.

Defining External Property Values with Composites

A property source can also be defined using XML-based composites:

Code Block
languagexml
<composite ... xmlns:f3-samples="urn:samples.fabric3.org">
    <component name="GatewayService">
        <implementation.java class="..."/>
        <property name="interval" source="$app//f3-samples:gateway/@timeout"/>
    </component>
</composite> 

...

Code Block
languagexml
<config xmlns="urn:fabric3.org" name="app" targetNamespace="urn:samples.fabric3.org">
    <gateway tineouttimeout="100"/>
</config>

The app XML file is deployed separately from the contribution containing the Gateway component. Note that it is possible for multiple components to reference parts of the same external configuration file.

...