Reference Guide

Table Of Contents
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
</configuration>
</plugin>
</plugins>
</build>
</project>
The component can then use Annotations to define the configuration properties as illustrated in the
following listing.
Configurable Property Key Definition Example:
package com.hp.hm.impl;
import org.apache.felix.scr.annotations.*;
...
@Component (metatype=true)
public class SwitchComponent implements SwitchService {
@Property(intValue = 100, description="Some Configuration")
protected static final String CONFIG_KEY = "cfg.key";
...
}
The component is provided the configuration data by the OSGi framework as a Java Dictionary
object, which can be referenced as a basic Map of key -> value pairs. The key will always be a
Java String object, and the value will be a Java Object. A component will be provided the
configuration data at component initialization via an annotated “activate” method. Live updates to
a components configuration will be provided via an annotated “modified” method. Both of these
annotated methods should define a Map<String, Object> as an input parameter. The following
listing shows an example.
Configurable Property Example:
...
import com.hp.sdn.misc.ConfigUtils;
@Component (metatype=true)
public class SwitchComponent implements SwitchService {
@Property(intValue = 100, description="Some Configuration")
protected static final String CONFIG_KEY = "cfg.key";
private int someCfgVariable;
@Activate
protected void activate(Map<String, Object> config) {
someIntVariable = ConfigUtils.readInt(config, CONFIG_KEY, null, 100);
}
@Modified
protected void modified(Map<String, Object> config) {
22