use of org.osgi.framework.Filter in project rt.equinox.framework by eclipse.
the class Storage method listEntryPaths.
/**
* Returns the names of resources available from a list of bundle files.
* No duplicate resource names are returned, each name is unique.
* @param bundleFiles the list of bundle files to search in
* @param path The path name in which to look.
* @param filePattern The file name pattern for selecting resource names in
* the specified path.
* @param options The options for listing resource names.
* @return a list of resource names. If no resources are found then
* the empty list is returned.
* @see BundleWiring#listResources(String, String, int)
*/
public static List<String> listEntryPaths(List<BundleFile> bundleFiles, String path, String filePattern, int options) {
// Use LinkedHashSet for optimized performance of contains() plus
// ordering guarantees.
LinkedHashSet<String> pathList = new LinkedHashSet<>();
Filter patternFilter = null;
Hashtable<String, String> patternProps = null;
if (filePattern != null) {
// Avoid pattern matching and use BundleFile.getEntry() if recursion was not requested.
if ((options & BundleWiring.FINDENTRIES_RECURSE) == 0 && filePattern.indexOf('*') == -1 && filePattern.indexOf('\\') == -1) {
if (path.length() == 0)
path = filePattern;
else
path += path.charAt(path.length() - 1) == '/' ? filePattern : '/' + filePattern;
for (BundleFile bundleFile : bundleFiles) {
if (bundleFile.getEntry(path) != null && !pathList.contains(path))
pathList.add(path);
}
return new ArrayList<>(pathList);
}
// For when the file pattern includes a wildcard.
try {
// create a file pattern filter with 'filename' as the key
// $NON-NLS-1$ //$NON-NLS-2$
patternFilter = FilterImpl.newInstance("(filename=" + sanitizeFilterInput(filePattern) + ")");
// create a single hashtable to be shared during the recursive search
patternProps = new Hashtable<>(2);
} catch (InvalidSyntaxException e) {
// eventPublisher.publishFrameworkEvent(FrameworkEvent.ERROR, b, e);
return new ArrayList<>(pathList);
}
}
// find the entry paths for the datas
for (BundleFile bundleFile : bundleFiles) {
listEntryPaths(bundleFile, path, patternFilter, patternProps, options, pathList);
}
return new ArrayList<>(pathList);
}
use of org.osgi.framework.Filter in project fabric8 by jboss-fuse.
the class OsgiUtils method waitForSerice.
public static void waitForSerice(Class type, String filter, long timeout) {
BundleContext bundleContext = getBundleContext();
ServiceTracker tracker = null;
try {
String flt;
if (filter != null) {
if (filter.startsWith("(")) {
flt = "(&(" + org.osgi.framework.Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
} else {
flt = "(&(" + org.osgi.framework.Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
}
} else {
flt = "(" + org.osgi.framework.Constants.OBJECTCLASS + "=" + type.getName() + ")";
}
Filter osgiFilter = FrameworkUtil.createFilter(flt);
tracker = new ServiceTracker(bundleContext, osgiFilter, null);
tracker.open(true);
if (tracker.waitForService(timeout) == null) {
throw new RuntimeException("Gave up waiting for service " + flt);
}
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException("Invalid filter", e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
tracker.close();
}
}
use of org.osgi.framework.Filter in project eclipse-integration-commons by spring-projects.
the class DescriptorMatcher method match.
@SuppressWarnings({ "unchecked", "rawtypes" })
public boolean match(Descriptor descriptor) {
if (version != null && descriptor.getRequires() != null) {
try {
VersionRange versionRange = new VersionRange(descriptor.getRequires());
if (!versionRange.isIncluded(version)) {
return false;
}
} catch (IllegalArgumentException e) {
// ignore
}
}
if (descriptor.getFilter() != null) {
try {
Filter filter = FrameworkUtil.createFilter(descriptor.getFilter());
// TODO e3.7 remove cast and use expected typesObject
return filter.match((Dictionary) environment);
} catch (IllegalArgumentException e) {
// ignore
} catch (InvalidSyntaxException e) {
// ignore
}
}
if (descriptor.isLocal()) {
File baseDirectory = installDirectory == null ? manager.getInstallDirectory() : installDirectory;
File directory = new File(baseDirectory, descriptor.getId() + "-" + descriptor.getVersion());
if (!directory.exists()) {
return false;
}
}
return true;
}
use of org.osgi.framework.Filter in project acs-aem-commons by Adobe-Consulting-Services.
the class CustomPollingImporterListServlet method activate.
@Activate
protected void activate(ComponentContext ctx) throws InvalidSyntaxException {
final BundleContext bundleContext = ctx.getBundleContext();
StringBuilder builder = new StringBuilder();
builder.append("(&(");
builder.append(Constants.OBJECTCLASS).append("=").append(Importer.SERVICE_NAME).append(")");
builder.append("(displayName=*))");
Filter filter = bundleContext.createFilter(builder.toString());
this.tracker = new ServiceTracker(bundleContext, filter, null);
this.tracker.open();
}
use of org.osgi.framework.Filter in project ecf by eclipse.
the class EventHandlerWrapper method handleEvent.
/**
* Dispatch event to handler. Perform final tests before actually calling
* the handler.
*
* @param event
* The event to dispatch
* @param perm
* The permission to be checked
*/
public void handleEvent(Event event, Permission perm) {
Bundle bundle = reference.getBundle();
// is service unregistered?
if (bundle == null) {
return;
}
// filter match
Filter eventFilter = getFilter();
if ((eventFilter != null) && !event.matches(eventFilter)) {
return;
}
// permission check
if ((perm != null) && (!bundle.hasPermission(perm))) {
return;
}
// get handler service
EventHandler handlerService = getHandler();
if (handlerService == null) {
return;
}
try {
handlerService.handleEvent(event);
} catch (Throwable t) {
// log/handle any Throwable thrown by the listener
log.log(LogService.LOG_ERROR, "Exception while dispatching event " + event + " to handler " + handlerService, t);
}
}
Aggregations