Search in sources :

Example 96 with Filter

use of org.osgi.framework.Filter in project aries by apache.

the class DeploymentMetadataImpl method getFilters.

private Collection<Filter> getFilters(String filterString) throws InvalidAttributeException {
    Collection<Filter> filters = new ArrayList<Filter>();
    List<String> fs = ManifestProcessor.split(filterString, ",");
    if ((fs != null) && (!!!fs.isEmpty())) {
        for (String filter : fs) {
            try {
                filters.add(FrameworkUtil.createFilter(FilterUtils.removeMandatoryFilterToken(filter)));
            } catch (InvalidSyntaxException ise) {
                InvalidAttributeException iae = new InvalidAttributeException(ise);
                throw iae;
            }
        }
    }
    return filters;
}
Also used : InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) Filter(org.osgi.framework.Filter) ArrayList(java.util.ArrayList) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Example 97 with Filter

use of org.osgi.framework.Filter in project aries by apache.

the class DeploymentMetadataImpl method convertFiltersToString.

private String convertFiltersToString(Collection<Filter> contents, String separator) {
    StringBuilder newContent = new StringBuilder();
    if ((contents != null) && (!!!contents.isEmpty())) {
        boolean beginning = true;
        for (Filter content : contents) {
            if (beginning)
                newContent.append(separator);
            newContent.append(content.toString());
            beginning = false;
        }
    }
    return newContent.toString();
}
Also used : Filter(org.osgi.framework.Filter)

Example 98 with Filter

use of org.osgi.framework.Filter in project aries by apache.

the class OSGiImpl method buildFilter.

static Filter buildFilter(BundleContext bundleContext, String filterString, Class<?> clazz) {
    Filter filter;
    String string = buildFilterString(filterString, clazz);
    try {
        filter = bundleContext.createFilter(string);
    } catch (InvalidSyntaxException e) {
        throw new RuntimeException(e);
    }
    return filter;
}
Also used : Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Example 99 with Filter

use of org.osgi.framework.Filter in project aries by apache.

the class ConsumerHeaderProcessor method findRequirement.

private static GenericMetadata findRequirement(List<GenericMetadata> requirements, String namespace, String type) throws InvalidSyntaxException {
    Dictionary<String, String> nsAttr = new Hashtable<String, String>();
    nsAttr.put(namespace, type);
    for (GenericMetadata req : requirements) {
        if (namespace.equals(req.getNamespace())) {
            String filterString = req.getDirectives().get(SpiFlyConstants.FILTER_DIRECTIVE);
            if (filterString != null) {
                Filter filter = FrameworkUtil.createFilter(filterString);
                if (filter.match(nsAttr)) {
                    return req;
                }
            }
        }
    }
    return null;
}
Also used : GenericMetadata(org.apache.aries.util.manifest.ManifestHeaderProcessor.GenericMetadata) Filter(org.osgi.framework.Filter) Hashtable(java.util.Hashtable)

Example 100 with Filter

use of org.osgi.framework.Filter in project aries by apache.

the class SubsystemPermissionCollection method implies0.

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

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