本文整理匯總了Java中org.osgi.framework.BundleContext.getBundle方法的典型用法代碼示例。如果您正苦於以下問題:Java BundleContext.getBundle方法的具體用法?Java BundleContext.getBundle怎麽用?Java BundleContext.getBundle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.osgi.framework.BundleContext
的用法示例。
在下文中一共展示了BundleContext.getBundle方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createApplicationContext
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
public DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(BundleContext bundleContext)
throws Exception {
Bundle bundle = bundleContext.getBundle();
ApplicationContextConfiguration config = new ApplicationContextConfiguration(bundle, configurationScanner);
if (log.isTraceEnabled())
log.trace("Created configuration " + config + " for bundle "
+ OsgiStringUtils.nullSafeNameAndSymName(bundle));
// it's not a spring bundle, ignore it
if (!config.isSpringPoweredBundle()) {
return null;
}
log.info("Discovered configurations " + ObjectUtils.nullSafeToString(config.getConfigurationLocations())
+ " in bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]");
DelegatedExecutionOsgiBundleApplicationContext sdoac = new OsgiBundleXmlApplicationContext(
config.getConfigurationLocations());
sdoac.setBundleContext(bundleContext);
sdoac.setPublishContextAsService(config.isPublishContextAsService());
return sdoac;
}
示例2: postProcessBeanFactory
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
public void postProcessBeanFactory(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory)
throws BeansException, OsgiException {
Bundle bundle = bundleContext.getBundle();
try {
// Try and load the annotation code using the bundle classloader
Class<?> annotationBppClass = bundle.loadClass(ANNOTATION_BPP_CLASS);
// instantiate the class
final BeanPostProcessor annotationBeanPostProcessor = (BeanPostProcessor) BeanUtils.instantiateClass(annotationBppClass);
// everything went okay so configure the BPP and add it to the BF
((BeanFactoryAware) annotationBeanPostProcessor).setBeanFactory(beanFactory);
((BeanClassLoaderAware) annotationBeanPostProcessor).setBeanClassLoader(beanFactory.getBeanClassLoader());
((BundleContextAware) annotationBeanPostProcessor).setBundleContext(bundleContext);
beanFactory.addBeanPostProcessor(annotationBeanPostProcessor);
}
catch (ClassNotFoundException exception) {
log.info("Spring-DM annotation package could not be loaded from bundle ["
+ OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]; annotation processing disabled...");
if (log.isDebugEnabled())
log.debug("Cannot load annotation injection processor", exception);
}
}
示例3: createApplicationContext
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
public DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(BundleContext bundleContext)
throws Exception {
Bundle bundle = bundleContext.getBundle();
ApplicationContextConfiguration config = new BlueprintContainerConfig(bundle);
String bundleName = OsgiStringUtils.nullSafeNameAndSymName(bundle);
if (log.isTraceEnabled())
log.trace("Created configuration " + config + " for bundle " + bundleName);
// it's not a spring bundle, ignore it
if (!config.isSpringPoweredBundle()) {
if (log.isDebugEnabled())
log.debug("No blueprint configuration found in bundle " + bundleName + "; ignoring it...");
return null;
}
log.info("Discovered configurations " + ObjectUtils.nullSafeToString(config.getConfigurationLocations())
+ " in bundle [" + bundleName + "]");
DelegatedExecutionOsgiBundleApplicationContext sdoac =
new OsgiBundleXmlApplicationContext(config.getConfigurationLocations());
sdoac.setBundleContext(bundleContext);
sdoac.setPublishContextAsService(config.isPublishContextAsService());
return sdoac;
}
示例4: registerManagedService
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
public static ServiceRegistration registerManagedService(BundleContext bundleContext, ManagedService listener,
String pid) {
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_PID, pid);
Bundle bundle = bundleContext.getBundle();
props.put(Constants.BUNDLE_SYMBOLICNAME, OsgiStringUtils.nullSafeSymbolicName(bundle));
props.put(Constants.BUNDLE_VERSION, OsgiBundleUtils.getBundleVersion(bundle));
return bundleContext.registerService(ManagedService.class.getName(), listener, props);
}
示例5: getPlatformName
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
public static String getPlatformName(BundleContext bundleContext) {
String vendorProperty = bundleContext.getProperty(Constants.FRAMEWORK_VENDOR);
String frameworkVersion = bundleContext.getProperty(Constants.FRAMEWORK_VERSION);
// get system bundle
Bundle bundle = bundleContext.getBundle(0);
String name = (String) bundle.getHeaders().get(Constants.BUNDLE_NAME);
String version = (String) bundle.getHeaders().get(Constants.BUNDLE_VERSION);
String symName = bundle.getSymbolicName();
StringBuilder buf = new StringBuilder();
buf.append(name);
buf.append(" ");
buf.append(symName);
buf.append("|");
buf.append(version);
buf.append("{");
buf.append(frameworkVersion);
buf.append(" ");
buf.append(vendorProperty);
buf.append("}");
return buf.toString();
}
示例6: invoke
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
private static Object invoke(BundleContext context, long bundleID, String classFqn, String methodToInvoke,
String[] args)
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
Bundle appBundle = context.getBundle(bundleID);
Class<?> appClass = appBundle.loadClass(classFqn);
final Method method = appClass.getMethod(methodToInvoke, args.getClass());
return method.invoke(null, new Object[] { args });
}
示例7: start
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
public @Override void start(final BundleContext context) throws Exception {
if (System.getProperty("netbeans.home") != null) {
throw new IllegalStateException("Should not be run from inside regular NetBeans module system");
}
String storage = context.getProperty(Constants.FRAMEWORK_STORAGE);
if (storage != null) {
System.setProperty("netbeans.user", storage);
}
System.setProperty("TopSecurityManager.disable", "true");
NbBundle.setBranding(System.getProperty("branding.token"));
OSGiMainLookup.initialize(context);
queue = new DependencyQueue<String,Bundle>();
this.context = context;
framework = ((Framework) context.getBundle(0));
if (framework.getState() == Bundle.STARTING) {
LOG.fine("framework still starting");
final AtomicReference<FrameworkListener> frameworkListener = new AtomicReference<FrameworkListener>();
frameworkListener.set(new FrameworkListener() {
public @Override void frameworkEvent(FrameworkEvent event) {
if (event.getType() == FrameworkEvent.STARTED) {
// System.err.println("framework started");
context.removeFrameworkListener(frameworkListener.get());
context.addBundleListener(Activator.this);
processLoadedBundles();
}
}
});
context.addFrameworkListener(frameworkListener.get());
} else {
LOG.fine("framework already started");
context.addBundleListener(this);
processLoadedBundles();
}
}
示例8: start
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
@Override
public void start(BundleContext context) throws Exception {
this.listenerManager = new BlueprintListenerManager(context);
EventAdminDispatcher dispatcher = new EventAdminDispatcher(context);
Bundle bundle = context.getBundle();
this.contextProcessor = new BlueprintContainerProcessor(dispatcher, listenerManager, bundle);
this.typeChecker = new BlueprintTypeCompatibilityChecker(bundle);
this.listenerServiceActivator.getMulticaster().addApplicationListener(this.contextProcessor);
super.start(context);
}
示例9: setBundleContext
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*
* <p/> Will automatically determine the bundle, create a new <code>ResourceLoader</code> (and set its
* <code>ClassLoader</code> (if none is set already) to a custom implementation that will delegate the calls to the
* bundle).
*/
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
this.bundle = bundleContext.getBundle();
this.osgiPatternResolver = createResourcePatternResolver();
if (getClassLoader() == null)
this.setClassLoader(createBundleClassLoader(this.bundle));
this.setDisplayName(ClassUtils.getShortName(getClass()) + "(bundle=" + getBundleSymbolicName() + ", config="
+ StringUtils.arrayToCommaDelimitedString(getConfigLocations()) + ")");
this.acc = AccessControlFactory.createContext(bundle);
}
示例10: getVersion
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
/**
* Returns the OSGi platform version (using the manifest entries from the system bundle). The version can be empty.
*
* @param bundleContext bundle context to inspect
* @return not-null system bundle version
*/
public static String getVersion(BundleContext bundleContext) {
if (bundleContext == null)
return "";
// get system bundle
Bundle sysBundle = bundleContext.getBundle(0);
// force string conversion instead of casting just to be safe
return "" + sysBundle.getHeaders().get(Constants.BUNDLE_VERSION);
}
示例11: isTypeCompatible
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
public boolean isTypeCompatible(BundleContext targetContext) {
Bundle bnd = targetContext.getBundle();
return (checkCompatibility(CONTAINER_PKG_CLASS, bnd, containerPkgClass) && checkCompatibility(
REFLECT_PKG_CLASS, bnd, reflectPkgClass));
}
示例12: injectBundleContext
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
/**
* Set the bundle context to be used by this test.
* <p/>
* <p/> This method is called automatically by the test infrastructure after the OSGi platform is being setup.
*/
private void injectBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
// instantiate ResourceLoader
this.resourceLoader = new OsgiBundleResourceLoader(bundleContext.getBundle());
}
示例13: instantiateModule
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
public ShutdownModule instantiateModule(final String instanceName, final DependencyResolver dependencyResolver,
final ShutdownModule oldModule, final AutoCloseable oldInstance,
final BundleContext bundleContext) {
Bundle systemBundle = bundleContext.getBundle(0);
return new ShutdownModule(new ModuleIdentifier(NAME, instanceName), oldModule, oldInstance, systemBundle);
}