本文整理了Java中org.osgi.framework.Bundle.getResource()
方法的一些代码示例,展示了Bundle.getResource()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bundle.getResource()
方法的具体详情如下:
包路径:org.osgi.framework.Bundle
类名称:Bundle
方法名:getResource
[英]Find the specified resource from this bundle's class loader. This bundle's class loader is called to search for the specified resource. If this bundle's state is INSTALLED, this method must attempt to resolve this bundle before attempting to get the specified resource. If this bundle cannot be resolved, then only this bundle must be searched for the specified resource. Imported packages cannot be searched when this bundle has not been resolved. If this bundle is a fragment bundle then null is returned.
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.
[中]从该捆绑包的类加载器中查找指定的资源。调用此捆绑包的类加载器来搜索指定的资源。如果此捆绑包的状态为已安装,则此方法必须在尝试获取指定资源之前尝试解析此捆绑包。如果无法解析此捆绑包,则必须仅在此捆绑包中搜索指定的资源。未解析此捆绑包时,无法搜索导入的包。如果此捆绑包是片段捆绑包,则返回null。
注意:Jar和zip文件不需要包含目录条目。如果捆绑包内容不包含目录项,则不会返回指向目录项的URL。
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override protected URL findResource(String name) {
URL resource = bundle.getResource(name);
if (resource == null && clsLdr != null)
resource = clsLdr.getResource(name);
return resource;
}
代码示例来源:origin: DozerMapper/dozer
@Override
public URL loadResource(String uri) {
return context.getBundle().getResource(uri);
}
代码示例来源:origin: hawtio/hawtio
@Override
public String getResourceURL(long bundleID, String resource) {
Bundle b = bundleContext.getBundle(bundleID);
if (b == null)
throw new IllegalArgumentException("Not a valid bundle ID: " + bundleID);
URL res = b.getResource(resource);
if (res == null)
return null;
else
return res.toString();
}
}
代码示例来源:origin: hibernate/hibernate-orm
private InputStream openInputStream() {
try {
return persistenceBundle.getResource( resource ).openStream();
}
catch ( IOException e ) {
throw new PersistenceException(
"Unable to open an InputStream on the OSGi Bundle resource!",
e );
}
}
代码示例来源:origin: hibernate/hibernate-orm
for ( Bundle bundle : bundles ) {
try {
final URL resource = bundle.getResource( name );
if ( resource != null ) {
resourceCache.put( name, resource );
代码示例来源:origin: pentaho/pentaho-kettle
@Override
public URL getResource( final String name ) {
final String normalizedname = Path.normalizeResourcePath( name );
return getBundle().getResource( normalizedname );
}
代码示例来源:origin: apache/activemq
URL resource = wrapper.bundle.getResource(path);
if( resource == null ) {
continue;
代码示例来源:origin: org.osgi/org.osgi.compendium
/**
* Called when this bundle is started so the Framework can perform the
* bundle-specific activities necessary to start this bundle. This method
* can be used to register services or to allocate any resources that this
* bundle needs.
*
* <p>
* This method must complete and return to its caller in a timely manner.
*
* <p>
* This method attempts to register a SAX and DOM parser with the
* Framework's service registry.
*
* @param context The execution context of the bundle being started.
* @throws java.lang.Exception If this method throws an exception, this
* bundle is marked as stopped and the Framework will remove this
* bundle's listeners, unregister all services registered by this
* bundle, and release all services used by this bundle.
*/
public void start(BundleContext context) throws Exception {
this.context = context;
Bundle parserBundle = context.getBundle();
// check for sax parsers
registerSAXParsers(getParserFactoryClassNames(parserBundle.getResource(SAXCLASSFILE)));
// check for dom parsers
registerDOMParsers(getParserFactoryClassNames(parserBundle.getResource(DOMCLASSFILE)));
}
代码示例来源:origin: DozerMapper/dozer
LOG.debug("Trying to locate [{}] via Bundle [{}]", xsdPath, bundle.getClass().getSimpleName());
url = bundle.getResource(xsdPath);
代码示例来源:origin: jersey/jersey
result.add(bundle.getResource(jarEntryName));
代码示例来源:origin: jersey/jersey
result.add(bundle.getResource(jarEntryName));
代码示例来源:origin: spring-projects/spring-roo
List<String> componentDescriptions = Arrays.asList(value.split("\\s*,\\s*"));
for (String desc : componentDescriptions) {
final URL url = bundle.getResource(desc);
process(url);
代码示例来源:origin: org.apache.felix/org.osgi.compendium
/**
* Called when this bundle is started so the Framework can perform the
* bundle-specific activities necessary to start this bundle. This method
* can be used to register services or to allocate any resources that this
* bundle needs.
*
* <p>
* This method must complete and return to its caller in a timely manner.
*
* <p>
* This method attempts to register a SAX and DOM parser with the
* Framework's service registry.
*
* @param context The execution context of the bundle being started.
* @throws java.lang.Exception If this method throws an exception, this
* bundle is marked as stopped and the Framework will remove this
* bundle's listeners, unregister all services registered by this
* bundle, and release all services used by this bundle.
*/
public void start(BundleContext context) throws Exception {
this.context = context;
Bundle parserBundle = context.getBundle();
// check for sax parsers
registerSAXParsers(getParserFactoryClassNames(parserBundle
.getResource(SAXCLASSFILE)));
// check for dom parsers
registerDOMParsers(getParserFactoryClassNames(parserBundle
.getResource(DOMCLASSFILE)));
}
代码示例来源:origin: eclipse-color-theme/eclipse-color-theme
.getName();
Bundle bundle = Platform.getBundle(contributorPluginId);
InputStream input = (InputStream) bundle.getResource(
xml).getContent();
((GenericMapper) mapper).parseMappings(input);
代码示例来源:origin: eclipse-color-theme/eclipse-color-theme
private void readStockThemes(Map<String, ColorTheme> themes) {
IConfigurationElement[] config = Platform.getExtensionRegistry()
.getConfigurationElementsFor(
Activator.EXTENSION_POINT_ID_THEME);
try {
for (IConfigurationElement e : config) {
String xml = e.getAttribute("file");
String contributorPluginId = e.getContributor().getName();
Bundle bundle = Platform.getBundle(contributorPluginId);
InputStream input = (InputStream) bundle.getResource(xml)
.getContent();
ParsedTheme theme = parseTheme(input, false);
amendThemeEntries(theme.getTheme().getEntries());
themes.put(theme.getTheme().getName(), theme.getTheme());
}
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: OpenNMS/opennms
private URL loadFromResources(String resourcePath) {
for (Bundle resourceBundle : resourceBundles) {
URL resourceUrl = resourceBundle.getResource(resourcePath);
if (null != resourceUrl)
return resourceUrl;
}
return null;
}
代码示例来源:origin: com.enonic.xp/core-api
@Override
public boolean exists()
{
return this.bundle.getResource( path ) != null;
}
代码示例来源:origin: OpenNMS/opennms
@Override
public URL getResource(String name)
{
if (name.startsWith("/")) {
name = name.substring(1);
}
return this.bundle.getResource(name);
}
代码示例来源:origin: org.jruby/jruby-complete
@Deprecated
private String createUri(Bundle cl, String ref) {
URL url = cl.getResource(ref);
if ( url == null && ref.startsWith( "/" ) ) {
url = cl.getResource( ref.substring( 1 ) );
}
if ( url == null ) {
throw new RuntimeException( "reference " + ref + " not found on classloader " + cl );
}
return "uri:" + url.toString().replaceFirst( ref + "$", "" );
}
/**
代码示例来源:origin: com.enonic.xp/core-api
@Override
public CharSource getCharSource()
{
final URL resource = this.bundle.getResource( this.path );
return Resources.asCharSource( resource, StandardCharsets.UTF_8 );
}
内容来源于网络,如有侵权,请联系作者删除!