use of org.osgi.framework.Bundle in project karaf by apache.
the class Converters method convertBundle.
private Object convertBundle(Object in) {
String s = in.toString();
try {
long id = Long.parseLong(s);
return context.getBundle(id);
} catch (NumberFormatException nfe) {
// Ignore
}
Bundle[] bundles = context.getBundles();
for (Bundle b : bundles) {
if (b.getLocation().equals(s)) {
return b;
}
if (b.getSymbolicName().equals(s)) {
return b;
}
}
return null;
}
use of org.osgi.framework.Bundle in project sling by apache.
the class CommonResourceResolverFactoryImpl method getServiceUserAuthenticationInfo.
@Override
public Map<String, Object> getServiceUserAuthenticationInfo(final String subServiceName) throws LoginException {
// get an administrative resource resolver
// Ensure a mapped user name: If no user is defined for a bundle
// acting as a service, the user may be null. We can decide whether
// this should yield guest access or no access at all. For now
// no access is granted if there is no service user defined for
// the bundle.
final Bundle bundle = this.activator.getBundleContext().getBundle();
final String userName = this.activator.getServiceUserMapper().getServiceUserID(bundle, subServiceName);
if (userName == null) {
throw new LoginException("Cannot derive user name for bundle " + bundle + " and sub service " + subServiceName);
}
final Map<String, Object> authenticationInfo = new HashMap<>();
// ensure proper user name and service bundle
authenticationInfo.put(ResourceResolverFactory.SUBSERVICE, subServiceName);
authenticationInfo.put(ResourceResolverFactory.USER, userName);
authenticationInfo.put(ResourceProvider.AUTH_SERVICE_BUNDLE, bundle);
return authenticationInfo;
}
use of org.osgi.framework.Bundle in project sling by apache.
the class ResourceResolverControl method getResourceTypeResourceResolver.
private ResourceResolver getResourceTypeResourceResolver(final ResourceResolverFactory factory, final ResourceResolver resolver) {
if (this.isAdmin) {
return resolver;
} else {
if (this.resourceTypeResourceResolver == null) {
try {
// make sure we're getting the resourceTypeResourceResolver on behalf of
// the resourceresolver bundle
final Bundle bundle = FrameworkUtil.getBundle(ResourceResolverControl.class);
final Map<String, Object> authenticationInfo = new HashMap<>();
authenticationInfo.put(ResourceProvider.AUTH_SERVICE_BUNDLE, bundle);
authenticationInfo.put(ResourceResolverFactory.SUBSERVICE, "hierarchy");
this.resourceTypeResourceResolver = factory.getServiceResourceResolver(authenticationInfo);
} catch (final LoginException e) {
throw new IllegalStateException("Failed to create resource-type ResourceResolver", e);
}
}
return this.resourceTypeResourceResolver;
}
}
use of org.osgi.framework.Bundle in project sling by apache.
the class ScriptEngineManagerFactory method refreshScriptEngineManager.
/**
* Refresh the script engine manager.
*/
private void refreshScriptEngineManager() {
// create (empty) script engine manager
final ClassLoader loader = getClass().getClassLoader();
final SlingScriptEngineManager tmp = new SlingScriptEngineManager(loader);
// register script engines from bundles
synchronized (this.engineSpiBundles) {
for (final Bundle bundle : this.engineSpiBundles) {
registerFactories(tmp, bundle);
}
}
// register script engines from registered services
synchronized (this.engineSpiServices) {
for (final Map.Entry<ScriptEngineFactory, Map<Object, Object>> factory : this.engineSpiServices.entrySet()) {
registerFactory(tmp, factory.getKey(), factory.getValue());
}
}
scriptEngineManager.setDelegatee(tmp);
final List<ScriptEngineFactory> factories = tmp.getEngineFactories();
for (final ScriptEngineFactory factory : factories) {
log.info("ScriptEngine {}/{} is now handling {}, {}, {}.", new Object[] { factory.getEngineName(), factory.getEngineVersion(), factory.getExtensions(), factory.getMimeTypes(), factory.getNames() });
}
}
use of org.osgi.framework.Bundle in project sling by apache.
the class ScriptEngineManagerFactoryTest method checkAddingScriptBundle.
@Test
public void checkAddingScriptBundle() throws Exception {
context.checking(new Expectations() {
{
exactly(1).of(bundleCtx).registerService(with(equal(new String[] { "javax.script.ScriptEngineManager", "org.apache.sling.scripting.core.impl.helper.SlingScriptEngineManager" })), with(any(Object.class)), with(any(Dictionary.class)));
will(returnValue(new MockServiceRegistration()));
}
});
ScriptEngineManagerFactory factory = new ScriptEngineManagerFactory();
factory.activate(componentCtx);
ScriptEngineManager first = factory.getScriptEngineManager();
assertNull(first.getEngineByName("dummy"));
final Bundle bundle = context.mock(Bundle.class);
final File factoryFile = createFactoryFile();
context.checking(new Expectations() {
{
atLeast(1).of(bundle).getEntry("META-INF/services/javax.script.ScriptEngineFactory");
will(returnValue(factoryFile.toURI().toURL()));
atLeast(1).of(bundle).loadClass(SCRIPT_ENGINE_FACTORY.getName());
will(returnValue(SCRIPT_ENGINE_FACTORY));
}
});
factory.bundleChanged(new BundleEvent(BundleEvent.STARTED, bundle));
ScriptEngineManager second = factory.getScriptEngineManager();
assertNotNull(second.getEngineByName("dummy"));
}
Aggregations