本文整理了Java中org.osgi.framework.Bundle.getEntry()
方法的一些代码示例,展示了Bundle.getEntry()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bundle.getEntry()
方法的具体详情如下:
包路径:org.osgi.framework.Bundle
类名称:Bundle
方法名:getEntry
[英]Returns a URL to the entry at the specified path in this bundle. This bundle's class loader is not used to search for the entry. Only the contents of this bundle are searched for the entry.
The specified path is always relative to the root of this bundle and may begin with "/". A path value of "/" indicates the root of this bundle.
Note: Jar and zip files are not required to include directory entries. URLs to directory entries will not be returned if the bundle contents do not contain directory entries.
[中]返回此捆绑包中指定路径处的项的URL。此捆绑包的类装入器不用于搜索条目。仅在该捆绑包的内容中搜索条目。
指定的路径始终相对于此束的根,并且可以以“/”开头。路径值“/”表示此捆绑包的根。
注意:Jar和zip文件不需要包含目录条目。如果捆绑包内容不包含目录项,则不会返回指向目录项的URL。
代码示例来源:origin: jersey/jersey
/**
* Lookup resource by given name. If OSGi runtime is detected and the originClass parameter is not null,
* an attempt will be made to get the resource input stream via OSGi API from the bundle where originClass is included.
* Otherwise (non OSGi environment) or if OSGi fails to provide the input stream, the return value
* will be taken from the provided loader getResourceAsStream method.
*
* @param loader class loader where to lookup the resource in non-OSGi environment or if OSGi means fail.
* @param originClass if not null, and OSGi environment is detected, the resource will be taken from the bundle including
* the originClass type.
* @param name filename of the desired resource.
* @return an input stream corresponding to the required resource or null if the resource could not be found.
*/
public static InputStream getResourceAsStream(final ClassLoader loader, final Class<?> originClass, final String name) {
try {
if (bundleReferenceClass != null
&& originClass != null
&& bundleReferenceClass.isInstance(ReflectionHelper.class.getClassLoader())) {
final Bundle bundle = FrameworkUtil.getBundle(originClass);
final URL resourceUrl = (bundle != null) ? bundle.getEntry(name) : null;
if (resourceUrl != null) {
return resourceUrl.openStream();
}
}
} catch (final IOException ex) {
// ignore
}
return loader.getResourceAsStream(name);
}
代码示例来源:origin: jersey/jersey
/**
* Lookup resource by given name. If OSGi runtime is detected and the originClass parameter is not null,
* an attempt will be made to get the resource input stream via OSGi API from the bundle where originClass is included.
* Otherwise (non OSGi environment) or if OSGi fails to provide the input stream, the return value
* will be taken from the provided loader getResourceAsStream method.
*
* @param loader class loader where to lookup the resource in non-OSGi environment or if OSGi means fail.
* @param originClass if not null, and OSGi environment is detected, the resource will be taken from the bundle including
* the originClass type.
* @param name filename of the desired resource.
* @return an input stream corresponding to the required resource or null if the resource could not be found.
*/
public static InputStream getResourceAsStream(final ClassLoader loader, final Class<?> originClass, final String name) {
try {
if (bundleReferenceClass != null
&& originClass != null
&& bundleReferenceClass.isInstance(ReflectionHelper.class.getClassLoader())) {
final Bundle bundle = FrameworkUtil.getBundle(originClass);
final URL resourceUrl = (bundle != null) ? bundle.getEntry(name) : null;
if (resourceUrl != null) {
return resourceUrl.openStream();
}
}
} catch (final IOException ex) {
// ignore
}
return loader.getResourceAsStream(name);
}
代码示例来源:origin: spring-projects/spring-roo
public void execute(final Bundle bundle) {
try {
final URL url = bundle.getEntry(resourceName);
if (url != null) {
results.add(url);
}
} catch (final IllegalStateException e) {
// The bundle has been uninstalled - ignore it
}
}
}, context);
代码示例来源:origin: spring-projects/spring-roo
public void execute(final Bundle bundle) {
try {
final URL url = bundle.getEntry(path);
if (url != null) {
final URI uri = url.toURI();
if (!uris.contains(uri)) {
// We haven't seen this URL before; add it
urls.add(url);
uris.add(uri);
}
}
} catch (final IllegalStateException e) {
// The bundle has been uninstalled - ignore it
} catch (final URISyntaxException e) {
// The URL can't be converted to a URI - ignore it
}
}
}, context);
代码示例来源:origin: spring-projects/spring-roo
/**
* Locates the first bundle that contains the presented type name and return
* its bundle symbolic name.
*
* @param context that can be used to obtain bundles to search (required)
* @param typeNameInExternalForm a type name (eg com.foo.Bar)
* @return the bundle symbolic name, if found (or null if not found)
*/
public static String findFirstBundleForTypeName(final BundleContext context,
final String typeNameInExternalForm) {
Validate.notNull(context, "Bundle context required to perform the search");
Validate.notBlank(typeNameInExternalForm, "Resource name to locate is required");
final String resourceName = "/" + typeNameInExternalForm.replace('.', '/') + ".class";
final Bundle[] bundles = context.getBundles();
if (bundles == null) {
return null;
}
for (final Bundle bundle : bundles) {
try {
final URL url = bundle.getEntry(resourceName);
if (url != null) {
return bundle.getSymbolicName();
}
} catch (final RuntimeException e) {
return null;
}
}
return null;
}
代码示例来源:origin: spring-projects/spring-roo
final URL url = bundle.getEntry(resourceName);
if (url != null) {
return bundle.loadClass(typeNameInExternalForm);
代码示例来源:origin: eclipse/smarthome
boolean isHostResource = bundle.getEntry(url.getPath()) != null
&& bundle.getEntry(url.getPath()).equals(url);
if (isHostResource) {
continue;
代码示例来源:origin: org.jboss.osgi/jboss-osgi-spi
@Override
public URL getEntry(String path)
{
return bundle.getEntry(path);
}
代码示例来源:origin: org.eclipse.equinox/common
private static URL findInPlugin(Bundle b, IPath filePath, ArrayList multiple) {
URL result = b.getEntry(filePath.toString());
if (result != null && multiple != null)
multiple.add(result);
return result;
}
代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.equinox.common
private static URL findInPlugin(Bundle b, IPath filePath, ArrayList<URL> multiple) {
URL result = b.getEntry(filePath.toString());
if (result != null && multiple != null)
multiple.add(result);
return result;
}
代码示例来源:origin: org.glassfish.fighterfish/osgi-javaee-base
public URI getURI() {
try {
return b.getEntry(distanceFromTop).toURI();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/cxf
private String getSwaggerUiRoot(Bundle b, String swaggerUiVersion) {
if (swaggerUiVersion == null) {
swaggerUiVersion = b.getVersion().toString();
}
URL entry = b.getEntry(SwaggerUiResolver.UI_RESOURCES_ROOT_START + swaggerUiVersion);
if (entry != null) {
return entry.toString() + "/";
}
return null;
}
}
代码示例来源:origin: org.apache.xbean/xbean-bundleutils
public boolean foundInJar(Bundle bundle, String jarName, ZipEntry entry, InputStream in) throws Exception {
URL jarURL = bundle.getEntry(jarName);
URL url = new URL("jar:" + jarURL.toString() + "!/" + entry.getName());
resources.add(url);
return true;
}
代码示例来源:origin: org.nuxeo.ecm.webengine/nuxeo-webengine-jaxrs
public static URL resolveResourceFromBundle(Bundle bundle, String name) throws ViewNotFoundException {
URL url = bundle.getEntry(name);
if (url == null) {
throw new ViewNotFoundException(null, bundle, name);
}
return url;
}
代码示例来源:origin: org.apache.geronimo.modules/geronimo-openejb
public boolean foundInJar(Bundle bundle, String jarName, ZipEntry entry, InputStream in) throws Exception
{
URL jarURL = bundle.getEntry(jarName);
URL beansUrl = new URL("jar:" + jarURL.toString() + "!/" + entry.getName());
logger.info("adding the following beans.xml URL: " + beansUrl);
beanXMLs.add(beansUrl);
beanArchiveJarNames.add(jarName);
return true;
}
代码示例来源:origin: org.eclipse.equinox/common
private static void addDevEntries(Bundle b, ArrayList classpath) {
if (!DevClassPathHelper.inDevelopmentMode())
return;
String[] binaryPaths = DevClassPathHelper.getDevClassPath(b.getSymbolicName());
for (int i = 0; i < binaryPaths.length; i++) {
URL classpathEntry = b.getEntry(binaryPaths[i]);
if (classpathEntry != null)
classpath.add(classpathEntry);
}
}
}
代码示例来源:origin: org.apache.xbean/xbean-bundleutils
public BundleJarEntry getBundleJarEntry(String name) {
URL url = bundle.getEntry(name);
if (url == null) {
return null;
}
return new BundleJarEntry(name, url, getManifestSafe());
}
代码示例来源:origin: org.eclipse/org.eclipse.datatools.connectivity.ui
private void processIconAttr() {
String iconAttr = mElement.getAttribute(ATTR_ICON);
if (iconAttr != null && iconAttr.trim().length() > 0) {
URL url = Platform.getBundle(
mElement.getContributor().getName()).getEntry(
iconAttr);
mIcon = ImageDescriptor.createFromURL(url);
}
else {
mIcon = ImageDescriptor.getMissingImageDescriptor();
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testStringsForResourcesInBundleWhenNoResources() throws Exception {
Bundle bundle = createMock(Bundle.class);
expect(bundle.getEntry("/META-INF/services/org.jclouds.apis.ApiMetadata")).andReturn(null);
replay(bundle);
assertEquals(Bundles.stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle),
ImmutableSet.of());
verify(bundle);
}
代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-test
public URL getBlobManagerContrib(FeaturesRunner runner) {
String bundleName = "org.nuxeo.ecm.core.test";
String contribPath = "OSGI-INF/test-storage-blob-contrib.xml";
RuntimeHarness harness = runner.getFeature(RuntimeFeature.class).getHarness();
Bundle bundle = harness.getOSGiAdapter().getRegistry().getBundle(bundleName);
URL contribURL = bundle.getEntry(contribPath);
assertNotNull("deployment contrib " + contribPath + " not found", contribURL);
return contribURL;
}
内容来源于网络,如有侵权,请联系作者删除!