00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package org.knopflerfish.framework;
00036
00037 import java.util.Dictionary;
00038 import java.util.Hashtable;
00039
00040 import org.osgi.framework.*;
00041
00042 public class FilterImpl implements Filter {
00043
00044 private String filter = null;
00045 private LDAPExpr ldap;
00046
00047
00048 public FilterImpl(String filter) throws InvalidSyntaxException {
00049 ldap = new LDAPExpr(filter);
00050 }
00051
00052
00053 public boolean match(ServiceReference reference) {
00054 if(reference instanceof ServiceReferenceImpl) {
00055
00056 return ldap.evaluate(((ServiceReferenceImpl)reference).getProperties(), false);
00057 } else {
00058
00059
00060 Hashtable props = new Hashtable();
00061 String[] keys = reference.getPropertyKeys();
00062 for(int i = 0; i < keys.length; i++) {
00063 props.put(keys[i], reference.getProperty(keys[i]));
00064 }
00065 return ldap.evaluate(props, false);
00066 }
00067 }
00068
00069
00070 public boolean match(Dictionary dictionary) {
00071 return ldap.evaluate(new PropertiesDictionary(dictionary), false);
00072 }
00073
00074
00075 public boolean matchCase(Dictionary dictionary) {
00076 return ldap.evaluate(new PropertiesDictionary(dictionary), true);
00077 }
00078
00079
00080 public String toString() {
00081 if (filter == null) {
00082 filter = ldap.toString();
00083 }
00084 return filter;
00085 }
00086
00087
00088 public boolean equals(Object obj) {
00089 return toString().equals(obj.toString());
00090 }
00091
00092
00093 public int hashCode() {
00094 return toString().hashCode();
00095 }
00096 }