use of org.osgi.framework.Filter in project aries by apache.
the class AbstractTest method addServiceExportPolicy.
protected void addServiceExportPolicy(Class<?> clazz, ScopeUpdate scopeUpdate) throws InvalidSyntaxException {
Filter filter = bundleContext.createFilter('(' + Constants.OBJECTCLASS + '=' + clazz.getName() + ')');
SharePolicy policy = new SharePolicy(SharePolicy.TYPE_EXPORT, "scope.share.service", filter);
Map<String, List<SharePolicy>> policyMap = scopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
List<SharePolicy> policies = policyMap.get("scope.share.service");
if (policies == null) {
policies = new ArrayList<SharePolicy>();
policyMap.put("scope.share.service", policies);
}
policies.add(policy);
}
use of org.osgi.framework.Filter in project aries by apache.
the class AbstractTest method addPackageImportPolicy.
protected void addPackageImportPolicy(String packageName, ScopeUpdate scopeUpdate) throws InvalidSyntaxException {
Filter filter = bundleContext.createFilter("(osgi.wiring.package=" + packageName + ')');
SharePolicy policy = new SharePolicy(SharePolicy.TYPE_IMPORT, "osgi.wiring.package", filter);
Map<String, List<SharePolicy>> policyMap = scopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
List<SharePolicy> policies = policyMap.get("osgi.wiring.package");
if (policies == null) {
policies = new ArrayList<SharePolicy>();
policyMap.put("osgi.wiring.package", policies);
}
policies.add(policy);
}
use of org.osgi.framework.Filter in project aries by apache.
the class RequirementImpl method isSatisfied.
@SuppressWarnings("unchecked")
public boolean isSatisfied(Capability cap) {
logger.debug(LOG_ENTRY, "isSatisfied", cap);
boolean result = false;
String name = getName();
if (name.equals(cap.getName())) {
String filterToCreate = getFilter();
try {
Filter f = FrameworkUtil.createFilter(FilterUtils.removeMandatoryFilterToken(filterToCreate));
Hashtable<String, Object> hash = new Hashtable<String, Object>();
Map<String, String> props = cap.getPropertiesAsMap();
if ((props != null) && (!!!props.isEmpty())) {
for (Map.Entry<String, String> propertyPair : props.entrySet()) {
hash.put(propertyPair.getKey(), propertyPair.getValue());
}
}
result = f.match(hash);
} catch (InvalidSyntaxException e) {
logger.error(e.getMessage());
}
}
logger.debug(LOG_EXIT, "isSatisfied", result);
return result;
}
use of org.osgi.framework.Filter in project aries by apache.
the class AriesRepositoryGenerator method getOsgiService.
private Object getOsgiService(BundleContext bc, String className) {
ServiceTracker tracker = null;
try {
String flt = "(" + Constants.OBJECTCLASS + "=" + className + ")";
Filter osgiFilter = FrameworkUtil.createFilter(flt);
tracker = new ServiceTracker(bc, osgiFilter, null);
tracker.open();
// add tracker to the list of trackers we close at tear down
srs.add(tracker);
Object x = tracker.waitForService(DEFAULT_TIMEOUT);
if (x == null) {
throw new RuntimeException("Gave up waiting for service " + flt);
}
return x;
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException("Invalid filter", e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
use of org.osgi.framework.Filter in project aries by apache.
the class ConfigurationTests method testNamedConfiguration.
@SuppressWarnings({ "unchecked", "serial" })
public void testNamedConfiguration() throws Exception {
Bundle tb3Bundle = installBundle("tb3.jar");
Configuration configurationA = null, configurationB = null;
try {
configurationA = configurationAdmin.getConfiguration("configA", "?");
Dictionary<String, Object> properties = new Hashtable<>();
properties.put("ports", new int[] { 12, 4567 });
configurationA.update(properties);
configurationB = configurationAdmin.getConfiguration("configB", "?");
properties = new Hashtable<>();
properties.put("color", "green");
properties.put("ports", new int[] { 80 });
configurationB.update(properties);
Filter filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + tb3Bundle.getBundleId() + ")(" + CdiConstants.CDI_CONTAINER_STATE + "=CREATED))");
ServiceTracker<CdiContainer, CdiContainer> st = new ServiceTracker<>(bundleContext, filter, null);
st.open();
CdiContainer container = st.waitForService(timeout);
assertNotNull(container);
int t = st.getTrackingCount();
BeanManager beanManager = container.getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans("configB");
assertNotNull(beans);
Bean<? extends Object> bean = beanManager.resolve(beans);
CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
Map<String, Object> config = (Map<String, Object>) beanManager.getReference(bean, new TypeLiteral<Map<String, Object>>() {
}.getType(), ctx);
assertNotNull(config);
assertEquals("green", config.get("color"));
assertArrayEquals(new int[] { 80 }, (int[]) config.get("ports"));
configurationA.delete();
while (t == st.getTrackingCount()) {
Thread.sleep(10);
}
assertTrue(st.isEmpty());
st.close();
filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + tb3Bundle.getBundleId() + ")(" + CdiConstants.CDI_CONTAINER_STATE + "=" + CdiEvent.Type.WAITING_FOR_CONFIGURATIONS + "))");
st = new ServiceTracker<>(bundleContext, filter, null);
st.open();
assertFalse(st.isEmpty());
} finally {
if (configurationB != null) {
try {
configurationB.delete();
} catch (Exception e) {
// ignore
}
}
tb3Bundle.uninstall();
}
}
Aggregations