本文整理汇总了Java中org.osgi.service.packageadmin.PackageAdmin类的典型用法代码示例。如果您正苦于以下问题:Java PackageAdmin类的具体用法?Java PackageAdmin怎么用?Java PackageAdmin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PackageAdmin类属于org.osgi.service.packageadmin包,在下文中一共展示了PackageAdmin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOSGiBundle
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
private Bundle getOSGiBundle(String symbolicName, BundleContext bcontext) {
ServiceReference<PackageAdmin> ref = bcontext.getServiceReference(PackageAdmin.class);
PackageAdmin packageAdmin = bcontext.getService(ref);
if (packageAdmin == null)
return null;
Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
if (bundles == null)
return null;
//Return the first bundle that is not installed or uninstalled
for (int i = 0; i < bundles.length; i++) {
if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
return bundles[i];
}
}
return null;
}
示例2: getOSGiBundle
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
private Bundle getOSGiBundle(String symbolicName) {
ServiceReference<PackageAdmin> ref = context.getBundleContext().getServiceReference(PackageAdmin.class);
PackageAdmin packageAdmin = context.getBundleContext().getService(ref);
if (packageAdmin == null)
return null;
Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
if (bundles == null)
return null;
//Return the first bundle that is not installed or uninstalled
for (int i = 0; i < bundles.length; i++) {
if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
return bundles[i];
}
}
return null;
}
示例3: loadClass
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
/**
* Load the Class of name <code>klassName</code>.
* TODO : handle class version
*
* @param context The BundleContext
* @param klassName The Class name
* @return The Class of name <code>klassName</code>
* @throws ClassNotFoundException if we can't load the Class of name <code>klassName</code>
*/
public static Class<?> loadClass(BundleContext context, String klassName) throws ClassNotFoundException {
ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
try {
PackageAdmin padmin = (PackageAdmin) context.getService(sref);
// extract package name
String packageName = klassName.substring(0, klassName.lastIndexOf('.'));
ExportedPackage pkg = padmin.getExportedPackage(packageName);
if (pkg == null) {
try {
return context.getBundle().loadClass(klassName);
} catch (ClassNotFoundException e) {
throw new ClassNotFoundException("No package found with name " + packageName + " while trying to load the class "
+ klassName + ".", e);
}
}
return pkg.getExportingBundle().loadClass(klassName);
} finally {
context.ungetService(sref);
}
}
示例4: toActivate
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
private static Set<String> toActivate(Framework f, Collection<? extends Module> allModules) {
ServiceReference sr = f.getBundleContext().getServiceReference("org.osgi.service.packageadmin.PackageAdmin"); // NOI18N
if (sr == null) {
return null;
}
PackageAdmin pkgAdm = (PackageAdmin)f.getBundleContext().getService(sr);
if (pkgAdm == null) {
return null;
}
Set<String> allCnbs = new HashSet<String>(allModules.size() * 2);
for (ModuleInfo m : allModules) {
allCnbs.add(m.getCodeNameBase());
}
Set<String> needEnablement = new HashSet<String>();
for (Bundle b : f.getBundleContext().getBundles()) {
String loc = b.getLocation();
if (loc.startsWith("netigso://")) {
loc = loc.substring("netigso://".length());
} else {
continue;
}
RequiredBundle[] arr = pkgAdm.getRequiredBundles(loc);
if (arr != null) for (RequiredBundle rb : arr) {
for (Bundle n : rb.getRequiringBundles()) {
if (allCnbs.contains(n.getSymbolicName().replace('-', '_'))) {
needEnablement.add(loc);
}
}
}
}
return needEnablement;
}
示例5: getPackageAdmin
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
private PackageAdmin getPackageAdmin() {
return AccessController.doPrivileged(new PrivilegedAction<PackageAdmin>() {
public PackageAdmin run() {
ServiceReference ref = bundleContext.getServiceReference(PackageAdmin.class.getName());
if (ref == null)
throw new IllegalStateException(PackageAdmin.class.getName() + " service is required");
// don't do any proxying since PackageAdmin is normally a framework service
// we can assume for now that it will always be available
return (PackageAdmin) bundleContext.getService(ref);
}
});
}
示例6: start
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
public void start(BundleContext context) throws Exception {
//disable the JSR99 compiler that does not work in OSGi;
//This will convince jasper to use the JDTCompiler that invokes ecj (see JSP-21 on the glassfish bug-tracker)
System.setProperty("org.apache.jasper.compiler.disablejsr199", Boolean.TRUE.toString());
this.context = context;
thisBundle = context.getBundle();
packageAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), this);
packageAdminTracker.open();
}
示例7: SystemBundle
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
SystemBundle() {
this.props = new Hashtable();
this.props.put(Constants.BUNDLE_NAME, Constants.SYSTEM_BUNDLE_LOCATION);
this.props.put(Constants.BUNDLE_VERSION, Framework.FRAMEWORK_VERSION);
this.props.put(Constants.BUNDLE_VENDOR, "Atlas");
ServiceReferenceImpl serviceReferenceImpl = new ServiceReferenceImpl(this, this, null, new String[]{StartLevel.class.getName(), PackageAdmin.class.getName()});
Framework.addValue(Framework.classes_services, StartLevel.class.getName(), serviceReferenceImpl);
Framework.addValue(Framework.classes_services, PackageAdmin.class.getName(), serviceReferenceImpl);
Framework.services.add(serviceReferenceImpl);
this.registeredServices = new ServiceReference[]{serviceReferenceImpl};
}
示例8: startBundle
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
private boolean startBundle(String bundleId)
{
PackageAdmin packageAdmin = (PackageAdmin) getService(getContext(), PackageAdmin.class.getName());
if (packageAdmin == null)
return false;
Bundle[] bundles = packageAdmin.getBundles(bundleId, null);
if (bundles != null && bundles.length > 0)
{
for (int i = 0; i < bundles.length; i++)
{
try
{
if ((bundles[0].getState() & Bundle.INSTALLED) == 0)
{
bundles[0].start();
return true;
}
}
catch (BundleException e)
{
// failed, try next bundle
}
}
}
return false;
}
示例9: getBundles
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
/**
* Returns the bundles for a given bundle name and version range,
* regardless whether the bundle is resolved or not.
*
* @param bundleName the bundle name
* @param version the version of the bundle, or <code>null</code> for all bundles
* @return the bundles of the given name belonging to the given version range
* @since 3.10
*/
public Bundle[] getBundles(String bundleName, String version) {
Bundle[] bundles= Platform.getBundles(bundleName, version);
if (bundles != null)
return bundles;
// Accessing unresolved bundle
ServiceReference<PackageAdmin> serviceRef= fBundleContext.getServiceReference(PackageAdmin.class);
PackageAdmin admin= fBundleContext.getService(serviceRef);
bundles= admin.getBundles(bundleName, version);
if (bundles != null && bundles.length > 0)
return bundles;
return null;
}
示例10: EclipseRuntimeDataProvider
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
public EclipseRuntimeDataProvider(BundleContext context) {
super();
this.context = context;
this.eclipseBundleListener = new EclipseBundleListener();
this.eclipseAllServiceListener = new EclipseAllServiceListener();
this.packageAdminReference = context.getServiceReference(PackageAdmin.class.getName());
this.packageAdmin = (PackageAdmin) context.getService(packageAdminReference);
this.startLevelReference = context.getServiceReference(StartLevel.class.getName());
this.startLevel = (StartLevel) context.getService(startLevelReference);
}
示例11: BundleItem
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
public BundleItem(final Bundle bundle, final StartLevel startLevel, final PackageAdmin packageAdmin) {
if (bundle == null) {
throw new NullPointerException("bundle");
}
this.bundleDelegate = bundle;
this.remoteBundleDelegate = null;
this.startLevel = startLevel;
this.packageAdmin = packageAdmin;
}
示例12: getPackageAdmin
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
public static PackageAdmin getPackageAdmin() throws Exception {
if (packageAdminInstance == null) {
String msg = "Before activating Carbon UI bundle, an instance of "
+ "PackageAdmin Service should be in existance";
log.error(msg);
throw new Exception(msg);
}
return packageAdminInstance;
}
示例13: getDMCoreBundle
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
public static Bundle getDMCoreBundle(BundleContext ctx) {
ServiceReference ref = ctx.getServiceReference(PackageAdmin.class.getName());
if (ref != null) {
Object service = ctx.getService(ref);
if (service instanceof PackageAdmin) {
PackageAdmin pa = (PackageAdmin) service;
if (pa != null) {
return pa.getBundle(OsgiBundleXmlApplicationContext.class);
}
}
}
return null;
}
示例14: getPackageAdmin
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
private PackageAdmin getPackageAdmin() {
return (PackageAdmin) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ServiceReference ref = bundleContext.getServiceReference(PackageAdmin.class.getName());
if (ref == null)
throw new IllegalStateException(PackageAdmin.class.getName() + " service is required");
// don't do any proxying since PackageAdmin is normally a framework service
// we can assume for now that it will always be available
return (PackageAdmin) bundleContext.getService(ref);
}
});
}
示例15: refreshBundle
import org.osgi.service.packageadmin.PackageAdmin; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void refreshBundle(Bundle changedBundle, BundleContext context) {
try {
ServiceReference ref = context.getServiceReference(PackageAdmin.class.getName());
PackageAdmin pa = (ref == null) ? null : (PackageAdmin) context.getService(ref);
System.out.println("Refreshing bundle " + changedBundle);
pa.refreshPackages(new Bundle[] { changedBundle });
} catch (Throwable e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}