Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FilterTests.java11
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceReferenceImpl.java36
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl.java16
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/ServiceReference.java30
4 files changed, 91 insertions, 2 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FilterTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FilterTests.java
index 95d4d5687..72b32f465 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FilterTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FilterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 IBM Corporation and others.
+ * Copyright (c) 2008, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,6 +14,7 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import junit.framework.*;
+import org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap;
import org.osgi.framework.*;
public abstract class FilterTests extends TestCase {
@@ -434,5 +435,13 @@ public abstract class FilterTests extends TestCase {
public boolean isAssignableTo(Bundle bundle, String className) {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public Dictionary getProperties() {
+ if (dictionary == null) {
+ return new CaseInsensitiveDictionaryMap();
+ }
+ return new CaseInsensitiveDictionaryMap(dictionary);
+ }
}
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceReferenceImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceReferenceImpl.java
index ab34d6d45..71e4f2c56 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceReferenceImpl.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceReferenceImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2012 IBM Corporation and others.
+ * Copyright (c) 2003, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
package org.eclipse.osgi.internal.serviceregistry;
+import java.util.Dictionary;
import org.osgi.framework.*;
/**
@@ -272,4 +273,37 @@ public class ServiceReferenceImpl<S> implements ServiceReference<S> {
String[] getClasses() {
return registration.getClasses();
}
+
+ /**
+ * Returns a copy of the properties of the service referenced by this
+ * {@code ServiceReference} object.
+ * <p>
+ * This method will continue to return the properties after the service has
+ * been unregistered. This is so references to unregistered services (for
+ * example, {@code ServiceReference} objects stored in the log) can still be
+ * interrogated.
+ * <p>
+ * The returned {@code Dictionary} object:
+ * <ul>
+ * <li>Must map property values by using property keys in a
+ * <i>case-insensitive manner</i>.</li>
+ * <li>Must return property keys is a <i>case-preserving</i> manner. This
+ * means that the keys must have the same case as the corresponding key in
+ * the properties {@code Dictionary} that was passed to the
+ * {@link BundleContext#registerService(String[],Object,Dictionary)} or
+ * {@link ServiceRegistration#setProperties(Dictionary)} methods.</li>
+ * <li>Is the property of the caller and can be modified by the caller but
+ * any changes are not reflected in the properties of the service.
+ * {@link ServiceRegistration#setProperties(Dictionary)} must be called to
+ * modify the properties of the service.</li>
+ * </ul>
+ *
+ * @return A copy of the properties of the service referenced by this
+ * {@code ServiceReference} object
+ * @since 1.9
+ */
+ @Override
+ public Dictionary<String, Object> getProperties() {
+ return registration.getPropertiesCopy();
+ }
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl.java
index 6ad73da28..fbe499653 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl.java
@@ -387,6 +387,22 @@ public class ServiceRegistrationImpl<S> implements ServiceRegistration<S>, Compa
}
/**
+ * Get a copy of the service's properties.
+ *
+ * <p>This method will continue to return the properties after the
+ * service has been unregistered. This is so that references to
+ * unregistered service can be interrogated.
+ * (For example: ServiceReference objects stored in the log.)
+ *
+ * @return A copy of the properties.
+ */
+ Dictionary<String, Object> getPropertiesCopy() {
+ synchronized (registrationLock) {
+ return new ServiceProperties(properties);
+ }
+ }
+
+ /**
* Return the service id for this service.
* @return The service id for this service.
*/
diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/ServiceReference.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/ServiceReference.java
index d561e9049..a5717304f 100644
--- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/ServiceReference.java
+++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/ServiceReference.java
@@ -181,4 +181,34 @@ public interface ServiceReference<S> extends Comparable<Object> {
*/
@Override
public int compareTo(Object reference);
+
+ /**
+ * Returns a copy of the properties of the service referenced by this
+ * {@code ServiceReference} object.
+ * <p>
+ * This method will continue to return the properties after the service has
+ * been unregistered. This is so references to unregistered services (for
+ * example, {@code ServiceReference} objects stored in the log) can still be
+ * interrogated.
+ * <p>
+ * The returned {@code Dictionary} object:
+ * <ul>
+ * <li>Must map property values by using property keys in a
+ * <i>case-insensitive manner</i>.</li>
+ * <li>Must return property keys is a <i>case-preserving</i> manner. This
+ * means that the keys must have the same case as the corresponding key in
+ * the properties {@code Dictionary} that was passed to the
+ * {@link BundleContext#registerService(String[],Object,Dictionary)} or
+ * {@link ServiceRegistration#setProperties(Dictionary)} methods.</li>
+ * <li>Is the property of the caller and can be modified by the caller but
+ * any changes are not reflected in the properties of the service.
+ * {@link ServiceRegistration#setProperties(Dictionary)} must be called to
+ * modify the properties of the service.</li>
+ * </ul>
+ *
+ * @return A copy of the properties of the service referenced by this
+ * {@code ServiceReference} object
+ * @since 1.9
+ */
+ public Dictionary<String,Object> getProperties();
}

Back to the top