当前位置: 首页>>代码示例>>Java>>正文


Java Bundle.adapt方法代码示例

本文整理汇总了Java中org.osgi.framework.Bundle.adapt方法的典型用法代码示例。如果您正苦于以下问题:Java Bundle.adapt方法的具体用法?Java Bundle.adapt怎么用?Java Bundle.adapt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.osgi.framework.Bundle的用法示例。


在下文中一共展示了Bundle.adapt方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processClass

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
@Override
public byte[] processClass(String className, byte[] bytes, ClasspathEntry ce, BundleEntry be, ClasspathManager cm) {
    final BaseData bd = ce.getBaseData();
    if (bd == null) {
        return bytes;
    }
    final Bundle b = bd.getBundle();
    if (b == null) {
        return bytes;
    }
    BundleWiring w = b.adapt(org.osgi.framework.wiring.BundleWiring.class);
    if (w == null) {
        return bytes;
    }
    ClassLoader loader = w.getClassLoader();
    return archive.patchByteCode(loader, className, ce.getDomain(), bytes);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:NetbinoxHooks.java

示例2: isRequiredBundle

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
 * Checks if is required bundle.
 *
 * @param bundle the bundle
 * @param className the class name
 * @return true, if is required bundle
 */
private boolean isRequiredBundle(Bundle bundle, String className) {
	
	// --- 1. Simply try to load the class ----------------------
	try {
		Class<?> classInstance = bundle.loadClass(className);
		if (classInstance!=null)  return true;
	
	} catch (ClassNotFoundException cnfEx) {
		//cnfEx.printStackTrace();
	}
	
	// --- 2. Try to check the resources of the bundle ----------
	String simpleClassName = className.substring(className.lastIndexOf(".")+1);
	String packagePath = className.substring(0, className.lastIndexOf("."));
	packagePath = packagePath.replace(".", "/");
	if (packagePath.startsWith("/")==false) packagePath = "/" + packagePath;
	if (packagePath.endsWith("/")  ==false) packagePath = packagePath + "/";
	
	BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
	Collection<String> resources = bundleWiring.listResources(packagePath, simpleClassName + ".class", BundleWiring.LISTRESOURCES_LOCAL);
	if (resources!=null && resources.size()>0) {
		return true;
	}
	return false;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:33,代码来源:AbstractClassLoadServiceUtilityImpl.java

示例3: getJPAPackages

import org.osgi.framework.Bundle; //导入方法依赖的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]);
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:34,代码来源:Activator.java

示例4: setStartLevel

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private void setStartLevel ( final String symbolicName, final int startLevel ) throws BundleException
{
    final Bundle bundle = findBundle ( symbolicName );
    if ( bundle == null )
    {
        return;
    }
    final BundleStartLevel bundleStartLevel = bundle.adapt ( BundleStartLevel.class );
    if ( bundleStartLevel == null )
    {
        return;
    }

    bundleStartLevel.setStartLevel ( startLevel < 0 ? this.defaultStartLevel : startLevel );
    bundle.start ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:Activator.java

示例5: updateContext

import org.osgi.framework.Bundle; //导入方法依赖的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);
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:14,代码来源:TempBundleDelegatingClassLoader.java

示例6: incompatibleClassSpace

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
    * Sufficient Criteria for having/failing class space compatibility - 
    * <ol>
    *   <li>Sharing a contract for <code>JavaJPA</code></li>
    *   <li>Sharing a provider of <code>javax.persistence</code></li>
    *   <li>Sharing a provider of <code>org.osgi.service.jpa</code></li>
    * </ol>
    * 
    * @param bundle
    * @return
    */
private boolean incompatibleClassSpace(Bundle bundle) {
	BundleWiring pbWiring = bundle.adapt(BundleWiring.class);
	
	BundleCapability pbContract = getUsedCapability(pbWiring, OSGI_CONTRACT_NS, JAVA_JPA_CONTRACT);
	
	if(pbContract != null) {
		LOGGER.debug("Matching JPA contract for possible persistence bundle {}", bundle.getSymbolicName());
		
		BundleCapability implContract = getUsedCapability(pbWiring, OSGI_CONTRACT_NS, JAVA_JPA_CONTRACT);
		return !pbContract.equals(implContract);
	}
	
	// No contract required by the persistence bundle, try javax.persistence
	BundleCapability pbJavaxPersistence = getUsedCapability(pbWiring, 
				OSGI_PACKAGE_NS, JAVAX_PERSISTENCE_PKG);
		
	if(pbJavaxPersistence != null) {
		LOGGER.debug("Matching JPA API package for possible persistence bundle {}", bundle.getSymbolicName());
		
		BundleCapability implJavaxPersistence = getUsedCapability(pbWiring, 
				OSGI_PACKAGE_NS, JAVAX_PERSISTENCE_PKG);
		return !pbJavaxPersistence.equals(implJavaxPersistence);
	}

	// No jpa package required by the persistence bundle, try org.osgi.service.jpa
	BundleCapability pbJpaService = getUsedCapability(pbWiring, 
			OSGI_PACKAGE_NS, JPA_SERVICE_PKG);
	
	if(pbJpaService != null) {
		LOGGER.debug("Matching JPA service package for possible persistence bundle {}", bundle.getSymbolicName());
		
		BundleCapability implJpaService = getUsedCapability(pbWiring, 
				OSGI_PACKAGE_NS, JPA_SERVICE_PKG);
		return !pbJpaService.equals(implJpaService);
	}
	
	// If there is nothing to clash on then we must assume that it's safe
	return false;
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:51,代码来源:PersistenceBundleTracker.java

示例7: getWirings

import org.osgi.framework.Bundle; //导入方法依赖的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;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:16,代码来源:PluginResolveContext.java

示例8: getComboBoxModel

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
 * Gets the combo box model for the versions.
 * @return the combo box model
 */
private DefaultComboBoxModel<String> getComboBoxModel() {

	// --- Set default combo box model --------------------------
	DefaultComboBoxModel<String> cbm = new DefaultComboBoxModel<String>();

	// --- Find all files in the package 'agentgui/ -------------
	Vector<String> versionSites = new Vector<String>();

	// --- Use BundleWiring to get the html-changes sites ------- 
	Bundle bundle = Platform.getBundle(BundleProperties.PLUGIN_ID);
	BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
	if (bundleWiring!=null) {
		Collection<String> sitesFound = bundleWiring.listResources(this.changeFilesPackage, "*.html", BundleWiring.LISTRESOURCES_LOCAL);
		versionSites.addAll(sitesFound);
	}
	
	if (versionSites!=null) {
		// --- Files found - get the version files -------------- 
		Vector<String> versionNumbers = new Vector<String>();
		for (int i = 0; i < versionSites.size(); i++) {
			String fileName = versionSites.get(i);
			if (fileName.endsWith(".html")) {
				int cut1 = fileName.indexOf("build") + 6;
				int cut2 = fileName.indexOf("changes") - 1;
				String versionNumber = fileName.substring(cut1, cut2);
				versionNumbers.addElement(versionNumber);
			}
		}
		// --- Sort result descending ---------------------------
		Collections.sort(versionNumbers, new Comparator<String>() {
			public int compare(String version1, String version2) {
				int compared = 0;
				Integer buildNo1 = Integer.parseInt(version1.substring(version1.indexOf("-")+1));
				Integer buildNo2 = Integer.parseInt(version2.substring(version2.indexOf("-")+1));
				compared = buildNo1.compareTo(buildNo2);
				return compared*-1;
			};
		});
		// --- Fill the combo box model -------------------------
		cbm = new DefaultComboBoxModel<String>(versionNumbers);
		
		// --- set the current file -----------------------------
		this.loadBuildChanges(versionNumbers.get(0));
	}
	return cbm;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:51,代码来源:ChangeDialog.java

示例9: getBundleLoader

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private static ClassLoader getBundleLoader(String name) {
Bundle bundle = Platform.getBundle(name);
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
return bundleWiring.getClassLoader();
}
 
开发者ID:eclipse,项目名称:scanning,代码行数:6,代码来源:JythonInterpreterManager.java

示例10: findProviders

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
@Override
public List<Capability> findProviders(Requirement requirement) {
	List<Capability> resultCaps = new LinkedList<>();

	// Find from installed bundles
	Bundle[] bundles = this.bundleContext.getBundles();
	for (Bundle bundle : bundles) {
           if (bundle.getState() == Bundle.UNINSTALLED) {
               continue; // Skip UNINSTALLED bundles
           }

		BundleRevision revision = bundle.adapt(BundleRevision.class);
		List<Capability> bundleCaps = revision.getCapabilities(requirement.getNamespace());
		if (bundleCaps != null) {
               for (Capability bundleCap : bundleCaps) {
               	if (match(requirement, bundleCap, this.log)) {
                       resultCaps.add(bundleCap);
                   }
               }
           }
	}

	// Find from repositories
	for (Entry<URI, Repository> repoEntry : this.repositories.entrySet()) {
		Repository repository = repoEntry.getValue();
		Map<Requirement, Collection<Capability>> providers = repository.findProviders(Collections.singleton(requirement));
		if (providers != null) {
			Collection<Capability> repoCaps = providers.get(requirement);
			if (repoCaps != null) {
				resultCaps.addAll(repoCaps);

				for (Capability repoCap : repoCaps) {
					// Get the list of physical URIs for this resource.
					Resource resource = repoCap.getResource();
					// Keep track of which repositories own which resources.
					this.resourceRepositoryMap.putIfAbsent(resource, repository);

					// Resolve the Resource's URI relative to the Repository Index URI and save for later.
					URI repoIndexUri = repoEntry.getKey();
					URI resolvedUri = resolveResourceLocation(resource, repoIndexUri);
					if (resolvedUri != null) {
						// Cache the resolved URI into the resource URI map, which will be used after resolve.
						this.resourceLocationMap.put(resource, resolvedUri.toString());
					}
				}
			}
		}
	}
	return resultCaps;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:51,代码来源:PluginResolveContext.java


注:本文中的org.osgi.framework.Bundle.adapt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。