本文整理汇总了Java中org.osgi.framework.wiring.BundleRevision类的典型用法代码示例。如果您正苦于以下问题:Java BundleRevision类的具体用法?Java BundleRevision怎么用?Java BundleRevision使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BundleRevision类属于org.osgi.framework.wiring包,在下文中一共展示了BundleRevision类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WrappingTransformer
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
public WrappingTransformer(ClassTransformer delegate, ServiceReference<?> persistenceProvider) {
validate(delegate, persistenceProvider);
this.delegate = delegate;
Object packages = persistenceProvider.getProperty("org.apache.aries.jpa.container.weaving.packages");
if (packages instanceof String[]) {
for (String s : (String[])packages) {
packageImportsToAdd.add(s);
}
} else {
Bundle provider = persistenceProvider.getBundle();
String suffix = ";" + Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE + "=" + provider.getSymbolicName()
+ ";" + Constants.BUNDLE_VERSION_ATTRIBUTE + "=" + provider.getVersion();
BundleRevision br = provider.adapt(BundleWiring.class).getRevision();
for (BundleCapability bc : br.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE)) {
packageImportsToAdd.add(bc.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE) + suffix);
}
}
}
示例2: getJPAPackages
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
/**
* Get all the relevant packages that the EclipseLink JPA provider exports or persistence packages it uses itself. These are needed
* so that the woven proxy (for runtime enhancement) can be used later on :)
*
* Note that differently to OpenJPA the relevant classes are actually in more than just one bundle (org.eclipse.persistence.jpa and org.eclipse.persistence.core
* at the time of this writing). Hence, we have to take more than just the packages of the JPA provider bundle into account ...
*
* @param jpaBundle
* @return
*/
private String[] getJPAPackages(Bundle jpaBundle) {
Set<String> result = new HashSet<String>();
for (Bundle b : context.getBundles()) {
BundleWiring bw = b.adapt(BundleWiring.class);
if (bw == null) {
continue;
}
boolean isJpaBundle = b.equals(jpaBundle);
List<BundleWire> wires = bw.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);
for (BundleWire w : wires) {
String pkgName = (String)w.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE);
boolean add = isJpaBundle || pkgName.startsWith("org.eclipse.persistence");
if (add) {
result.add(getPkg(b, pkgName));
}
}
}
result.add(getPkg(context.getBundle(), "org.apache.aries.jpa.eclipselink.adapter.platform"));
LOG.debug("Found JPA packages {}", result);
return result.toArray(new String[0]);
}
示例3: findResourceRepositoryIndex
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
/**
* Get the repository index for the specified resource, where 0 indicates an
* existing OSGi bundle in the framework and -1 indicates not found. This
* method is used by
* {@link #insertHostedCapability(List, HostedCapability)}.
*/
private int findResourceRepositoryIndex(Resource resource) {
if (resource instanceof BundleRevision) {
return 0;
}
int index = 1;
Repository repo = this.resourceRepositoryMap.get(resource);
if (repo == null) {
return -1;
}
for (Repository match : this.repositories.values()) {
if (repo == match) {
return index;
}
index++;
}
// Still not found
return -1;
}
示例4: waitBundleStarted
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
public static void waitBundleStarted(Bundle bundle) {
if ((bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
return;
}
BundleContext ctx;
int state;
// 自旋锁
for (;;) {
state = bundle.getState();
if (state != Bundle.STARTING && state != Bundle.ACTIVE) {
return;
}
ctx = bundle.getBundleContext();
if (ctx == null) {
Thread.yield();
} else {
return;
}
}
}
示例5: getDynamicClassLoader
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
private ProxyClassLoader getDynamicClassLoader(Class<?> clazz) {
// Find all bundles required to instanciate the class
// and bridge their classloaders in case the abstract class or interface
// lives in non-imported packages...
Class<?> currClazz = clazz;
List<BundleRevision> bundleRevs = new ArrayList<>();
Map<BundleRevision, BundleRevPath> revisions = revisionMap;
BundleRevPath bundleRevPath = null;
do {
BundleRevision bundleRev = FrameworkUtil.getBundle(currClazz).adapt(BundleRevision.class);
if (!bundleRevs.contains(bundleRev)) {
bundleRevs.add(bundleRev);
bundleRevPath = revisions.computeIfAbsent(bundleRev, k -> new BundleRevPath());
revisions = bundleRevPath
.computeSubMapIfAbsent(() -> Collections.synchronizedMap(new WeakIdentityHashMap<>()));
}
currClazz = currClazz.getSuperclass();
} while (currClazz != null && currClazz != Object.class);
return bundleRevPath.computeClassLoaderIfAbsent(() -> {
// the bundles set is now prioritised ...
ClassLoader[] classLoaders = bundleRevs.stream().map(b -> b.getWiring().getClassLoader())
.toArray(ClassLoader[]::new);
return new ProxyClassLoader(new BridgingClassLoader(classLoaders));
});
}
示例6: getInUseBundleWirings
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
private Set<BundleWiring> getInUseBundleWirings() {
Set<BundleWiring> wirings = new HashSet<>();
Collection<BundleCapability> bundles = fwkWiring.findProviders(ALL_BUNDLES_REQUIREMENT);
for (BundleCapability bundleCap : bundles) {
// Only pay attention to non JPMS boot modules.
// NOTE this means we will not create a real JPMS Module or Layer for this bundle
if (bundleCap.getAttributes().get(BOOT_JPMS_MODULE) == null) {
BundleRevision revision = bundleCap.getRevision();
BundleWiring wiring = revision.getWiring();
if (wiring != null && wiring.isInUse()) {
wirings.add(wiring);
}
if (revision.getBundle().getBundleId() == 0) {
// also store the system.bundle fragments because they may have exports unknown to JPMS
List<BundleWire> hostWires = wiring.getProvidedWires(HostNamespace.HOST_NAMESPACE);
for (BundleWire hostWire : hostWires) {
wirings.add(hostWire.getRequirerWiring());
}
}
}
}
return wirings;
}
示例7: prepareDependencies
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
private void prepareDependencies(final Bundle bundle) {
final BundleWiring wiring = bundle.adapt(BundleWiring.class);
final List<BundleWire> wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
if (wires != null) {
for (final BundleWire wire : wires) {
try {
final Bundle dependency = wire.getProviderWiring().getBundle();
if (visited.add(dependency.getSymbolicName()) && hasComponents(dependency)) {
if (!live(dependency)) {
dependency.start();
}
if (live(dependency)) {
// pseudo-event to trigger bundle activation
addingBundle(dependency, null /* unused */);
}
}
}
catch (final Exception e) {
log.warn("MISSING {}", wire, e);
}
}
}
}
示例8: getRequiredPackages
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
public static List<PackageQuery> getRequiredPackages(Bundle bundle) throws BundleException {
List<PackageQuery> rtn=new ArrayList<PackageQuery>();
BundleRevision br = bundle.adapt(BundleRevision.class);
List<Requirement> requirements = br.getRequirements(null);
Iterator<Requirement> it = requirements.iterator();
Requirement r;
Entry<String, String> e;
String value;
PackageQuery pd;
while(it.hasNext()){
r = it.next();
Iterator<Entry<String, String>> iit = r.getDirectives().entrySet().iterator();
inner:while(iit.hasNext()){
e = iit.next();
if(!"filter".equals(e.getKey())) continue;
value=e.getValue();
pd=toPackageQuery(value);
if(pd!=null)rtn.add(pd);
}
}
return rtn;
}
示例9: getAPICapabilities
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
/**
* Returns all capabilities published by the core plugin that are associated with the Hobson API.
*
* @return an array of Capability objects (or null if a bundle lookup failure occurred)
*/
protected Capability[] getAPICapabilities() {
Bundle coreBundle = FrameworkUtil.getBundle(getClass());
if (coreBundle != null) {
List<Capability> apiCapabilities = new ArrayList<>();
BundleRevision revision = coreBundle.adapt(BundleRevision.class);
List<BundleCapability> caps = revision.getDeclaredCapabilities(null);
for (BundleCapability bc : caps) {
Object pkgName = bc.getAttributes().get("osgi.wiring.package");
Object version = bc.getAttributes().get("bundle-version");
if (pkgName != null && version != null && pkgName.toString().startsWith("com.whizzosoftware.hobson.api")) {
apiCapabilities.add(new HobsonApiCapability(pkgName.toString(), version.toString()));
}
}
return apiCapabilities.toArray(new Capability[apiCapabilities.size()]);
}
return null;
}
示例10: addPackagesFrom
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
public void addPackagesFrom(Bundle bundle) {
synchronized (m_packageResourceByPackageIdMap) {
BundleRevision revision = bundle.adapt(BundleRevision.class);
if (revision != null) {
List<BundleCapability> bundleCapabilities = revision.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
if (!bundleCapabilities.isEmpty()) {
for (BundleCapability bc : bundleCapabilities) {
PackageResource packageResource = new PackageResource(bc);
String uniquePackageId = packageResource.getUniquePackageId();
PackageResource oldPackage = m_packageResourceByPackageIdMap.put(uniquePackageId, packageResource);
if (oldPackage != null) {
Everest.postResource(ResourceEvent.UPDATED, packageResource);
} else {
Everest.postResource(ResourceEvent.CREATED, packageResource);
}
}
}
}
}
}
示例11: getExportedPackage
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
/**
* Return the BundleCapability of a bundle exporting the package packageName.
*
* @param context The BundleContext
* @param packageName The package name
* @return the BundleCapability of a bundle exporting the package packageName
*/
private static BundleCapability getExportedPackage(BundleContext context, String packageName) {
List<BundleCapability> packages = new ArrayList<BundleCapability>();
for (Bundle bundle : context.getBundles()) {
BundleRevision bundleRevision = bundle.adapt(BundleRevision.class);
for (BundleCapability packageCapability : bundleRevision.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE)) {
String pName = (String) packageCapability.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE);
if (pName.equalsIgnoreCase(packageName)) {
packages.add(packageCapability);
}
}
}
Version max = Version.emptyVersion;
BundleCapability maxVersion = null;
for (BundleCapability aPackage : packages) {
Version version = (Version) aPackage.getAttributes().get("version");
if (max.compareTo(version) <= 0) {
max = version;
maxVersion = aPackage;
}
}
return maxVersion;
}
示例12: updateContext
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
private void updateContext(Bundle currentContext, String className) {
Bundle contextToSet = (currentContext == null) ? bundle : currentContext;
int idx = className.lastIndexOf('.');
String packageName = (idx == -1) ? "" : className.substring(0, idx);
BundleWiring wiring = contextToSet.adapt(BundleWiring.class);
for (BundleWire wire : wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE)) {
if (wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).equals(packageName)) {
contextToSet = wire.getProviderWiring().getBundle();
break;
}
}
currentLoadingBundle.get().push(contextToSet);
}
示例13: getWirings
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
@Override
public Map<Resource, Wiring> getWirings() {
Map<Resource, Wiring> wiringMap = new HashMap<>();
Bundle[] bundles = this.bundleContext.getBundles();
for (Bundle bundle : bundles) {
// BundleRevision extends Resource
BundleRevision revision = bundle.adapt(BundleRevision.class);
// BundleWiring extends Wiring
BundleWiring wiring = revision.getWiring();
if (wiring != null) {
wiringMap.put(revision, wiring);
}
}
return wiringMap;
}
示例14: getLocation
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
String getLocation(Resource resource) {
String location;
if (resource instanceof BundleRevision) {
location = ((BundleRevision) resource).getBundle().getLocation();
} else {
location = this.resourceLocationMap.get(resource);
}
return location;
}
示例15: isFragment
import org.osgi.framework.wiring.BundleRevision; //导入依赖的package包/类
private boolean isFragment(Bundle bundle) {
BundleRevision bundleRevision = bundle.adapt(BundleRevision.class);
if (bundleRevision == null)
throw new NullPointerException("Null bundle revision means that bundle has probably been uninstalled: " +
bundle.getSymbolicName() + ":" + bundle.getVersion());
return (bundleRevision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0;
}