Package org.osgi.framework

Examples of org.osgi.framework.Filter


    final int desired = requested.action_mask;
    if ((effective & desired) != desired) {
      return false;
    }
    /* if we have no filter */
    Filter f = filter;
    if (f == null) {
      // it's "*"
      return true;
    }
    return f.matchCase(requested.getProperties());
  }
View Full Code Here


    final int desired = requested.action_mask;
    if ((effective & desired) != desired) {
      return false;
    }
    /* Get filter */
    Filter f = filter;
    if (f == null) {
      // it's "*"
      return true;
    }
    return f.matches(requested.getProperties());
  }
View Full Code Here

                addBundle(bundle);
            }
        }

        this.bundleContext.addBundleListener(this);
        final Filter filter = this.bundleContext.createFilter("(&(adaptables=*)(adapters=*)(" + Constants.OBJECTCLASS + "=" + AdapterFactory.SERVICE_NAME + "))");
        this.adapterTracker = new ServiceTracker(this.bundleContext, filter, this);
        this.adapterTracker.open();
    }
View Full Code Here

    /**
     * Helper method to create a mock component context
     */
    protected ComponentContext createComponentContext() throws Exception {
        final BundleContext bundleCtx = this.context.mock(BundleContext.class);
        final Filter filter = this.context.mock(Filter.class);
        final ComponentContext ctx = this.context.mock(ComponentContext.class);
        this.context.checking(new Expectations() {{
            allowing(ctx).locateService(with(any(String.class)), with(any(ServiceReference.class)));
            will(returnValue(new MockAdapterFactory()));
            allowing(ctx).getBundleContext();
View Full Code Here

        /**
     * Helper method to create a mock component context
     */
    protected ComponentContext createMultipleAdaptersComponentContext(final ServiceReference firstServiceReference, final ServiceReference secondServiceReference) throws Exception {
        final BundleContext bundleCtx = this.context.mock(BundleContext.class);
        final Filter filter = this.context.mock(Filter.class);
        final ComponentContext ctx = this.context.mock(ComponentContext.class);
        this.context.checking(new Expectations() {{
            allowing(ctx).locateService(with(any(String.class)), with(firstServiceReference));
            will(returnValue(new FirstImplementationAdapterFactory()));
            allowing(ctx).locateService(with(any(String.class)), with(secondServiceReference));
View Full Code Here

    private ServiceRegistration beanFactoryReg;

    public OsgiBeanFactory(BundleContext bundleContext) {
        this.bundleContext = bundleContext;
        Filter filter = null;
        try {
            filter = bundleContext.createFilter("(jackrabbit.extension=true)");
        } catch (InvalidSyntaxException e) {
            //Should not happen
            throw new RuntimeException("Invalid filter", e);
View Full Code Here

    public Iterator<Tenant> getTenants() {
        return getTenants(null);
    }

    public Iterator<Tenant> getTenants(final String tenantFilter) {
        final Filter filter;
        if (tenantFilter != null && tenantFilter.length() > 0) {
            try {
                filter = FrameworkUtil.createFilter(tenantFilter);
            } catch (InvalidSyntaxException e) {
                throw new IllegalArgumentException(e.getMessage(), e);
            }
        } else {
            filter = null;
        }

        Iterator<Tenant> result = call(new ResourceResolverTask<Iterator<Tenant>>() {
            public Iterator<Tenant> call(ResourceResolver resolver) {
                Resource tenantRootRes = resolver.getResource(tenantRootPath);

                List<Tenant> tenantList = new ArrayList<Tenant>();
                Iterator<Resource> tenantResourceList = tenantRootRes.listChildren();
                while (tenantResourceList.hasNext()) {
                    Resource tenantRes = tenantResourceList.next();

                    if (filter == null || filter.matches(ResourceUtil.getValueMap(tenantRes))) {
                        TenantImpl tenant = new TenantImpl(tenantRes);
                        tenantList.add(tenant);
                    }
                }
                return tenantList.iterator();
View Full Code Here

                "initSQL=SELECT 1",
        });
        p.put("maxActive",70);
        config.update(p);

        Filter filter = context.createFilter("(&(objectclass=javax.sql.DataSource)(datasource.name=test))");
        ServiceTracker<DataSource, DataSource> st =
                new ServiceTracker<DataSource, DataSource>(context, filter, null);
        st.open();

        DataSource ds = st.waitForService(10000);
View Full Code Here

        {
            return (Wire [])m_wires.toArray(new Wire[m_wires.size()]);
    }
        else
        {
      Filter tempFilter = m_bundleContext.createFilter(filter);
      Iterator iter = m_wires.iterator();
      while (iter.hasNext())
            {
        WireImpl currentWire = (WireImpl) iter.next();
        if (tempFilter.match(currentWire.getProperties()))
                {
          if (res == null)
                    {
            res = new ArrayList();
                    }
View Full Code Here

      ServiceReference serRef = event.getServiceReference();
      Object obj = serRef.getProperty(UPnPEventListener.UPNP_FILTER);
      /* obtain interested devices for the listener */
      ServiceReference[] devicesRefs = null;
      if (obj != null) {
        Filter filter = (Filter) obj;
        String filtra = filter.toString();
        /*
         * Avoid to implement the notification for device
         * that are not been created by BaseDriver
         */
        String newfilter = "(&" + filtra +  IMPORT_FLTR + ")";
                //String newfilter = "(&" + filtra + "(!" + EXPORT_FLTR + ")" + ")";
        //System.out.println(newfilter);
        try {
          devicesRefs = context.getServiceReferences(UPnPDevice.class
              .getName(), newfilter);
        } catch (InvalidSyntaxException e) {
          e.printStackTrace();
        }

        if (devicesRefs != null) {/*
                       *
                       * only if there is a compatibile device
                       */
          Dictionary dic = new Hashtable();
          for (int i = 0; i < devicesRefs.length; i++) {
            UPnPDevice device = (UPnPDevice) context.getService(devicesRefs[i]);
            dic.put(UPnPDevice.ID, device.getDescriptions(null).get(UPnPDevice.UDN));
            dic.put(UPnPDevice.TYPE, device.getDescriptions(null).get(UPnPDevice.TYPE));
            UPnPService[] services = device.getServices();
            if (services != null) {
              for (int j = 0; j < services.length; j++) {
                dic.put(UPnPService.ID, services[j].getId());
                dic.put(UPnPService.TYPE, services[j].getType());
                //TODO add method boolean serviceEvented() so we can remove the below cycle
                UPnPStateVariable[] stateVars = services[j].getStateVariables();
                boolean hasEventedVars = false;
                for (int k = 0; k < stateVars.length && ! hasEventedVars; k++) {
                  hasEventedVars = stateVars[k].sendsEvents();
                  if (hasEventedVars) {
                    if(filter.match(dic)){
                      UPnPEventListener listener =
                                            (UPnPEventListener) context.getService(serRef);
                      FirstMessage msg = new FirstMessage(
                          ((UPnPServiceImpl) services[j]).getCyberService(),
                          listener);
                      subQueue.enqueue(msg);                     
                    }
                  }
                }
              }
            }
                        context.ungetService(devicesRefs[i]);
          }
        }
      } else {/* obj==null (interested in all devices) */
        try {
          String newfilter = "(!" + EXPORT_FLTR+ ")";
          devicesRefs = context.getServiceReferences(UPnPDevice.class.getName(), newfilter);
        } catch (InvalidSyntaxException e) {
          e.printStackTrace();
        }
        if (devicesRefs != null) {/*
                       *
                       * only if there is a device
                       */

          for (int i = 0; i < devicesRefs.length; i++) {
            UPnPDevice device = (UPnPDevice) context
                .getService(devicesRefs[i]);
            UPnPService[] services = device.getServices();
            if (services != null) {
              for (int j = 0; j < services.length; j++) {
                UPnPStateVariable[] stateVars = services[j]
                    .getStateVariables();
                boolean bool = false;               
                for (int k = 0; k < stateVars.length; k++) {
                  bool = stateVars[k].sendsEvents();
                  if (bool) {
                    break;
                  }
                }
                if (bool) {
                  UPnPEventListener listener =
                                        (UPnPEventListener) context.getService(serRef);
                  FirstMessage msg = new FirstMessage(
                      ((UPnPServiceImpl) services[j]).getCyberService(),
                      listener);
                  subQueue.enqueue(msg);
                }
              }
            }
                        context.ungetService(devicesRefs[i]);
          }
        }
      }

    } else if (event.getType() == ServiceEvent.MODIFIED) {
      Vector newServices = new Vector();
      ServiceReference serRef = event.getServiceReference();
      Filter filter = (Filter) serRef.getProperty(UPnPEventListener.UPNP_FILTER);
      UPnPEventListener listener = (UPnPEventListener) context.getService(serRef);
      ServiceReference[] devicesRefs = null;

      if (filter != null) {
        try {
          String filtra = filter.toString();
                    String newfilter = "(&" + filtra + "(!" + EXPORT_FLTR + ")" + ")";
          devicesRefs = context.getServiceReferences(UPnPDevice.class.getName(), newfilter);
        } catch (InvalidSyntaxException e) {
          e.printStackTrace();
        }
        if (devicesRefs != null) {/*
                       *
                       * only if there is a compatibile device
                       */
          Dictionary dic = new Hashtable();
          /*
           * look for the service that match
           */
          for (int i = 0; i < devicesRefs.length; i++) {
            UPnPDevice device = (UPnPDevice) context
                .getService(devicesRefs[i]);
            dic.put(UPnPDevice.ID, device.getDescriptions(null)
                .get(UPnPDevice.UDN));
            dic.put(UPnPDevice.TYPE, device.getDescriptions(null)
                .get(UPnPDevice.TYPE));
            UPnPService[] services = device.getServices();

            if (services != null) {
              for (int j = 0; j < services.length; j++) {
                dic.put(UPnPService.ID, services[j].getId());
                dic.put(UPnPService.TYPE, services[j].getType());

                UPnPStateVariable[] stateVars = services[j]
                    .getStateVariables();
                boolean hasEventedVars = false;
                for (int k = 0; k < stateVars.length; k++) {
                  hasEventedVars = stateVars[k].sendsEvents();
                  if (hasEventedVars) {
                    break;
                  }
                }
                if (!hasEventedVars) {
                  continue;
                }

                boolean bool = filter.match(dic);
                if (bool) {
                  newServices
                      .add(((UPnPServiceImpl) services[j])
                          .getCyberService());
                }
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.