Search in sources :

Example 56 with Filter

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
}
Also used : Dictionary(java.util.Dictionary) Filter(org.osgi.framework.Filter) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference)

Example 57 with Filter

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);
    }
}
Also used : Filter(org.osgi.framework.Filter) Properties(java.util.Properties)

Example 58 with Filter

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()]);
}
Also used : Role(org.osgi.service.useradmin.Role) DBCollection(com.mongodb.DBCollection) DBCursor(com.mongodb.DBCursor) Filter(org.osgi.framework.Filter) ArrayList(java.util.ArrayList)

Example 59 with Filter

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());
            }
        }
    }
}
Also used : Dictionary(java.util.Dictionary) Entry(java.util.Map.Entry) Filter(org.osgi.framework.Filter) Hashtable(java.util.Hashtable) Iterator(java.util.Iterator) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition)

Example 60 with Filter

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();
}
Also used : Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker)

Aggregations

Filter (org.osgi.framework.Filter)167 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)63 ServiceTracker (org.osgi.util.tracker.ServiceTracker)42 ArrayList (java.util.ArrayList)41 ServiceReference (org.osgi.framework.ServiceReference)36 BundleContext (org.osgi.framework.BundleContext)27 Hashtable (java.util.Hashtable)25 List (java.util.List)23 Bundle (org.osgi.framework.Bundle)21 Dictionary (java.util.Dictionary)20 HashMap (java.util.HashMap)17 Test (org.junit.Test)17 Map (java.util.Map)15 IOException (java.io.IOException)9 Iterator (java.util.Iterator)9 Properties (java.util.Properties)8 SharePolicy (org.apache.aries.subsystem.scope.SharePolicy)7 Configuration (org.osgi.service.cm.Configuration)7 URL (java.net.URL)6 Collection (java.util.Collection)6