Created
August 19, 2009 14:59
-
-
Save alaz/170392 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Scala trait to hold Configuration Admin | |
*/ | |
package com.yours.app | |
import org.osgi.service.cm.ConfigurationAdmin | |
trait ConfigAdminHolder { | |
protected var configAdmin: Option[ConfigurationAdmin] = None | |
def bindConfigAdmin(ca: ConfigurationAdmin): Unit = configAdmin = Some(ca) | |
def unbindConfigAdmin(ca: ConfigurationAdmin): Unit = configAdmin = None | |
} | |
/* | |
* OSGi component | |
*/ | |
class Component extends ConfigAdminHolder { | |
def someMethod { /* make use of configAdmin */ } | |
} | |
/* | |
* OSGi component XML | |
*/ | |
<?xml version="1.0" encoding="UTF-8"?> | |
<component name="My component"> | |
<implementation class="com.yours.app.Component"/> | |
<reference | |
name="ConfigAdmin Service" | |
interface="org.osgi.service.cm.ConfigurationAdmin" | |
bind="bindConfigAdmin" | |
unbind="unbindConfigAdmin" | |
cardinality="1..1" | |
policy="dynamic"/> | |
</component> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment