本文整理汇总了Java中org.osgi.framework.Bundle.getEntry方法的典型用法代码示例。如果您正苦于以下问题:Java Bundle.getEntry方法的具体用法?Java Bundle.getEntry怎么用?Java Bundle.getEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.framework.Bundle
的用法示例。
在下文中一共展示了Bundle.getEntry方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIcons
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private void createIcons() {
icons = new HashMap<String, Image>(7);
final IConfigurationElement[] eles = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.scanning.api.generator");
for (IConfigurationElement e : eles) {
final String identity = e.getAttribute("id");
final String icon = e.getAttribute("icon");
if (icon !=null) {
final String cont = e.getContributor().getName();
final Bundle bundle= Platform.getBundle(cont);
final URL entry = bundle.getEntry(icon);
final ImageDescriptor des = ImageDescriptor.createFromURL(entry);
icons.put(identity, des.createImage());
}
}
}
示例2: addingBundle
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
@Override
public Boolean addingBundle(final Bundle bundle, final BundleEvent event) {
URL resource = bundle.getEntry("META-INF/services/" + ModuleFactory.class.getName());
LOG.trace("Got addingBundle event of bundle {}, resource {}, event {}", bundle, resource, event);
if (resource != null) {
try {
for (String factoryClassName : Resources.readLines(resource, StandardCharsets.UTF_8)) {
registerFactory(factoryClassName, bundle);
}
return Boolean.TRUE;
} catch (final IOException e) {
LOG.error("Error while reading {}", resource, e);
throw new RuntimeException(e);
}
}
return Boolean.FALSE;
}
示例3: resolveFile
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private static File resolveFile(String pluginName, String path) {
Bundle bundle = Platform.getBundle(pluginName);
URL fileURL = bundle.getEntry(path);
try {
URL resolvedFileURL = FileLocator.toFileURL(fileURL);
URI resolvedURI = new URI(resolvedFileURL.getProtocol(), resolvedFileURL.getPath(), null);
return new File(resolvedURI);
} catch (URISyntaxException | IOException e) {
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
}
return null;
}
示例4: resolveImage
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private static Image resolveImage(String pluginName, String path) {
Bundle bundle = Platform.getBundle(pluginName);
URL fileURL = bundle.getEntry(path);
try {
URL resolvedFileURL = FileLocator.toFileURL(fileURL);
return ImageDescriptor.createFromURL(resolvedFileURL).createImage();
} catch (IOException e) {
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
}
return null;
}
示例5: getTemplateURI
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
* Finds the template in the plug-in. Returns the template plug-in URI.
*
* @param bundleID
* is the plug-in ID
* @param relativePath
* is the relative path of the template in the plug-in
* @return the template URI
* @throws IOException
* @generated
*/
@SuppressWarnings("unchecked")
private URI getTemplateURI(String bundleID, IPath relativePath) throws IOException {
Bundle bundle = Platform.getBundle(bundleID);
if (bundle == null) {
// no need to go any further
return URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false);
}
URL url = bundle.getEntry(relativePath.toString());
if (url == null && relativePath.segmentCount() > 1) {
Enumeration<URL> entries = bundle.findEntries("/", "*.emtl", true);
if (entries != null) {
String[] segmentsRelativePath = relativePath.segments();
while (url == null && entries.hasMoreElements()) {
URL entry = entries.nextElement();
IPath path = new Path(entry.getPath());
if (path.segmentCount() > relativePath.segmentCount()) {
path = path.removeFirstSegments(path.segmentCount() - relativePath.segmentCount());
}
String[] segmentsPath = path.segments();
boolean equals = segmentsPath.length == segmentsRelativePath.length;
for (int i = 0; equals && i < segmentsPath.length; i++) {
equals = segmentsPath[i].equals(segmentsRelativePath[i]);
}
if (equals) {
url = bundle.getEntry(entry.getPath());
}
}
}
}
URI result;
if (url != null) {
result = URI.createPlatformPluginURI(new Path(bundleID).append(new Path(url.getPath())).toString(), false);
} else {
result = URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false);
}
return result;
}
示例6: bundleAdded
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private void bundleAdded(final Bundle bundle) {
URL resource = bundle.getEntry(serviceResourcePath);
if (resource == null) {
return;
}
LOG.debug("{}: Found {} resource in bundle {}", logName(), resource, bundle.getSymbolicName());
try {
for (String line : Resources.readLines(resource, StandardCharsets.UTF_8)) {
int ci = line.indexOf('#');
if (ci >= 0) {
line = line.substring(0, ci);
}
line = line.trim();
if (line.isEmpty()) {
continue;
}
String serviceType = line;
LOG.debug("{}: Retrieved service type {}", logName(), serviceType);
expectedServiceTypes.add(serviceType);
}
} catch (final IOException e) {
setFailure(String.format("%s: Error reading resource %s from bundle %s", logName(), resource,
bundle.getSymbolicName()), e);
}
}
示例7: findResources
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
@Override
protected Enumeration<URL> findResources(Module m, String resName) {
Bundle b = findBundle(m.getCodeNameBase());
URL u = b.getEntry(resName);
return u == null ? Enumerations.<URL>empty() : Enumerations.singleton(u);
}
示例8: testBundleResourceProtocol
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
@RandomlyFails
public void testBundleResourceProtocol() throws Exception {
ModuleSystem ms = Main.getModuleSystem();
ModuleManager mgr = ms.getManager();
mgr.mutexPrivileged().enterWriteAccess();
HashSet<Module> both = null;
try {
String mfBar = "Bundle-SymbolicName: org.bar\n" +
"Bundle-Version: 1.1.0\n" +
"Bundle-ManifestVersion: 2\n" +
"Export-Package: org.bar\n" +
"Require-Bundle: org.foo;bundle-version=\"[100.0,102.0)\"\n" +
"\n\n";
File j1 = new File(jars, "simple-module.jar");
File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
LOG.log(Level.INFO, "Create {0}", j2);
Module m1 = mgr.create(j1, null, false, false, false);
LOG.log(Level.INFO, "Create {0}", j2);
Module m2 = mgr.create(j2, null, false, false, false);
HashSet<Module> b = new HashSet<Module>(Arrays.asList(m1, m2));
LOG.log(Level.INFO, "enable {0}", b);
mgr.enable(b);
LOG.info("enabled Ok");
both = b;
Bundle bundle = NetigsoServicesTest.findBundle("org.foo");
LOG.log(Level.INFO, "bundle org.foo: {0}", bundle);
URL root = bundle.getEntry("/");
LOG.log(Level.INFO, "Root entry {0}", root);
assertNotNull("Root URL found", root);
URL resRoot = new URL("bundleresource", root.getHost(), root.getPath());
LOG.log(Level.INFO, "res root: {0}", resRoot);
URL helloRes = new URL(resRoot, "org/foo/hello.txt");
LOG.log(Level.INFO, "Assert content {0}", helloRes);
assertURLContent(helloRes, "Hello resources!");
} finally {
LOG.info("Finally block started");
if (both != null) {
mgr.disable(both);
}
mgr.mutexPrivileged().exitWriteAccess();
LOG.info("Finally block finished");
}
}
示例9: testActivation
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public void testActivation() throws Exception {
ModuleSystem ms = Main.getModuleSystem();
mgr = ms.getManager();
mgr.mutexPrivileged().enterWriteAccess();
Enumeration en;
int checks = 0;
System.setProperty("activated.checkentries", "/org/test/x.txt");
try {
m1 = mgr.create(simpleModule, null, false, false, false);
mgr.enable(m1);
Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
Object s = main.getField("start").get(null);
assertNotNull("Bundle started, its context provided", s);
BundleContext bc = (BundleContext)s;
StringBuilder sb = new StringBuilder();
for (Bundle b : bc.getBundles()) {
URL root = b.getEntry("/");
if (root == null) {
sb.append("No root URL for ").append(b.getSymbolicName()).append("\n");
}
en = b.findEntries("/", null, true);
if (en == null) {
sb.append("No entries for ").append(b.getSymbolicName()).append("\n");
continue;
}
while (en.hasMoreElements()) {
URL u = (URL) en.nextElement();
final String ef = u.toExternalForm();
int pref = ef.indexOf("/org/");
int last = ef.lastIndexOf("/");
if (pref != -1 && last != -1) {
String entry = ef.substring(pref + 1, last + 1);
assertTrue("/ is at the end", entry.endsWith("/"));
checks++;
final URL found = b.getEntry(entry);
assertNotNull("Entry found " + entry + " in " + b.getSymbolicName(), found);
URL notFound = b.getEntry("non/existent/entry/");
assertNull("Entries for non-existing entries are not found", notFound);
}
}
}
if (sb.length() > 0) {
fail(sb.toString());
}
if (checks == 0) {
fail("There shall be some checks for entries");
}
String text = System.getProperty("activated.entry");
assertEquals("Ahoj", text);
String localURL = System.getProperty("activated.entry.local");
assertNotNull("bundleentry read OK", localURL);
assertTrue("external file is referred as file:/.... = " + localURL, localURL.startsWith("file:/"));
assertEquals("Ahoj", readLine(localURL));
String fileURL = System.getProperty("activated.entry.file");
assertNotNull("fileURL found", fileURL);
assertTrue("file:/..... = " + fileURL, fileURL.startsWith("file:/"));
assertEquals("Ahoj", readLine(fileURL));
mgr.disable(m1);
Object e = main.getField("stop").get(null);
assertNotNull("Bundle stopped, its context provided", e);
} finally {
mgr.mutexPrivileged().exitWriteAccess();
}
}
示例10: getTemplateURI
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
* Finds the template in the plug-in. Returns the template plug-in URI.
*
* @param bundleID
* is the plug-in ID
* @param relativePath
* is the relative path of the template in the plug-in
* @return the template URI
* @throws IOException
* @generated
*/
@SuppressWarnings ( "unused" )
private URI getTemplateURI ( final String bundleID, final IPath relativePath ) throws IOException
{
final Bundle bundle = Platform.getBundle ( bundleID );
if ( bundle == null )
{
// no need to go any further
return URI.createPlatformResourceURI ( new Path ( bundleID ).append ( relativePath ).toString (), false );
}
URL url = bundle.getEntry ( relativePath.toString () );
if ( url == null && relativePath.segmentCount () > 1 )
{
final Enumeration<URL> entries = bundle.findEntries ( "/", "*.emtl", true );
if ( entries != null )
{
final String[] segmentsRelativePath = relativePath.segments ();
while ( url == null && entries.hasMoreElements () )
{
final URL entry = entries.nextElement ();
IPath path = new Path ( entry.getPath () );
if ( path.segmentCount () > relativePath.segmentCount () )
{
path = path.removeFirstSegments ( path.segmentCount () - relativePath.segmentCount () );
}
final String[] segmentsPath = path.segments ();
boolean equals = segmentsPath.length == segmentsRelativePath.length;
for ( int i = 0; equals && i < segmentsPath.length; i++ )
{
equals = segmentsPath[i].equals ( segmentsRelativePath[i] );
}
if ( equals )
{
url = bundle.getEntry ( entry.getPath () );
}
}
}
}
URI result;
if ( url != null )
{
result = URI.createPlatformPluginURI ( new Path ( bundleID ).append ( new Path ( url.getPath () ) ).toString (), false );
}
else
{
result = URI.createPlatformResourceURI ( new Path ( bundleID ).append ( relativePath ).toString (), false );
}
return result;
}
示例11: createConnectionActions
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private void createConnectionActions() {
connectors.clear();
String lastId = Activator.getDefault().getPreferenceStore().getString(DevicePreferenceConstants.STREAM_ID);
final IConfigurationElement[] eles = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.scanning.api.stream");
for (IConfigurationElement e : eles) {
CheckableActionGroup group = new CheckableActionGroup();
try {
final IStreamConnection<ILazyDataset> connection = (IStreamConnection<ILazyDataset>)e.createExecutableExtension("stream");
connectors.add(connection);
connection.setId(e.getAttribute("id"));
connection.setLabel(e.getAttribute("label"));
final String iconPath = e.getAttribute("icon");
ImageDescriptor icon=null;
if (iconPath!=null) {
final String id = e.getContributor().getName();
final Bundle bundle= Platform.getBundle(id);
final URL entry = bundle.getEntry(iconPath);
icon = ImageDescriptor.createFromURL(entry);
}
final MenuAction menu = new MenuAction(connection.getLabel());
final IAction connect = new Action(connection.getLabel(), IAction.AS_CHECK_BOX) {
@Override
public void run() {
connect(connection);
}
};
connect.setImageDescriptor(icon);
connect.setChecked(lastId!=null && lastId.equals(connection.getId()));
group.add(connect);
menu.add(connect);
menu.setSelectedAction(connect);
final IAction configure = new Action("Configure...") {
@Override
public void run() {
configure(connection);
}
};
menu.add(configure);
getViewSite().getActionBars().getToolBarManager().add(menu);
} catch (Exception ne) {
logger.error("Problem creating stream connection for "+e, ne);
}
getViewSite().getActionBars().getToolBarManager().add(new Separator());
}
}
示例12: tstGetEntryOnMetaInfEntryOnSystemBundle
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public void tstGetEntryOnMetaInfEntryOnSystemBundle() throws Exception {
Bundle sysBundle = bundleContext.getBundle(0);
URL url = sysBundle.getEntry("/META-INF");
assertNotNull("system bundle doesn't consider META-INF on classpath", url);
}