use of org.osgi.framework.Filter in project felix by apache.
the class UPnPEventNotifier method setupUPnPListenerWatcher.
/**
* @param deviceId
*/
private void setupUPnPListenerWatcher() {
Dictionary dict = device.getDescriptions(null);
this.deviceId = (String) dict.get(UPnPDevice.ID);
this.serviceId = service.getId();
UPnPTargetListener = new Properties();
UPnPTargetListener.put(UPnPDevice.ID, deviceId);
UPnPTargetListener.put(UPnPService.ID, serviceId);
UPnPTargetListener.put(UPnPDevice.TYPE, dict.get(UPnPDevice.TYPE));
UPnPTargetListener.put(UPnPService.TYPE, service.getType());
String ANY_UPnPEventListener = "(" + Constants.OBJECTCLASS + "=" + UPnPEventListener.class.getName() + ")";
synchronized (LOCK) {
try {
String filter = ANY_UPnPEventListener;
context.addServiceListener(this, filter);
} catch (Exception ex) {
System.out.println(ex);
}
ServiceReference[] listeners = null;
try {
listeners = context.getServiceReferences(UPnPEventListener.class.getName(), null);
if (listeners != null) {
for (int i = 0; i < listeners.length; i++) {
ServiceReference sr = listeners[i];
Filter filter = (Filter) sr.getProperty(UPnPEventListener.UPNP_FILTER);
if (filter == null)
upnpListeners.add(sr);
else {
if (filter.match(UPnPTargetListener))
addNewListener(sr);
}
}
}
} catch (Exception ex) {
System.out.println(ex);
}
Properties status = getCurrentStatus();
if (!status.isEmpty())
doNotify(status);
}
// end LOCK
}
use of org.osgi.framework.Filter in project felix by apache.
the class UPnPSubscriber method subscribe.
public void subscribe(String deviceType, String serviceType) {
String keys = "(&(" + UPnPDevice.TYPE + "=" + deviceType + ")(" + UPnPService.TYPE + "=" + serviceType + "))";
try {
Filter filter = context.createFilter(keys);
Properties props = new Properties();
props.put(UPnPEventListener.UPNP_FILTER, filter);
registration = context.registerService(UPnPEventListener.class.getName(), listener, props);
} catch (Exception ex) {
System.out.println(ex);
}
}
use of org.osgi.framework.Filter in project felix by apache.
the class MongoDBStore method getRoles.
@Override
public Role[] getRoles(String filterValue) throws InvalidSyntaxException, MongoException {
List<Role> roles = new ArrayList<Role>();
Filter filter = null;
if (filterValue != null) {
filter = FrameworkUtil.createFilter(filterValue);
}
DBCollection coll = getCollection();
DBCursor cursor = coll.find();
try {
while (cursor.hasNext()) {
// Hmm, there might be a more clever way of doing this...
Role role = m_helper.deserialize(cursor.next());
if ((filter == null) || filter.match(role.getProperties())) {
roles.add(role);
}
}
} finally {
cursor.close();
}
return roles.toArray(new Role[roles.size()]);
}
use of org.osgi.framework.Filter in project felix by apache.
the class ConfigAdminSupport method addMetaTypeNames.
private void addMetaTypeNames(final Map pidMap, final Map ocdCollection, final String filterSpec, final String type) {
Filter filter = null;
if (filterSpec != null) {
try {
filter = getBundleContext().createFilter(filterSpec);
} catch (InvalidSyntaxException not_expected) {
/* filter is correct */
}
}
for (Iterator ei = ocdCollection.entrySet().iterator(); ei.hasNext(); ) {
Entry ociEntry = (Entry) ei.next();
final String pid = (String) ociEntry.getKey();
final ObjectClassDefinition ocd = (ObjectClassDefinition) ociEntry.getValue();
if (filter == null) {
pidMap.put(pid, ocd.getName());
} else {
final Dictionary props = new Hashtable();
props.put(type, pid);
if (filter.match(props)) {
pidMap.put(pid, ocd.getName());
}
}
}
}
use of org.osgi.framework.Filter in project felix by apache.
the class Activator method start.
/**
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public final void start(BundleContext context) throws Exception {
this.context = context;
Filter filter = context.createFilter(// $NON-NLS-1$
"(|" + '(' + OBJECTCLASS + // $NON-NLS-1$
"=org.osgi.service.obr.RepositoryAdmin)" + '(' + OBJECTCLASS + // $NON-NLS-1$
"=org.apache.felix.bundlerepository.RepositoryAdmin)" + ')');
this.tracker = new ServiceTracker(context, filter, this);
this.tracker.open();
}
Aggregations