Last active
January 4, 2016 07:49
-
-
Save shsteimer/8591063 to your computer and use it in GitHub Desktop.
This file contains 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
@Component(configurationFactory = true, | |
policy = ConfigurationPolicy.REQUIRE, metatype = true, immediate = true) | |
@Service() | |
public class MyFactoryConfigServiceClass { | |
//define config properties here as usual | |
@Property(name = "some.prop.name", label = "My Property", value = "") | |
private String myProperty | |
/** | |
* Activate the configuration. | |
* | |
* @param ctx | |
* the component context object | |
*/ | |
@Activate | |
protected void activate(final ComponentContext ctx) { | |
log.info("activating instance of {}", this.getClass().getName()); | |
Dictionary<?, ?> props = ctx.getProperties(); | |
//init property values using PropertiesUtil | |
myProperty = PropertiesUtil.toString(props.get("some.prop.name"),""); | |
} | |
} |
This file contains 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
@Component() | |
@Service() | |
public class MyFactoryConsumer { | |
@Reference(referenceInterface = MyFactoryConfigServiceClass.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, | |
policy = ReferencePolicy.DYNAMIC) | |
private List<MyFactoryConfigServiceClass> configs; | |
protected synchronized void bindMyFactoryConfigServiceClass(final MyFactoryConfigServiceClass config) { | |
if (configs == null) { | |
configs = new ArrayList<MyFactoryConfigServiceClass>(); | |
} | |
configs.add(config); | |
} | |
protected synchronized void unbindMyFactoryConfigServiceClass(final MyFactoryConfigServiceClass config) { | |
configs.remove(config); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment