Permalink
Browse files

buglabs-osgi: style fixes in common

  • Loading branch information...
1 parent 2058469 commit a1313a9cc0972f19ad816792fecae02038889c98 @kgilmer kgilmer committed Aug 4, 2011
@@ -39,12 +39,18 @@
import org.osgi.framework.InvalidSyntaxException;
/**
- * A helper class for OSGi filters.
+ * A helper class for constructing OSGi filters.
*
*/
public final class FilterUtil {
/**
+ * Non-constructible utility class.
+ */
+ private FilterUtil() {
+
+ }
+ /**
* Generate a service filter string for a single service.
* @param clazz Service name
* @return Filter as a String
@@ -70,10 +76,13 @@ public static String generateServiceFilter(String ... services) {
public static String generateServiceFilter(List<String> services) {
if (services == null) {
return null;
- } if (services.size() == 1) {
+ }
+
+ if (services.size() == 1) {
return "(" + Constants.OBJECTCLASS + "=" + services.get(0) + ")";
} else if (services.size() > 1) {
- return "(|" + generateServiceFilter(services.subList(0, 1)) + generateServiceFilter(services.subList(1, services.size())) + ")";
+ return "(|" + generateServiceFilter(services.subList(0, 1))
+ + generateServiceFilter(services.subList(1, services.size())) + ")";
}
return "";
@@ -96,13 +105,16 @@ public static Filter generateServiceFilter(BundleContext context, String[] servi
/**
* servicesMap is SortedMap<String, Map<String, String>> where the key is
- * the service name and the map is a map of service properties
+ * the service name and the map is a map of service properties.
*
* (| (& (objectClass=com.buglabs.bug.module.bugbee.pub.IBUGBeeControl) (&
* (Provider=com.buglabs.bug.module.bugbee.BUGBeeModlet)(Slot=2))) (| (&
* (objectClass=com.buglabs.module.IModuleControl)) (&
* (objectClass=org.osgi.service.http.HttpService)(port=8082))))
*
+ * @param servicesMap Map of services to generate filter with.
+ * @return Filter as a string.
+ *
*/
public static String generateServiceFilter(SortedMap<String, Map<String, String>> servicesMap) {
if (servicesMap.size() == 1) {
@@ -119,15 +131,16 @@ public static String generateServiceFilter(SortedMap<String, Map<String, String>
* Generate a Filter as a String given a Map of property/value pairs.
* (& (prop1=value1) (& (prop2=value1)))
*
- * @param propertiesMap
+ * @param propertiesMap Map of properties
* @return Filter as a String
*/
public static String generatePropertiesFilter(SortedMap<String, String> propertiesMap) {
if (propertiesMap.size() == 1) {
return "(" + propertiesMap.firstKey() + "=" + propertiesMap.get(propertiesMap.firstKey()) + ")";
} else if (propertiesMap.size() > 1) {
- return "(&" + generatePropertiesFilter(propertiesMap.subMap(propertiesMap.firstKey(), propertiesMap.firstKey() + "\0"))
- + generatePropertiesFilter(propertiesMap.tailMap(propertiesMap.firstKey() + "\0")) + ")";
+ return "(&" + generatePropertiesFilter(propertiesMap.subMap(propertiesMap.firstKey(),
+ propertiesMap.firstKey() + "\0")) + generatePropertiesFilter(
+ propertiesMap.tailMap(propertiesMap.firstKey() + "\0")) + ")";
}
return "";
}
@@ -170,19 +170,19 @@ public void run() {
/* (non-Javadoc)
* @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference, java.lang.Object)
*/
- public void modifiedService(ServiceReference arg0, Object arg1) {
- String key = ((String []) arg0.getProperty(Constants.OBJECTCLASS))[0];
+ public void modifiedService(ServiceReference reference, Object arg1) {
+ String key = ((String []) reference.getProperty(Constants.OBJECTCLASS))[0];
serviceMap.put(key, arg1);
}
/* (non-Javadoc)
* @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference, java.lang.Object)
*/
- public void removedService(ServiceReference arg0, Object arg1) {
+ public void removedService(ServiceReference reference, Object arg1) {
if (shutdownCalled)
return;
- String key = ((String []) arg0.getProperty(Constants.OBJECTCLASS))[0];
+ String key = ((String []) reference.getProperty(Constants.OBJECTCLASS))[0];
if (serviceMap.containsKey(key)) {
serviceMap.remove(key);
@@ -193,8 +193,8 @@ public void removedService(ServiceReference arg0, Object arg1) {
try {
runnable.shutdown();
} catch (Exception e) {
- if (arg0 != null && arg0.getBundle() != null && arg0.getBundle().getBundleContext() != null) {
- LogService ls = LogServiceUtil.getLogService(arg0.getBundle().getBundleContext());
+ if (reference != null && reference.getBundle() != null && reference.getBundle().getBundleContext() != null) {
+ LogService ls = LogServiceUtil.getLogService(reference.getBundle().getBundleContext());
if (ls != null) {
ls.log(LogService.LOG_ERROR, "An error occured while shutting down ManagedRunnable.", e);
}

0 comments on commit a1313a9

Please sign in to comment.