use of org.osgi.framework.InvalidSyntaxException in project aries by apache.
the class RepositoryServiceRepository method findProviders.
@SuppressWarnings("unchecked")
public Collection<Capability> findProviders(Requirement requirement) {
Set<Capability> result = new HashSet<Capability>();
ServiceReference<?>[] references;
try {
references = context.getAllServiceReferences("org.osgi.service.repository.Repository", null);
if (references == null)
return result;
} catch (InvalidSyntaxException e) {
throw new IllegalStateException(e);
}
for (ServiceReference<?> reference : references) {
Object repository = context.getService(reference);
if (repository == null)
continue;
try {
// Reflection is used here to allow the service to work with a mixture of
// Repository services implementing different versions of the API.
Class<?> clazz = repository.getClass();
Class<?> repoInterface = null;
while (clazz != null && repoInterface == null) {
for (Class<?> intf : clazz.getInterfaces()) {
if (Repository.class.getName().equals(intf.getName())) {
// Compare interfaces by name so that we can work with different versions of the
// interface.
repoInterface = intf;
break;
}
}
clazz = clazz.getSuperclass();
}
if (repoInterface == null) {
continue;
}
Map<Requirement, Collection<Capability>> map;
try {
Method method = repoInterface.getMethod("findProviders", Collection.class);
map = (Map<Requirement, Collection<Capability>>) method.invoke(repository, Collections.singleton(requirement));
} catch (Exception e) {
throw new SubsystemException(e);
}
Collection<Capability> capabilities = map.get(requirement);
if (capabilities == null)
continue;
result.addAll(capabilities);
} finally {
context.ungetService(reference);
}
}
return result;
}
use of org.osgi.framework.InvalidSyntaxException in project aries by apache.
the class SubsystemResource method getRegion.
public synchronized Region getRegion() throws BundleException, IOException, InvalidSyntaxException, URISyntaxException {
if (region == null) {
region = createRegion(getId());
Coordination coordination = Activator.getInstance().getCoordinator().peek();
coordination.addParticipant(new Participant() {
@Override
public void ended(Coordination arg0) throws Exception {
// Nothing.
}
@Override
public void failed(Coordination arg0) throws Exception {
if (isScoped())
region.getRegionDigraph().removeRegion(region);
}
});
if (!isApplication()) {
setImportIsolationPolicy();
}
}
return region;
}
use of org.osgi.framework.InvalidSyntaxException in project aries by apache.
the class RichBundleContext method getService.
public <T> T getService(Class<T> type, String filter, long timeout) {
ServiceTracker tracker = null;
try {
String flt;
if (filter != null) {
if (filter.startsWith("(")) {
flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
} else {
flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
}
} else {
flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
}
Filter osgiFilter = FrameworkUtil.createFilter(flt);
tracker = new ServiceTracker(delegate, osgiFilter, null);
tracker.open();
Object svc = type.cast(tracker.waitForService(timeout));
if (svc == null) {
System.out.println("Could not obtain a service in time, service-ref=" + tracker.getServiceReference() + ", time=" + System.currentTimeMillis());
throw new RuntimeException("Gave up waiting for service " + flt);
}
return type.cast(svc);
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException("Invalid filter", e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
use of org.osgi.framework.InvalidSyntaxException in project aries by apache.
the class AbstractJPAManagedServiceFactory method getConfigurationDrivenResource.
@Override
protected LifecycleAware getConfigurationDrivenResource(BundleContext context, String pid, Map<String, Object> properties) throws Exception {
Properties jdbcProps = getJdbcProps(pid, properties);
Map<String, Object> jpaProps = getJPAProps(pid, properties);
try {
LifecycleAware worker;
if (properties.containsKey(OSGI_JDBC_DRIVER_CLASS) || properties.containsKey(DSF_TARGET_FILTER)) {
worker = dataSourceTracking(context, pid, properties, jdbcProps, jpaProps);
} else {
if (!jdbcProps.isEmpty()) {
LOG.warn("The configuration {} contains raw JDBC configuration, but no osgi.jdbc.driver.class or aries.dsf.target.filter properties. No DataSourceFactory will be used byt this bundle, so the JPA provider must be able to directly create the datasource, and these configuration properties will likely be ignored. {}", pid, jdbcProps.stringPropertyNames());
}
worker = emfTracking(context, pid, properties, jpaProps);
}
return worker;
} catch (InvalidSyntaxException e) {
LOG.error("The configuration {} contained an invalid target filter {}", pid, e.getFilter());
throw new ConfigurationException(DSF_TARGET_FILTER, "The target filter was invalid", e);
}
}
use of org.osgi.framework.InvalidSyntaxException in project aries by apache.
the class SingleServiceTracker method findMatchingReference.
private void findMatchingReference(ServiceReference original) {
boolean clear = true;
ServiceReference ref;
if (isCustomFilter) {
try {
ServiceReference[] refs = ctx.getServiceReferences(className, filterString);
if (refs == null || refs.length == 0) {
ref = null;
} else {
ref = refs[0];
}
} catch (InvalidSyntaxException e) {
//This can't happen, we'd have blown up in the constructor
ref = null;
}
} else {
ref = ctx.getServiceReference(className);
}
if (ref != null) {
T service = (T) ctx.getService(ref);
if (service != null) {
clear = false;
// We do the unget out of the lock so we don't exit this class while holding a lock.
if (!!!update(original, ref, service)) {
ctx.ungetService(ref);
}
}
} else if (original == null) {
clear = false;
}
if (clear) {
update(original, null, null);
}
}
Aggregations