Search in sources :

Example 1 with TrackingStruct

use of org.osgi.service.indexer.osgi.AnalyzerTracker.TrackingStruct in project bnd by bndtools.

the class AnalyzerTracker method addingService.

@Override
public TrackingStruct addingService(ServiceReference<ResourceAnalyzer> reference) {
    TrackingStruct struct = new TrackingStruct();
    try {
        String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER);
        Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null;
        ResourceAnalyzer analyzer = context.getService(reference);
        if (analyzer == null)
            return null;
        struct = new TrackingStruct();
        struct.analyzer = analyzer;
        struct.filter = filter;
        struct.valid = true;
        indexer.addAnalyzer(analyzer, filter);
    } catch (InvalidSyntaxException e) {
        struct.valid = false;
        log.log(reference, LogService.LOG_ERROR, "Ignoring ResourceAnalyzer due to invalid filter expression", e);
    }
    return struct;
}
Also used : ResourceAnalyzer(org.osgi.service.indexer.ResourceAnalyzer) Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TrackingStruct(org.osgi.service.indexer.osgi.AnalyzerTracker.TrackingStruct)

Example 2 with TrackingStruct

use of org.osgi.service.indexer.osgi.AnalyzerTracker.TrackingStruct in project bnd by bndtools.

the class AnalyzerTracker method modifiedService.

@Override
public void modifiedService(ServiceReference<ResourceAnalyzer> reference, TrackingStruct struct) {
    if (struct.valid) {
        indexer.removeAnalyzer(struct.analyzer, struct.filter);
    }
    try {
        String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER);
        Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null;
        struct = new TrackingStruct();
        struct.filter = filter;
        struct.valid = true;
        indexer.addAnalyzer(struct.analyzer, filter);
    } catch (InvalidSyntaxException e) {
        struct.valid = false;
        log.log(reference, LogService.LOG_ERROR, "Ignoring ResourceAnalyzer due to invalid filter expression", e);
    }
}
Also used : Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TrackingStruct(org.osgi.service.indexer.osgi.AnalyzerTracker.TrackingStruct)

Aggregations

Filter (org.osgi.framework.Filter)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 TrackingStruct (org.osgi.service.indexer.osgi.AnalyzerTracker.TrackingStruct)2 ResourceAnalyzer (org.osgi.service.indexer.ResourceAnalyzer)1