Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBJ Hargrave2008-11-11 17:23:44 +0000
committerBJ Hargrave2008-11-11 17:23:44 +0000
commit9529dec90ed5f3a88499caa84d707de8b89f106d (patch)
tree147a1b8dcc6f736d4cc9cd31c87c562a1fea438d
parent1a20b884aa947ec896aacd900d903ffcbf120ecd (diff)
downloadrt.equinox.framework-9529dec90ed5f3a88499caa84d707de8b89f106d.tar.gz
rt.equinox.framework-9529dec90ed5f3a88499caa84d707de8b89f106d.tar.xz
rt.equinox.framework-9529dec90ed5f3a88499caa84d707de8b89f106d.zip
ASSIGNED - bug 254912: FilterImpl needs to support foreign ServiceReference parameters
https://bugs.eclipse.org/bugs/show_bug.cgi?id=254912
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FilterTests.java101
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/FilterImpl.java228
-rwxr-xr-xbundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java69
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/ExternalMessages.properties14
4 files changed, 253 insertions, 159 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 e9ae373e7..c9289bbf7 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
@@ -127,8 +127,9 @@ public class FilterTests extends TestCase {
}
}
- private void testFilter(String query, Properties props, int expect) {
+ private void testFilter(String query, Dictionary props, int expect) {
final BundleContext testContext = OSGiTestsActivator.getContext();
+ final ServiceReference ref = new DictionaryServiceReference(props);
Filter p;
try {
p = testContext.createFilter(query);
@@ -145,6 +146,28 @@ public class FilterTests extends TestCase {
boolean val = p.match(props);
assertEquals("wrong result", expect == ISTRUE, val); //$NON-NLS-1$
+
+ val = p.match(ref);
+ assertEquals("wrong result", expect == ISTRUE, val); //$NON-NLS-1$
+
+ try {
+ p = FrameworkUtil.createFilter(query);
+
+ if (expect == ISILLEGAL) {
+ fail("expected exception"); //$NON-NLS-1$
+ }
+ } catch (InvalidSyntaxException e) {
+ if (expect != ISILLEGAL) {
+ fail("exception: " + e.toString()); //$NON-NLS-1$
+ }
+ return;
+ }
+
+ val = p.match(props);
+ assertEquals("wrong result", expect == ISTRUE, val); //$NON-NLS-1$
+
+ val = p.match(ref);
+ assertEquals("wrong result", expect == ISTRUE, val); //$NON-NLS-1$
}
public void testComparable() {
@@ -161,10 +184,29 @@ public class FilterTests extends TestCase {
comp = new SampleComparable("42"); //$NON-NLS-1$
hash.put("comparable", comp); //$NON-NLS-1$
assertTrue("does not match filter", filter.match(hash)); //$NON-NLS-1$
+ assertTrue("does not match filter", filter.match(new DictionaryServiceReference(hash))); //$NON-NLS-1$
comp = new Long(42);
hash.put("comparable", comp); //$NON-NLS-1$
assertTrue("does not match filter", filter.match(hash)); //$NON-NLS-1$
+ assertTrue("does not match filter", filter.match(new DictionaryServiceReference(hash))); //$NON-NLS-1$
+
+ try {
+ filter = FrameworkUtil.createFilter("(comparable=42)"); //$NON-NLS-1$
+ } catch (InvalidSyntaxException e) {
+ fail("invalid syntax" + e); //$NON-NLS-1$
+ }
+ hash = new Hashtable();
+
+ comp = new SampleComparable("42"); //$NON-NLS-1$
+ hash.put("comparable", comp); //$NON-NLS-1$
+ assertTrue("does not match filter", filter.match(hash)); //$NON-NLS-1$
+ assertTrue("does not match filter", filter.match(new DictionaryServiceReference(hash))); //$NON-NLS-1$
+
+ comp = new Long(42);
+ hash.put("comparable", comp); //$NON-NLS-1$
+ assertTrue("does not match filter", filter.match(hash)); //$NON-NLS-1$
+ assertTrue("does not match filter", filter.match(new DictionaryServiceReference(hash))); //$NON-NLS-1$
}
private static class SampleComparable implements Comparable {
@@ -183,4 +225,61 @@ public class FilterTests extends TestCase {
}
}
+ private static class DictionaryServiceReference implements ServiceReference {
+ private final Dictionary dictionary;
+ private final String[] keys;
+
+ DictionaryServiceReference(Dictionary dictionary) {
+ if (dictionary == null) {
+ this.dictionary = null;
+ this.keys = new String[] {};
+ return;
+ }
+ this.dictionary = dictionary;
+ List keyList = new ArrayList(dictionary.size());
+ for (Enumeration e = dictionary.keys(); e.hasMoreElements();) {
+ Object k = e.nextElement();
+ if (k instanceof String) {
+ String key = (String) k;
+ for (Iterator i = keyList.iterator(); i.hasNext();) {
+ if (key.equalsIgnoreCase((String) i.next())) {
+ throw new IllegalArgumentException();
+ }
+ }
+ keyList.add(key);
+ }
+ }
+ this.keys = (String[]) keyList.toArray(new String[keyList.size()]);
+ }
+
+ public int compareTo(Object reference) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Bundle getBundle() {
+ return OSGiTestsActivator.getContext().getBundle();
+ }
+
+ public Object getProperty(String k) {
+ for (int i = 0, length = keys.length; i < length; i++) {
+ String key = keys[i];
+ if (key.equalsIgnoreCase(k)) {
+ return dictionary.get(key);
+ }
+ }
+ return null;
+ }
+
+ public String[] getPropertyKeys() {
+ return (String[]) keys.clone();
+ }
+
+ public Bundle[] getUsingBundles() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isAssignableTo(Bundle bundle, String className) {
+ throw new UnsupportedOperationException();
+ }
+ }
}
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/FilterImpl.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/FilterImpl.java
index 5f348691b..c495d2411 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/FilterImpl.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/FilterImpl.java
@@ -144,25 +144,35 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
/**
* Filter using a service's properties.
- * The Filter is executed using the referenced service's
- * properties.
+ * <p>
+ * The filter is executed using the keys and values of the referenced
+ * service's properties. The keys are case insensitively matched with
+ * the filter.
*
- * @param reference the reference to the service whose
- * properties are used in the match.
- * @return <code>true</code> if the service's properties match this filter;
- * <code>false</code> otherwise.
+ * @param reference The reference to the service whose properties are
+ * used in the match.
+ * @return <code>true</code> if the service's properties match this
+ * filter; <code>false</code> otherwise.
*/
public boolean match(ServiceReference reference) {
- return match0(((ServiceReferenceImpl) reference).getRegistration().getProperties());
+ if (reference instanceof ServiceReferenceImpl) {
+ return match0(((ServiceReferenceImpl) reference).getRegistration().getProperties());
+ }
+ return match0(new ServiceReferenceDictionary(reference));
}
/**
- * Filter using a Dictionary.
- * The Filter is executed using the Dictionary's keys.
+ * Filter using a <code>Dictionary</code> object. The Filter is executed
+ * using the <code>Dictionary</code> object's keys and values. The keys
+ * are case insensitively matched with the filter.
*
- * @param dictionary the dictionary whose keys are used in the match.
- * @return <code>true</code> if the Dictionary's keys match this filter;
- * <code>false</code> otherwise.
+ * @param dictionary The <code>Dictionary</code> object whose keys are
+ * used in the match.
+ * @return <code>true</code> if the <code>Dictionary</code> object's
+ * keys and values match this filter; <code>false</code>
+ * otherwise.
+ * @throws IllegalArgumentException If <code>dictionary</code> contains
+ * case variants of the same key name.
*/
public boolean match(Dictionary dictionary) {
if (dictionary != null) {
@@ -173,16 +183,16 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
/**
- * Filter with case sensitivity using a <tt>Dictionary</tt> object. The
- * Filter is executed using the <tt>Dictionary</tt> object's keys and
- * values. The keys are case sensitively matched with the filter.
- *
- * @param dictionary The <tt>Dictionary</tt> object whose keys are used in
- * the match.
- *
- * @return <tt>true</tt> if the <tt>Dictionary</tt> object's keys and
- * values match this filter; <tt>false</tt> otherwise.
+ * Filter with case sensitivity using a <code>Dictionary</code> object.
+ * The Filter is executed using the <code>Dictionary</code> object's
+ * keys and values. The keys are case sensitively matched with the
+ * filter.
*
+ * @param dictionary The <code>Dictionary</code> object whose keys are
+ * used in the match.
+ * @return <code>true</code> if the <code>Dictionary</code> object's
+ * keys and values match this filter; <code>false</code>
+ * otherwise.
* @since 1.3
*/
public boolean matchCase(Dictionary dictionary) {
@@ -190,11 +200,12 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
/**
- * Returns this Filter object's filter string.
- * The filter string is normalized by removing
- * whitespace which does not affect the meaning of the filter.
+ * Returns this <code>Filter</code> object's filter string.
+ * <p>
+ * The filter string is normalized by removing whitespace which does not
+ * affect the meaning of the filter.
*
- * @return filter string.
+ * @return Filter string.
*/
public String toString() {
String result = this.filterString;
@@ -207,9 +218,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
sb.append('&');
FilterImpl[] filters = (FilterImpl[]) value;
- int size = filters.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = filters.length; i < size; i++) {
sb.append(filters[i].toString());
}
@@ -220,9 +229,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
sb.append('|');
FilterImpl[] filters = (FilterImpl[]) value;
- int size = filters.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = filters.length; i < size; i++) {
sb.append(filters[i].toString());
}
@@ -242,9 +249,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
String[] substrings = (String[]) value;
- int size = substrings.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = substrings.length; i < size; i++) {
String substr = substrings[i];
if (substr == null) /* * */{
@@ -305,12 +310,13 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
/**
- * Compares this Filter object to another object.
+ * Compares this <code>Filter</code> object to another object.
*
- * @param obj the object to compare.
- * @return If the other object is a Filter object, then
- * returns <code>this.toString().equals(obj.toString())</code>,
- * otherwise <code>false</code>.
+ * @param obj The object to compare against this <code>Filter</code>
+ * object.
+ * @return If the other object is a <code>Filter</code> object, then
+ * returns <code>this.toString().equals(obj.toString()</code>;
+ * <code>false</code> otherwise.
*/
public boolean equals(Object obj) {
if (obj == this) {
@@ -325,16 +331,16 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
/**
- * Returns the hashCode for this Filter object.
+ * Returns the hashCode for this <code>Filter</code> object.
*
- * @return The hashCode of the filter string, <i>i.e.</i>
+ * @return The hashCode of the filter string; that is,
* <code>this.toString().hashCode()</code>.
*/
public int hashCode() {
return this.toString().hashCode();
}
- /* Protected fields and methods for the Filter implementation */
+ /* non public fields and methods for the Filter implementation */
/** filter operation */
private final int op;
@@ -379,9 +385,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
switch (op) {
case AND : {
FilterImpl[] filters = (FilterImpl[]) value;
- int size = filters.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = filters.length; i < size; i++) {
if (!filters[i].match0(properties)) {
return false;
}
@@ -392,9 +396,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
case OR : {
FilterImpl[] filters = (FilterImpl[]) value;
- int size = filters.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = filters.length; i < size; i++) {
if (filters[i].match0(properties)) {
return true;
}
@@ -540,9 +542,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
private boolean compare_Collection(int operation, Collection collection, Object value2) {
- Iterator iterator = collection.iterator();
-
- while (iterator.hasNext()) {
+ for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
if (compare(operation, iterator.next(), value2)) {
return true;
}
@@ -552,9 +552,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
private boolean compare_ObjectArray(int operation, Object[] array, Object value2) {
- int size = array.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = array.length; i < size; i++) {
if (compare(operation, array[i], value2)) {
return true;
}
@@ -566,10 +564,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
private boolean compare_PrimitiveArray(int operation, Class type, Object primarray, Object value2) {
if (Integer.TYPE.isAssignableFrom(type)) {
int[] array = (int[]) primarray;
-
- int size = array.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = array.length; i < size; i++) {
if (compare_Integer(operation, array[i], value2)) {
return true;
}
@@ -580,10 +575,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
if (Long.TYPE.isAssignableFrom(type)) {
long[] array = (long[]) primarray;
-
- int size = array.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = array.length; i < size; i++) {
if (compare_Long(operation, array[i], value2)) {
return true;
}
@@ -594,10 +586,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
if (Byte.TYPE.isAssignableFrom(type)) {
byte[] array = (byte[]) primarray;
-
- int size = array.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = array.length; i < size; i++) {
if (compare_Byte(operation, array[i], value2)) {
return true;
}
@@ -608,10 +597,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
if (Short.TYPE.isAssignableFrom(type)) {
short[] array = (short[]) primarray;
-
- int size = array.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = array.length; i < size; i++) {
if (compare_Short(operation, array[i], value2)) {
return true;
}
@@ -622,10 +608,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
if (Character.TYPE.isAssignableFrom(type)) {
char[] array = (char[]) primarray;
-
- int size = array.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = array.length; i < size; i++) {
if (compare_Character(operation, array[i], value2)) {
return true;
}
@@ -636,10 +619,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
if (Float.TYPE.isAssignableFrom(type)) {
float[] array = (float[]) primarray;
-
- int size = array.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = array.length; i < size; i++) {
if (compare_Float(operation, array[i], value2)) {
return true;
}
@@ -650,10 +630,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
if (Double.TYPE.isAssignableFrom(type)) {
double[] array = (double[]) primarray;
-
- int size = array.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = array.length; i < size; i++) {
if (compare_Double(operation, array[i], value2)) {
return true;
}
@@ -664,10 +641,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
if (Boolean.TYPE.isAssignableFrom(type)) {
boolean[] array = (boolean[]) primarray;
-
- int size = array.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = array.length; i < size; i++) {
if (compare_Boolean(operation, array[i], value2)) {
return true;
}
@@ -688,10 +662,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
String[] substrings = (String[]) value2;
int pos = 0;
-
- int size = substrings.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = substrings.length; i < size; i++) {
String substr = substrings[i];
if (i + 1 < size) /* if this is not that last substr */{
@@ -947,7 +918,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
if (Debug.DEBUG && Debug.DEBUG_FILTER) {
Debug.println("APPROX(" + charval + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- return Character.toLowerCase(charval) == Character.toLowerCase(charval2);
+ return (charval == charval2) || (Character.toUpperCase(charval) == Character.toUpperCase(charval2)) || (Character.toLowerCase(charval) == Character.toLowerCase(charval2));
}
case GREATER : {
if (Debug.DEBUG && Debug.DEBUG_FILTER) {
@@ -1212,11 +1183,8 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
private static String approxString(String input) {
boolean changed = false;
char[] output = input.toCharArray();
-
- int length = output.length;
-
int cursor = 0;
- for (int i = 0; i < length; i++) {
+ for (int i = 0, length = output.length; i < length; i++) {
char c = output[i];
if (Character.isWhitespace(c)) {
@@ -1311,7 +1279,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
if (pos != filterChars.length) {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_TRAILING_CHARACTERS, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_TRAILING_CHARACTERS, filterstring.substring(pos)), filterstring);
}
return filter;
}
@@ -1321,7 +1289,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
skipWhiteSpace();
if (filterChars[pos] != '(') {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_LEFTPAREN, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_LEFTPAREN, filterstring.substring(pos)), filterstring);
}
pos++;
@@ -1331,7 +1299,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
skipWhiteSpace();
if (filterChars[pos] != ')') {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_RIGHTPAREN, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_RIGHTPAREN, filterstring.substring(pos)), filterstring);
}
pos++;
@@ -1367,7 +1335,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
skipWhiteSpace();
if (filterChars[pos] != '(') {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_LEFTPAREN, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_LEFTPAREN, filterstring.substring(pos)), filterstring);
}
ArrayList operands = new ArrayList(10);
@@ -1386,7 +1354,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
skipWhiteSpace();
if (filterChars[pos] != '(') {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_LEFTPAREN, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_LEFTPAREN, filterstring.substring(pos)), filterstring);
}
ArrayList operands = new ArrayList(10);
@@ -1405,7 +1373,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
skipWhiteSpace();
if (filterChars[pos] != '(') {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_LEFTPAREN, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_LEFTPAREN, filterstring.substring(pos)), filterstring);
}
FilterImpl child = parse_filter(false);
@@ -1461,7 +1429,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
}
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_INVALID_OPERATOR, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_INVALID_OPERATOR, filterstring.substring(pos)), filterstring);
}
private String parse_attr() throws InvalidSyntaxException {
@@ -1485,7 +1453,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
int length = end - begin;
if (length == 0) {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_ATTR, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_ATTR, filterstring.substring(pos)), filterstring);
}
return new String(filterChars, begin, length);
@@ -1503,7 +1471,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
case '(' : {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_INVALID_VALUE, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_INVALID_VALUE, filterstring.substring(pos)), filterstring);
}
case '\\' : {
@@ -1521,7 +1489,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
if (sb.length() == 0) {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_VALUE, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_VALUE, filterstring.substring(pos)), filterstring);
}
return sb.toString();
@@ -1545,7 +1513,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
case '(' : {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_INVALID_VALUE, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_INVALID_VALUE, filterstring.substring(pos)), filterstring);
}
case '*' : {
@@ -1578,7 +1546,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
int size = operands.size();
if (size == 0) {
- throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_VALUE, String.valueOf(pos)), filterstring);
+ throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_VALUE, filterstring.substring(pos)), filterstring);
}
if (size == 1) {
@@ -1605,6 +1573,52 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{
}
}
+ /**
+ * This Dictionary is used for key lookup from a ServiceReference during
+ * filter evaluation. This Dictionary implementation only supports the get
+ * operation using a String key as no other operations are used by the
+ * Filter implementation.
+ *
+ */
+ private static class ServiceReferenceDictionary extends Dictionary {
+ private final ServiceReference reference;
+
+ ServiceReferenceDictionary(ServiceReference reference) {
+ this.reference = reference;
+ }
+
+ public Object get(Object key) {
+ if (reference == null) {
+ return null;
+ }
+ return reference.getProperty((String) key);
+ }
+
+ public boolean isEmpty() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Enumeration keys() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Enumeration elements() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object put(Object key, Object value) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object remove(Object key) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int size() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
private static class SetAccessibleAction implements PrivilegedAction {
private final AccessibleObject accessible;
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java
index cbf3ce978..2acbc1eb4 100755
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java
@@ -178,15 +178,16 @@ public class ServiceRegistry {
}
/* copy the array so that changes to the original will not affect us. */
- List copy = new ArrayList(clazzes.length);
+ List copy = new ArrayList(size);
// intern the strings and remove duplicates
- for (int i = 0; i < clazzes.length; i++) {
+ for (int i = 0; i < size; i++) {
String clazz = clazzes[i].intern();
if (!copy.contains(clazz)) {
copy.add(clazz);
}
}
- clazzes = (String[]) copy.toArray(new String[copy.size()]);
+ size = copy.size();
+ clazzes = (String[]) copy.toArray(new String[size]);
/* check for ServicePermissions. */
checkRegisterServicePermission(clazzes);
@@ -294,8 +295,7 @@ public class ServiceRegistry {
}
Filter filter = (filterstring == null) ? null : context.createFilter(filterstring);
List references = changeRegistrationsToReferences(lookupServiceRegistrations(clazz, filter));
- Iterator iter = references.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = references.iterator(); iter.hasNext();) {
ServiceReferenceImpl reference = (ServiceReferenceImpl) iter.next();
if (allservices || isAssignableTo(context, reference)) {
if (clazz == null) {
@@ -510,8 +510,7 @@ public class ServiceRegistry {
*/
public ServiceReferenceImpl[] getRegisteredServices(BundleContextImpl context) {
List references = changeRegistrationsToReferences(lookupServiceRegistrations(context));
- Iterator iter = references.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = references.iterator(); iter.hasNext();) {
ServiceReferenceImpl reference = (ServiceReferenceImpl) iter.next();
try { /* test for permission to the classes */
checkGetServicePermission(reference.getClasses());
@@ -565,8 +564,7 @@ public class ServiceRegistry {
}
references = changeRegistrationsToReferences(new ArrayList(servicesInUse.keySet()));
}
- Iterator iter = references.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = references.iterator(); iter.hasNext();) {
ServiceReferenceImpl reference = (ServiceReferenceImpl) iter.next();
try { /* test for permission to the classes */
checkGetServicePermission(reference.getClasses());
@@ -590,8 +588,7 @@ public class ServiceRegistry {
*/
public void unregisterServices(BundleContextImpl context) {
List registrations = lookupServiceRegistrations(context);
- Iterator iter = registrations.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = registrations.iterator(); iter.hasNext();) {
ServiceRegistrationImpl registration = (ServiceRegistrationImpl) iter.next();
try {
registration.unregister();
@@ -622,8 +619,7 @@ public class ServiceRegistry {
if (Debug.DEBUG && Debug.DEBUG_SERVICES) {
Debug.println("Releasing services"); //$NON-NLS-1$
}
- Iterator iter = registrations.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = registrations.iterator(); iter.hasNext();) {
ServiceRegistrationImpl registration = (ServiceRegistrationImpl) iter.next();
registration.releaseService(context);
}
@@ -735,8 +731,7 @@ public class ServiceRegistry {
Map /*<BundleContextImpl,Set<Map.Entry<Object,Object>>>*/listenerSnapshot;
synchronized (serviceEventListeners) {
listenerSnapshot = new HashMap(serviceEventListeners.size());
- Iterator iter = serviceEventListeners.entrySet().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = serviceEventListeners.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
BundleContextImpl context = (BundleContextImpl) entry.getKey();
Map listeners = (Map) entry.getValue();
@@ -759,8 +754,7 @@ public class ServiceRegistry {
/* deliver the event to the snapshot */
ListenerQueue queue = framework.newListenerQueue();
- Iterator iter = listenerSnapshot.entrySet().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = listenerSnapshot.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
EventDispatcher dispatcher = (BundleContextImpl) entry.getKey();
Set listeners = (Set) entry.getValue();
@@ -799,10 +793,8 @@ public class ServiceRegistry {
// Add the ServiceRegistrationImpl to the list of Services published by Class Name.
String[] clazzes = registration.getClasses();
- int size = clazzes.length;
int insertIndex;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = clazzes.length; i < size; i++) {
String clazz = clazzes[i];
List services = (List) publishedServicesByClass.get(clazz);
@@ -839,9 +831,7 @@ public class ServiceRegistry {
// Remove the ServiceRegistrationImpl from the list of Services published by Class Name.
String[] clazzes = serviceReg.getClasses();
- int size = clazzes.length;
-
- for (int i = 0; i < size; i++) {
+ for (int i = 0, size = clazzes.length; i < size; i++) {
String clazz = clazzes[i];
List services = (List) publishedServicesByClass.get(clazz);
services.remove(serviceReg);
@@ -880,8 +870,7 @@ public class ServiceRegistry {
return result;
}
- Iterator iter = result.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = result.iterator(); iter.hasNext();) {
ServiceRegistrationImpl registration = (ServiceRegistrationImpl) iter.next();
if (!filter.match(registration.getReferenceImpl())) {
iter.remove();
@@ -913,8 +902,7 @@ public class ServiceRegistry {
* @return result which has been changed to List<ServiceReferenceImpl>
*/
private static List changeRegistrationsToReferences(List result) {
- ListIterator iter = result.listIterator();
- while (iter.hasNext()) {
+ for (ListIterator iter = result.listIterator(); iter.hasNext();) {
ServiceRegistrationImpl registration = (ServiceRegistrationImpl) iter.next();
iter.set(registration.getReferenceImpl()); /* replace the registration with its reference */
}
@@ -931,8 +919,7 @@ public class ServiceRegistry {
if (sm == null) {
return;
}
- int len = names.length;
- for (int i = 0; i < len; i++) {
+ for (int i = 0, len = names.length; i < len; i++) {
sm.checkPermission(new ServicePermission(names[i], ServicePermission.REGISTER));
}
}
@@ -959,8 +946,7 @@ public class ServiceRegistry {
return;
}
SecurityException se = null;
- int len = names.length;
- for (int i = 0; i < len; i++) {
+ for (int i = 0, len = names.length; i < len; i++) {
try {
sm.checkPermission(new ServicePermission(names[i], ServicePermission.GET));
return;
@@ -982,8 +968,7 @@ public class ServiceRegistry {
ServiceReferenceImpl reference = (ServiceReferenceImpl) event.getServiceReference();
String[] names = reference.getClasses();
- int len = names.length;
- for (int i = 0; i < len; i++) {
+ for (int i = 0, len = names.length; i < len; i++) {
if (domain.implies(new ServicePermission(names[i], ServicePermission.GET))) {
return true;
}
@@ -1004,7 +989,7 @@ public class ServiceRegistry {
return serviceObject.getClass().getClassLoader();
}
});
- for (int i = 0; i < clazzes.length; i++) {
+ for (int i = 0, len = clazzes.length; i < len; i++) {
try {
Class serviceClazz = cl == null ? Class.forName(clazzes[i]) : cl.loadClass(clazzes[i]);
if (!serviceClazz.isInstance(serviceObject))
@@ -1022,7 +1007,7 @@ public class ServiceRegistry {
if (clazz.equals(serviceClazz.getName()))
return false;
Class[] interfaces = serviceClazz.getInterfaces();
- for (int i = 0; i < interfaces.length; i++)
+ for (int i = 0, len = interfaces.length; i < len; i++)
if (!extensiveCheckServiceClass(clazz, interfaces[i]))
return false;
Class superClazz = serviceClazz.getSuperclass();
@@ -1035,7 +1020,7 @@ public class ServiceRegistry {
static boolean isAssignableTo(BundleContextImpl context, ServiceReferenceImpl reference) {
Bundle bundle = context.getBundleImpl();
String[] clazzes = reference.getClasses();
- for (int i = 0; i < clazzes.length; i++)
+ for (int i = 0, len = clazzes.length; i < len; i++)
if (!reference.isAssignableTo(bundle, clazzes[i]))
return false;
return true;
@@ -1079,8 +1064,7 @@ public class ServiceRegistry {
// Since the list is already sorted, we don't need to sort the list to call the hooks
// in the proper order.
- Iterator iter = hooks.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = hooks.iterator(); iter.hasNext();) {
ServiceRegistrationImpl registration = (ServiceRegistrationImpl) iter.next();
Object findHook = registration.getService(systemBundleContext);
if (findHook == null) { // if the hook is null
@@ -1127,8 +1111,7 @@ public class ServiceRegistry {
// Since the list is already sorted, we don't need to sort the list to call the hooks
// in the proper order.
- Iterator iter = hooks.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = hooks.iterator(); iter.hasNext();) {
ServiceRegistrationImpl registration = (ServiceRegistrationImpl) iter.next();
Object publishHook = registration.getService(systemBundleContext);
if (publishHook == null) { // if the hook is null
@@ -1185,8 +1168,7 @@ public class ServiceRegistry {
Collection addedListeners = new ArrayList(initialCapacity);
synchronized (serviceEventListeners) {
- Iterator iter = serviceEventListeners.values().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = serviceEventListeners.values().iterator(); iter.hasNext();) {
Map listeners = (Map) iter.next();
if (!listeners.isEmpty()) {
addedListeners.addAll(listeners.values());
@@ -1254,8 +1236,7 @@ public class ServiceRegistry {
// Since the list is already sorted, we don't need to sort the list to call the hooks
// in the proper order.
- Iterator iter = hooks.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = hooks.iterator(); iter.hasNext();) {
ServiceRegistrationImpl registration = (ServiceRegistrationImpl) iter.next();
Object listenerHook = registration.getService(systemBundleContext);
if (listenerHook == null) { // if the hook is null
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/ExternalMessages.properties b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/ExternalMessages.properties
index dd128a752..c814fcebb 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/ExternalMessages.properties
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/core/ExternalMessages.properties
@@ -54,14 +54,14 @@ SERVICE_ALREADY_UNREGISTERED_EXCEPTION=The service has been unregistered
SERVICE_EMPTY_CLASS_LIST_EXCEPTION=The array of service names is empty
HEADER_DUPLICATE_KEY_EXCEPTION=The key \"{0}\" already exists in another case variation
FILTER_INVALID=The filter is invalid.
-FILTER_MISSING_LEFTPAREN=Missing ''('' at character {0}
-FILTER_MISSING_RIGHTPAREN=Missing '')'' at character {0}
-FILTER_TRAILING_CHARACTERS=Extraneous trailing characters at character {0}
+FILTER_MISSING_LEFTPAREN=Missing ''('' at \"{0}\"
+FILTER_MISSING_RIGHTPAREN=Missing '')'' at \"{0}\"
+FILTER_TRAILING_CHARACTERS=Extraneous trailing characters at \"{0}\"
FILTER_TERMINATED_ABRUBTLY=Filter ended abruptly
-FILTER_INVALID_OPERATOR=Invalid operator at character {0}
-FILTER_MISSING_ATTR=Missing attr at character {0}
-FILTER_MISSING_VALUE=Missing value at character {0}
-FILTER_INVALID_VALUE=Invalid value at character {0}
+FILTER_INVALID_OPERATOR=Invalid operator at \"{0}\"
+FILTER_MISSING_ATTR=Missing attr at \"{0}\"
+FILTER_MISSING_VALUE=Missing value at \"{0}\"
+FILTER_INVALID_VALUE=Invalid value at \"{0}\"
STARTLEVEL_EXCEPTION_INVALID_REQUESTED_STARTLEVEL=The requested start level of {0} is invalid. The value must be a positive integer.
STARTLEVEL_CANT_CHANGE_SYSTEMBUNDLE_STARTLEVEL=The System Bundle's start level can not be modified.

Back to the top