You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Robert Lillack (Updated) (JIRA)" <ji...@apache.org> on 2011/10/06 17:39:30 UTC
[jira] [Updated] (FELIX-2981) Unable to remove configuration
properties using iPOJO's configuration handler
[ https://issues.apache.org/jira/browse/FELIX-2981?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Robert Lillack updated FELIX-2981:
----------------------------------
Attachment: felix-2981-2.patch
> Unable to remove configuration properties using iPOJO's configuration handler
> -----------------------------------------------------------------------------
>
> Key: FELIX-2981
> URL: https://issues.apache.org/jira/browse/FELIX-2981
> Project: Felix
> Issue Type: Bug
> Components: iPOJO
> Affects Versions: iPOJO-1.8.0
> Environment: * Apache Felix Bundle Repository (1.6.0)
> * Apache Felix Configuration Admin Service (1.2.8)
> * Apache Felix Gogo Runtime (0.8.0)
> * Apache Felix iPOJO (1.8.0)
> * Apache Felix iPOJO Annotations (1.8.0)
> * iPOJO Metadata (1.4.0)
> * Apache Felix Preferences Service (1.0.4)
> Reporter: Robert Lillack
> Assignee: Clement Escoffier
> Priority: Minor
> Fix For: ipojo-core-1.8.2
>
> Attachments: felix-2981-2.patch, felix-2981.patch
>
>
> Hi,
> using iPOJO's _very nice_ OSGi Configuration Admin integration I sadly seem unable to remove any properties from a configuration to "reset" this property back to it's default value. Comparing the following two classes---one using iPOJO the other one directly implementing the ManagedService interface ...
> @Component(managedservice = "example1")
> @Instantiate
> public class Example1 {
>
> @Property
> private String key;
>
> @Updated
> private void updated() {
> System.out.format("example1 = %s\n", key);
> }
> }
> @Component
> @Instantiate
> public class Example2 implements ManagedService {
> BundleContext ctx;
>
> public Example2(BundleContext c) {
> ctx = c;
> }
>
> @Validate
> public void start() {
> ctx.registerService(ManagedService.class.getName(), this, getDefaults());
> }
> private Hashtable getDefaults() {
> Hashtable defaults = new Hashtable();
> defaults.put(Constants.SERVICE_PID, "example2");
> return defaults;
> }
> @Override
> public void updated(Dictionary properties) throws ConfigurationException {
> System.out.format("example2 = %s\n", properties == null ? null : properties.get("key"));
> }
> }
> ... with the code setting the properties looking like this ...
> public void set(String value) throws Exception {
> setProperty("example1", value);
> setProperty("example2", value);
> }
>
> public void unset() throws Exception {
> setProperty("example1", null);
> setProperty("example2", null);
> }
>
> private void setProperty(String srv, String value) throws IOException {
> Configuration cfg = configAdmin.getConfiguration(srv, null);
> Dictionary p = cfg.getProperties();
> if (p == null) {
> p = new Properties();
> }
>
> if (value == null) {
> p.remove("key");
> } else {
> p.put("key", value);
> }
> cfg.update(p);
> }
> ... these are the results after calling set("qsdasdasd") followed by unset():
> example1 = qsdasdasd
> example2 = qsdasdasd
> example1 = qsdasdasd
> example2 = null
> Am I using iPOJO the wrong way here? Thanks!
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira