Skip to content

Commit

Permalink
Update config admin bridge to R5
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1686177 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cziegeler committed Jun 18, 2015
1 parent 66c3dc9 commit e920048
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 67 deletions.
16 changes: 8 additions & 8 deletions eventadmin/bridge.configuration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.apache.felix</groupId>
<artifactId>felix</artifactId>
<version>1.0.4</version>
<artifactId>felix-parent</artifactId>
<version>2.1</version>
<relativePath>../../pom/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand All @@ -33,22 +33,22 @@
</description>
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.0.0</version>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>1.0.0</version>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.enterprise</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.0</version>
<version>2.5.3</version>
<extensions>true</extensions>
<configuration>
<instructions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand All @@ -19,6 +19,7 @@
package org.apache.felix.eventadmin.bridge.configuration;

import java.util.Arrays;
import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.framework.BundleContext;
Expand Down Expand Up @@ -49,72 +50,77 @@ public ConfigurationEventToEventAdminBridge(final BundleContext context)

public void configurationEvent(final ConfigurationEvent event)
{
final ServiceReference ref = m_context
.getServiceReference(EventAdmin.class.getName());
final ServiceReference ref = m_context.getServiceReference(EventAdmin.class.getName());

if(null != ref)
if (null != ref)
{
final EventAdmin eventAdmin = (EventAdmin) m_context
.getService(ref);
final EventAdmin eventAdmin = (EventAdmin) m_context.getService(ref);

if(null != eventAdmin)
if (null != eventAdmin)
{
final String topic;

switch(event.getType())
{
case ConfigurationEvent.CM_UPDATED:
topic = "org/osgi/service/cm/ConfigurationEvent/CM_UPDATED";
break;
case ConfigurationEvent.CM_DELETED:
topic = "org/osgi/service/cm/ConfigurationEvent/CM_DELETED";
break;
default:
m_context.ungetService(ref);
return;
}

final Hashtable properties = new Hashtable();

if(null != event.getFactoryPid())
try
{
properties.put("cm.factoryPid", event.getFactoryPid());
final String topic;

switch (event.getType())
{
case ConfigurationEvent.CM_UPDATED:
topic = "org/osgi/service/cm/ConfigurationEvent/CM_UPDATED";
break;
case ConfigurationEvent.CM_DELETED:
topic = "org/osgi/service/cm/ConfigurationEvent/CM_DELETED";
break;
case ConfigurationEvent.CM_LOCATION_CHANGED:
topic = "org/osgi/service/cm/ConfigurationEvent/CM_LOCATION_CHANGED";
break;
default:
return;
}

final Hashtable properties = new Hashtable();

if (null != event.getFactoryPid())
{
properties.put("cm.factoryPid", event.getFactoryPid());
}

properties.put("cm.pid", event.getPid());

final ServiceReference eventRef = event.getReference();

if (null == eventRef)
{
throw new IllegalArgumentException(
"ConfigurationEvent.getReference() may not be null");
}

properties.put(EventConstants.SERVICE, eventRef);

properties.put(EventConstants.SERVICE_ID, eventRef.getProperty(
EventConstants.SERVICE_ID));

final Object objectClass = eventRef.getProperty(
Constants.OBJECTCLASS);

if(!(objectClass instanceof String[])
|| !Arrays.asList((String[]) objectClass).contains(
ConfigurationAdmin.class.getName()))
{
throw new IllegalArgumentException(
"Bad objectclass: " + objectClass);
}

properties.put(EventConstants.SERVICE_OBJECTCLASS, objectClass);

properties.put(EventConstants.SERVICE_PID, eventRef.getProperty(
EventConstants.SERVICE_PID));

eventAdmin.postEvent(new Event(topic, (Dictionary)properties));
}

properties.put("cm.pid", event.getPid());

final ServiceReference eventRef = event.getReference();

if(null == eventRef)
finally
{
throw new IllegalArgumentException(
"ConfigurationEvent.getReference() may not be null");
m_context.ungetService(ref);
}

properties.put(EventConstants.SERVICE, eventRef);

properties.put(EventConstants.SERVICE_ID, eventRef.getProperty(
EventConstants.SERVICE_ID));

final Object objectClass = eventRef.getProperty(
Constants.OBJECTCLASS);

if(!(objectClass instanceof String[])
|| !Arrays.asList((String[]) objectClass).contains(
ConfigurationAdmin.class.getName()))
{
throw new IllegalArgumentException(
"Bad objectclass: " + objectClass);
}

properties.put(EventConstants.SERVICE_OBJECTCLASS, objectClass);

properties.put(EventConstants.SERVICE_PID, eventRef.getProperty(
EventConstants.SERVICE_PID));

eventAdmin.postEvent(new Event(topic, properties));

m_context.ungetService(ref);
}
}
}
Expand Down

0 comments on commit e920048

Please sign in to comment.