Java Code Examples for org.osgi.framework.Filter#matches()

The following examples show how to use org.osgi.framework.Filter#matches() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoordinationPermission.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Internal implies method. Used by the implies and the permission
 * collection implies methods.
 * 
 * @param requested The requested CoordinationPermission which has already
 *        be validated as a proper argument. The requested
 *        CoordinationPermission must not have a filter expression.
 * @param effective The effective actions with which to start.
 * @return {@code true} if the specified permission is implied by this
 *         object; {@code false} otherwise.
 */
boolean implies0(CoordinationPermission requested, int effective) {
	/* check actions first - much faster */
	effective |= action_mask;
	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());
}
 
Example 2
Source File: ResolveContextImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addToProvidersIfMatching(Resource res, List<Capability> providers, Requirement req) {
	String f = req.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
	Filter filter = null;
	if(f != null) {
	  try {
	    filter = bc.createFilter(f);
	  } catch (InvalidSyntaxException e) {
	    // TODO log filter failure, skip
	    System.err.println("Failed, " + f + ". " + e);
	    return;
	  }
	}
	for(Capability c : res.getCapabilities(req.getNamespace())) {
	  if(filter != null && !filter.matches(c.getAttributes())) {
	    continue;
	  }
	  providers.add(c);
	}
}
 
Example 3
Source File: FrameworkNodeImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
public Collection<ServiceReferenceDTO> getServiceReferences(String filter) throws InvalidSyntaxException {
	Filter f = context.createFilter(filter);
	List<ServiceReferenceDTO> filtered = new ArrayList<ServiceReferenceDTO>();
	for(ServiceReferenceDTO r : getServiceReferences()){
		if(f.matches(r.properties)){
			filtered.add(r);
		}
	}
	return filtered; 
}
 
Example 4
Source File: SubsystemPermission.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Internal implies method. Used by the implies and the permission
 * collection implies methods.
 * 
 * @param requested The requested SubsystemPermision which has already been
 *        validated as a proper argument. The requested SubsystemPermission
 *        must not have a filter expression.
 * @param effective The effective actions with which to start.
 * @return {@code true} if the specified permission is implied by this
 *         object; {@code false} otherwise.
 */
boolean implies0(SubsystemPermission requested, int effective) {
	/* check actions first - much faster */
	effective |= action_mask;
	final int desired = requested.action_mask;
	if ((effective & desired) != desired) {
		return false;
	}

	/* Get our filter */
	Filter f = filter;
	if (f == null) {
		// it's "*"
		return true;
	}
	/* is requested a wildcard filter? */
	if (requested.subsystem == null) {
		return false;
	}
	Map<String, Object> requestedProperties = requested.getProperties();
	if (requestedProperties == null) {
		/*
		 * If the requested properties are null, then we have detected a
		 * recursion getting the subsystem location. So we return true to
		 * permit the subsystem location request in the SubsystemPermission
		 * check up the stack to succeed.
		 */
		return true;
	}
	return f.matches(requestedProperties);
}
 
Example 5
Source File: FrameworkWiringImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public Collection<BundleCapability> findProviders(Requirement requirement) {
  final String namespace = requirement.getNamespace();
  final String filterStr = requirement.getDirectives().get("filter");
  Filter filter;
  if (filterStr != null) {
    try {
      filter = FrameworkUtil.createFilter(filterStr);
    } catch (InvalidSyntaxException ise) {
      final String msg = "Invalid filter directive '" + filterStr + "': " + ise;
      throw new IllegalArgumentException(msg, ise);
    }
  } else {
    filter = null;
  }
  HashSet<BundleCapability> res = new HashSet<BundleCapability>();
  for (BundleGeneration bg : fwCtx.bundles.getBundleGenerations(null)) {
    BundleRevisionImpl bri = bg.bundleRevision;
    if (bri != null) {
      for (BundleCapability bc : bri.getDeclaredCapabilities(namespace)) {
        if (null == filter || filter.matches(bc.getAttributes())) {
          res.add(bc);
        }
      }
    }
  }
  return res;
}
 
Example 6
Source File: RFC1960Filter.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
static List<Capability> filterWithIndex(final Requirement requirement,
		final String filterStr,
		final Concierge.CapabilityRegistry capabilityIndex)
				throws InvalidSyntaxException {
	final Set<String> values = new HashSet<String>();

	final String namespace = requirement.getNamespace();

	final Filter filter = fromString(filterStr);

	final int prefilterResult = prefilter(namespace, filter,
			capabilityIndex, INSUFFICIENT, false, values);

	final List<Capability> candidates;

	if (prefilterResult == REQUIRED) {
		if (values.size() != 1) {
			return Collections.emptyList();
		}
		return capabilityIndex.getByValue(namespace,
				values.iterator().next());
	} else if (prefilterResult == NECESSARY) {
		// FIXME: check
		if (values.size() != 1) {
			candidates = capabilityIndex.getAll(namespace);
		} else {
			candidates = capabilityIndex.getByKey(namespace,
					values.iterator().next());
		}
	} else {
		candidates = capabilityIndex.getAll(namespace);
	}

	if (candidates == null) {
		return Collections.emptyList();
	}

	final ArrayList<Capability> matches = new ArrayList<Capability>();

	for (final Capability cap : candidates) {
		if (filter.matches(cap.getAttributes()) && Concierge
				.matches0(namespace, requirement, cap, filterStr)) {
			matches.add(cap);
		}
	}

	return matches;
}
 
Example 7
Source File: LinkerManagement.java    From fuchsia with Apache License 2.0 2 votes vote down vote up
/**
 * Return true if the Declaration can be linked to the ImporterService.
 *
 * @param declaration          The Declaration
 * @param declarationBinderRef The ServiceReference<ImporterService> of the ImporterService
 * @return true if the Declaration can be linked to the ImporterService
 */
public boolean canBeLinked(D declaration, ServiceReference<S> declarationBinderRef) {
    // Evaluate the target filter of the ImporterService on the Declaration
    Filter filter = bindersManager.getTargetFilter(declarationBinderRef);
    return filter.matches(declaration.getMetadata());
}