org.osgi.framework.Filter#matches ( )源码实例Demo

下面列出了org.osgi.framework.Filter#matches ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: knopflerfish.org   文件: CoordinationPermission.java
/**
 * 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());
}
 
源代码2 项目: knopflerfish.org   文件: ResolveContextImpl.java
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);
	}
}
 
源代码3 项目: concierge   文件: FrameworkNodeImpl.java
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; 
}
 
源代码4 项目: knopflerfish.org   文件: SubsystemPermission.java
/**
 * 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);
}
 
源代码5 项目: knopflerfish.org   文件: FrameworkWiringImpl.java
@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;
}
 
源代码6 项目: concierge   文件: RFC1960Filter.java
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;
}
 
源代码7 项目: fuchsia   文件: LinkerManagement.java
/**
 * 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());
}