Package org.osgi.framework

Examples of org.osgi.framework.Filter


            EasyMock.expect(b0.getState()).andReturn(Bundle.ACTIVE).anyTimes();
            EasyMock.expect(b0.findEntries("OSGI-INF/remote-service", "*.xml", false)).
                    andReturn(rsAEnum).anyTimes();
           
            BundleContext bc = control.createMock(BundleContext.class);
            Filter mockFilter = control.createMock(Filter.class);
            ServiceReference sr = control.createMock(ServiceReference.class);
            TestDiscoveredServiceTracker dst = new TestDiscoveredServiceTracker();
   
            EasyMock.expect(bc.getBundles()).andReturn(new Bundle[] {b0}).anyTimes();
            EasyMock.expect(bc.createFilter("(blah <= 5)")).andReturn(mockFilter).anyTimes();
            EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.FILTER_MATCH_CRITERIA)).
                    andReturn(Collections.singleton("(blah <= 5)")).anyTimes();
           
            EasyMock.expect(bc.getService(sr)).andReturn(dst).anyTimes();
           
            // set up the mock filter behaviour
            Dictionary<String, Object> d1 = new Hashtable<String, Object>();
            d1.put("blah", "5");
            EasyMock.expect(mockFilter.match(d1)).andReturn(true).anyTimes();
            Dictionary<String, Object> d2 = new Hashtable<String, Object>();
            d2.put("blah", "3");
            d2.put("boo", "hello");
            EasyMock.expect(mockFilter.match(d2)).andReturn(true).anyTimes();
           
            control.replay();
   
            // create the local discovery service
            LocalDiscoveryService lds = new LocalDiscoveryService(bc);
View Full Code Here


            Iterator matchedFilters =
                notification.getFilters().iterator();
            while (matchedFilters.hasNext() && !matched) {
                String filterString = (String)matchedFilters.next();
                try {
                    Filter filter = context.createFilter(filterString);
                    matched =
                        filter.match(getProperties(notification, currInterface));
                } catch (InvalidSyntaxException ise) {
                    LOG.warning("invalid filter syntax: " + filterString);
                }
                if (matched) {
                    matches.add(currInterface);
View Full Code Here

        return null;
    }

    private boolean filterMatches(String filterValue,
                                  ServiceEndpointDescription sd) {
        Filter filter = createFilter(filterValue);
        return filter != null
               ? filter.match(getServiceProperties(null, sd))
               : false;
    }
View Full Code Here

        EasyMock.expectLastCall();

        if (matchingInterfaces.size() == 0 && matchingFilters.size() > 0) {
            Iterator filters = matchingFilters.iterator();
            while (filters.hasNext()) {
                Filter f = control.createMock(Filter.class);
                dswContext.addFilter((String)filters.next(), f);
                f.match(EasyMock.isA(Dictionary.class));
                EasyMock.expectLastCall().andReturn(true);
            }
        }

        control.replay();
View Full Code Here

        try {
            ServiceReference sr = EasyMock.createMock(ServiceReference.class);
            EasyMock.expect(sr.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE))
                .andReturn("Filterstring");

            Filter f = EasyMock.createNiceMock(Filter.class);
           
            BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
            EasyMock.expect(bc.createFilter((String)EasyMock.anyObject())).andReturn(f);

            EasyMock.replay(sr);
View Full Code Here

           
            ServiceReference sr = EasyMock.createMock(ServiceReference.class);
            EasyMock.expect(sr.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE))
                .andReturn(filterStrings);

            Filter f = EasyMock.createNiceMock(Filter.class);
           
           
            BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
            EasyMock.expect(bc.createFilter((String)EasyMock.anyObject())).andReturn(f).times(filterStrings.length);
View Full Code Here

           
            ServiceReference sr = EasyMock.createMock(ServiceReference.class);
            EasyMock.expect(sr.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE))
                .andReturn(collection);

            Filter f = EasyMock.createNiceMock(Filter.class);
           
           
            BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
            EasyMock.expect(bc.createFilter((String)EasyMock.anyObject())).andReturn(f).times(collection.size());
View Full Code Here

        EasyMock.expect(bc.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("MyUUID").atLeastOnce();
        EasyMock.replay(bc);
       
        filter = Utils.extendFilter(filter, bc);
       
        Filter f = FrameworkUtil.createFilter(filter);
       
        Dictionary m = new Hashtable();
        m.put("a", "b");
       
        assertTrue(filter+" filter must match as uuid is missing",f.match(m));     
        m.put(RemoteConstants.ENDPOINT_FRAMEWORK_UUID , "MyUUID");
        assertFalse(filter+" filter must NOT match as uuid is the local one",f.match(m));
    }
View Full Code Here

public class MyActivator implements BundleActivator {   
    private ServiceTracker startTracker, tracker;

    public void start(final BundleContext bc) throws Exception {
        Filter filter = bc.createFilter("(&(objectClass=java.lang.Object)(testName=test1))");
        tracker = new MyServiceTracker(bc);
       
        // The start tracker waits until a service from the test class is set before the
        // 'MyServiceTracker' is activated.
        startTracker = new StartServiceTracker(bc, filter, tracker);
View Full Code Here

    public Role[] getRoles(String filter) throws InvalidSyntaxException {
        if (filter == null) {
            return m_roles.values().toArray(new Role[m_roles.size()]);
        }

        Filter f = m_context.createFilter(filter);

        List<Role> result = new ArrayList<Role>();
        for (RoleImpl impl : m_roles.values()) {
            if (f.match(impl.getProperties())) {
                result.add(impl);
            }
        }

        // The spec requires us to return null when we have no results.
View Full Code Here

TOP

Related Classes of org.osgi.framework.Filter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.