本文整理汇总了Java中org.osgi.framework.launch.Framework.getBundleContext方法的典型用法代码示例。如果您正苦于以下问题:Java Framework.getBundleContext方法的具体用法?Java Framework.getBundleContext怎么用?Java Framework.getBundleContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.framework.launch.Framework
的用法示例。
在下文中一共展示了Framework.getBundleContext方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGuiceWorksInOSGiContainer
import org.osgi.framework.launch.Framework; //导入方法依赖的package包/类
public void testGuiceWorksInOSGiContainer() throws Throwable {
// ask framework to clear cache on startup
Properties properties = new Properties();
properties.setProperty("org.osgi.framework.storage", BUILD_TEST_DIR + "/bundle.cache");
properties.setProperty("org.osgi.framework.storage.clean", "onFirstInit");
// test each available OSGi framework in turn
for (FrameworkFactory frameworkFactory : ServiceLoader.load(FrameworkFactory.class)) {
Framework framework = frameworkFactory.newFramework(properties);
framework.start();
BundleContext systemContext = framework.getBundleContext();
// load all the necessary bundles and start the OSGi test bundle
/*if[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/aopalliance.jar");
/*end[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/javax.inject.jar");
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/guava.jar");
systemContext.installBundle("reference:file:" + GUICE_JAR);
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/osgitests.jar").start();
framework.stop();
}
}
示例2: testActivation
import org.osgi.framework.launch.Framework; //导入方法依赖的package包/类
public void testActivation() throws Exception {
ModuleSystem ms = Main.getModuleSystem();
mgr = ms.getManager();
mgr.mutexPrivileged().enterWriteAccess();
try {
m1 = mgr.createBundle(simpleModule, null, false, false, false, 10);
mgr.enable(m1);
} finally {
mgr.mutexPrivileged().exitWriteAccess();
}
Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
Object s = main.getField("start").get(null);
assertNull("Not started yet", s);
Framework f = NetigsoServicesTest.findFramework();
final BundleContext fc = f.getBundleContext();
fc.addFrameworkListener(this);
ServiceReference sr = fc.getServiceReference(StartLevel.class.getName());
assertNotNull("Start level service found", sr);
StartLevel level = (StartLevel) fc.getService(sr);
assertNotNull("Start level found", level);
level.setStartLevel(10);
waitLevelChanged();
s = main.getField("start").get(null);
assertNotNull("Bundle started, its context provided", s);
mgr.mutexPrivileged().enterWriteAccess();
try {
mgr.disable(m1);
Object e = main.getField("stop").get(null);
assertNotNull("Bundle stopped, its context provided", e);
} finally {
mgr.mutexPrivileged().exitWriteAccess();
}
}
示例3: testExtendedLogReaderServiceAvailable
import org.osgi.framework.launch.Framework; //导入方法依赖的package包/类
public void testExtendedLogReaderServiceAvailable() throws Exception {
Framework f = IntegrationTest.findFramework();
BundleContext bc = f.getBundleContext();
ServiceTracker logReaderTracker = new ServiceTracker(bc, ExtendedLogReaderService.class.getName(), null);
logReaderTracker.open();
LogReaderService logReader = (ExtendedLogReaderService) logReaderTracker.getService();
assertNotNull(logReader);
}
示例4: testSAXParserAvailable
import org.osgi.framework.launch.Framework; //导入方法依赖的package包/类
public void testSAXParserAvailable() throws Exception {
Framework f = IntegrationTest.findFramework();
BundleContext bc = f.getBundleContext();
ServiceReference sr = bc.getServiceReference(SAXParserFactory.class.getName());
assertNotNull("SAX Service found", sr);
Object srvc = bc.getService(sr);
assertTrue("Instance of the right type: " + srvc, srvc instanceof SAXParserFactory);
}
示例5: initialize
import org.osgi.framework.launch.Framework; //导入方法依赖的package包/类
private void initialize() throws BundleException, URISyntaxException {
Map<String, String> configMap = loadProperties();
System.setProperty(LOG_CONFIG_FILE_PROPERTY, configMap.get(LOG_CONFIG_FILE_PROPERTY));
System.out.println("Building OSGi Framework");
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Framework framework = frameworkFactory.newFramework(configMap);
framework.init();
// (9) Use the system bundle context to process the auto-deploy
// and auto-install/auto-start properties.
AutoProcessor.process(configMap, framework.getBundleContext());
// (10) Start the framework.
System.out.println("Starting OSGi Framework");
framework.start();
BundleContext context = framework.getBundleContext();
// declarative services dependency is necessary, otherwise they won't be picked up!
loadScrBundle(context);
try {
framework.waitForStop(0);
} catch (InterruptedException e) {
appendToFile(e);
showErrorMessage();
}
System.exit(0);
}
示例6: testGuiceWorksInOSGiContainer
import org.osgi.framework.launch.Framework; //导入方法依赖的package包/类
public void testGuiceWorksInOSGiContainer()
throws Throwable {
// ask framework to clear cache on startup
Properties properties = new Properties();
properties.setProperty("org.osgi.framework.storage", BUILD_TEST_DIR + "/bundle.cache");
properties.setProperty("org.osgi.framework.storage.clean", "onFirstInit");
// test each available OSGi framework in turn
Iterator<FrameworkFactory> f = ServiceRegistry.lookupProviders(FrameworkFactory.class);
while (f.hasNext()) {
Framework framework = f.next().newFramework(properties);
framework.start();
BundleContext systemContext = framework.getBundleContext();
// load all the necessary bundles and start the OSGi test bundle
/*if[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/aopalliance.jar");
/*end[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/javax.inject.jar");
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/guava.jar");
systemContext.installBundle("reference:file:" + GUICE_JAR);
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/osgitests.jar").start();
framework.stop();
}
}
示例7: testGuiceWorksInOSGiContainer
import org.osgi.framework.launch.Framework; //导入方法依赖的package包/类
public void testGuiceWorksInOSGiContainer()
throws Throwable {
// ask framework to clear cache on startup
Properties properties = new Properties();
properties.setProperty("org.osgi.framework.storage", BUILD_TEST_DIR + "/bundle.cache");
properties.setProperty("org.osgi.framework.storage.clean", "onFirstInit");
// test each available OSGi framework in turn
Iterator<FrameworkFactory> f = ServiceRegistry.lookupProviders(FrameworkFactory.class);
while (f.hasNext()) {
Framework framework = f.next().newFramework(properties);
framework.start();
BundleContext systemContext = framework.getBundleContext();
// load all the necessary bundles and start the OSGi test bundle
/*if[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/aopalliance.jar");
/*end[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/javax.inject.jar");
systemContext.installBundle("reference:file:" + GUICE_JAR);
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/osgitests.jar").start();
framework.stop();
}
}
示例8: start
import org.osgi.framework.launch.Framework; //导入方法依赖的package包/类
public void start()
{
frame = new SplashFrame();
final SwingWorker<Void, Integer> worker = new SwingWorker<Void, Integer>() {
protected Void doInBackground() throws Exception {
try {
String factoryClass = getFactoryClass();
FrameworkFactory factory = (FrameworkFactory) Class.forName(factoryClass).newInstance();
Framework framework = factory.newFramework(getLaunchProperties());
framework.start();
context = framework.getBundleContext();
BundleLoader loader = new BundleLoader(context);
/* load embedded bundles, i.e. all bundles that are inside pathvisio.jar */
System.out.println("Installing bundles that are embedded in the jar.");
Set<String> jarNames = loader.getResourceListing(PathVisioMain.class);
int cnt = 0;
int total = jarNames.size() + pluginLocations.size();
for (String s : jarNames)
{
String text = (s.length() > 50) ? s.substring(0, 50) : s;
frame.getTextLabel().setText("<html>Install " + text + ".</html>");
frame.repaint();
publish(100 * (++cnt) / total);
loader.installEmbeddedBundle(s);
}
frame.getTextLabel().setText("<html>Install active plugins.</html>");
frame.repaint();
System.out.println("Installing bundles from directories specified on the command-line.");
for(String location : pluginLocations) {
publish(100 * (++cnt) / total);
loader.loadFromParameter(location);
}
startBundles(context, loader.getBundles());
frame.getTextLabel().setText("Start application.");
frame.repaint();
} catch(Exception ex) {
reportException("Startup Error", ex);
ex.printStackTrace();
}
return null;
}
protected void process(List<Integer> chunks) {
for (Integer chunk : chunks) {
frame.getProgressBar().setString("Installing modules..." + chunk + "%");
frame.getProgressBar().setValue(chunk);
frame.repaint();
}
}
protected void done() {
frame.setVisible(false);
}
};
worker.execute();
}
示例9: printMissingRequirements
import org.osgi.framework.launch.Framework; //导入方法依赖的package包/类
private void printMissingRequirements(final Framework osgiContainer) {
BundleContext systemBundleContext = osgiContainer.getBundleContext();
ServiceReference<PlatformAdmin> platformServiceSR = systemBundleContext
.getServiceReference(PlatformAdmin.class);
PlatformAdmin platformAdmin = systemBundleContext.getService(platformServiceSR);
State state = platformAdmin.getState();
Bundle[] bundles = systemBundleContext.getBundles();
List<BundleCapability> availableCapabilities = getAllCapabilities(bundles, state);
Map<Bundle, List<ImportPackageSpecification>> requiredMissingByBundle = new TreeMap<>();
Map<Bundle, List<ImportPackageSpecification>> optionalMissingByBundle = new TreeMap<>();
for (Bundle bundle : bundles) {
if (bundle.getState() == Bundle.INSTALLED) {
List<ImportPackageSpecification> requiredMissings = new ArrayList<>();
List<ImportPackageSpecification> optionalMissings = new ArrayList<>();
BundleDescription bundleDescription = state.getBundle(bundle.getBundleId());
ImportPackageSpecification[] allImports = bundleDescription.getImportPackages();
for (ImportPackageSpecification importPackage : allImports) {
BundleRequirement requirement = importPackage.getRequirement();
if (!requirementSatisfiable(requirement, availableCapabilities)) {
if (Constants.RESOLUTION_OPTIONAL
.equals(requirement.getDirectives().get(Constants.RESOLUTION_DIRECTIVE))) {
optionalMissings.add(importPackage);
} else {
requiredMissings.add(importPackage);
}
}
}
if (optionalMissings.size() > 0) {
optionalMissingByBundle.put(bundle, optionalMissings);
}
if (requiredMissings.size() > 0) {
requiredMissingByBundle.put(bundle, requiredMissings);
}
}
}
getLog().info("----- Missing required packages by bundles -----");
Set<String> requiredSum = printBundlesWithMissingImportsAndSummarize(requiredMissingByBundle);
getLog().info("");
getLog().info("");
getLog().info("----- Missing optional packages by bundles -----");
Set<String> optionalSum = printBundlesWithMissingImportsAndSummarize(optionalMissingByBundle);
getLog().info("");
getLog().info("");
getLog().info("----- Missing required packages (summary) -----");
printMissingSummary(requiredSum);
getLog().info("");
getLog().info("");
getLog().info("----- Missing optional packages (summary) -----");
printMissingSummary(optionalSum);
getLog().info("");
getLog().info("");
}
示例10: startOSGiContainer
import org.osgi.framework.launch.Framework; //导入方法依赖的package包/类
private Framework startOSGiContainer(final String[] bundleLocations,
final String tempDirPath) throws BundleException {
FrameworkFactory frameworkFactory = ServiceLoader
.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<String, String>();
config.put("org.osgi.framework.system.packages", "");
config.put("osgi.configuration.area", tempDirPath);
config.put("osgi.baseConfiguration.area", tempDirPath);
config.put("osgi.sharedConfiguration.area", tempDirPath);
config.put("osgi.instance.area", tempDirPath);
config.put("osgi.user.area", tempDirPath);
config.put("osgi.hook.configurators.exclude",
"org.eclipse.core.runtime.internal.adaptor.EclipseLogHook");
Framework framework = frameworkFactory.newFramework(config);
framework.init();
BundleContext systemBundleContext = framework.getBundleContext();
org.apache.maven.artifact.Artifact equinoxCompatibilityStateArtifact =
pluginArtifactMap.get("org.eclipse.tycho:org.eclipse.osgi.compatibility.state");
URI compatibilityBundleURI = equinoxCompatibilityStateArtifact.getFile().toURI();
systemBundleContext.installBundle("reference:" + compatibilityBundleURI.toString());
framework.start();
for (String bundleLocation : bundleLocations) {
try {
systemBundleContext.installBundle(bundleLocation);
} catch (BundleException e) {
getLog().warn("Could not install bundle " + bundleLocation, e);
}
}
FrameworkWiring frameworkWiring = framework
.adapt(FrameworkWiring.class);
frameworkWiring.resolveBundles(null);
return framework;
}