org.osgi.framework.Bundle#getEntry ( )源码实例Demo

下面列出了org.osgi.framework.Bundle#getEntry ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: incubator-tamaya   文件: OSGIServiceLoader.java
private void checkAndLoadBundle(Bundle bundle) {
    if (bundle.getEntry(META_INF_SERVICES) == null) {
        return;
    }
    synchronized (resourceBundles) {
        resourceBundles.add(bundle);
        LOG.info("Registered ServiceLoader bundle: " + bundle.getSymbolicName());
    }
    Enumeration<String> entryPaths = bundle.getEntryPaths(META_INF_SERVICES);
    while (entryPaths.hasMoreElements()) {
        String entryPath = entryPaths.nextElement();
        if (!entryPath.endsWith("/")) {
            processEntryPath(bundle, entryPath);
        }
    }
}
 
源代码2 项目: translationstudio8   文件: DBConfig.java
public DBConfig(URL dbconfig, MetaData metaData){
	this.metaData = metaData;
	try {
		SAXReader reader = new SAXReader();
		Document doc = reader.read(dbconfig);
		root = doc.getRootElement();
		
		Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
		URL defaultUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
		SAXReader defaultReader = new SAXReader();
		Document defaultDoc = defaultReader.read(defaultUrl);
		defaultRoot = defaultDoc.getRootElement();
	} catch (DocumentException e) {
		logger.warn("", e);
	}
}
 
/**
 * Loads the hover style sheet.
 */
protected static String loadStyleSheet(String cssPath)
{
	Bundle bundle = Platform.getBundle(UIEplPlugin.PLUGIN_ID);
	if (bundle == null)
	{
		return StringUtil.EMPTY;
	}
	URL styleSheetURL = bundle.getEntry(cssPath);
	if (styleSheetURL != null)
	{
		try
		{
			return IOUtil.read(styleSheetURL.openStream());
		}
		catch (IOException ex)
		{
			IdeLog.logError(UIEplPlugin.getDefault(), "Documentation hover - Error loading the style-sheet", ex); //$NON-NLS-1$
			return StringUtil.EMPTY;
		}
	}
	return StringUtil.EMPTY;
}
 
源代码4 项目: tmxeditor8   文件: OperateSystemDBImpl.java
public OperateSystemDBImpl(){
	metaData = new MetaDataImpl();
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
	metaData.setServerName(dbConfig.getDefaultServer());
	metaData.setPort(dbConfig.getDefaultPort());
	metaData.setDbType(dbConfig.getDefaultType());
}
 
源代码5 项目: packagedrone   文件: BundleInformation.java
public BundleInformation ( final Bundle bundle )
{
    this.bundle = bundle;
    this.bundleRevision = bundle.adapt ( BundleRevision.class );

    this.aboutHtml = bundle.getEntry ( "about.html" );
    this.licenseTxt = bundle.getEntry ( "META-INF/LICENSE.txt" );
    this.noticeTxt = bundle.getEntry ( "META-INF/NOTICE.txt" );

    this.licenses = LicenseInformation.parse ( bundle.getHeaders ().get ( Constants.BUNDLE_LICENSE ) );
}
 
源代码6 项目: statecharts   文件: TestFileCopier.java
public void copyFolderFromBundleToFolder(Bundle bundle, String sourcePath, String targetPath) {
	try {
		URL folder = bundle.getEntry(sourcePath);
		File file = new File(FileLocator.resolve(folder).toURI());
		if (file.exists() && file.isDirectory()) {
			for (File f : file.listFiles()) {
				copyFileFromBundleToFolder(bundle, new Path(sourcePath).append(f.getName()), new Path(targetPath));
			}
		}
	} catch (URISyntaxException | IOException e) {
		throw new RuntimeException(e);
	}
}
 
源代码7 项目: translationstudio8   文件: PluginUtil.java
/**
 * 根据相对路径获取绝对路径
 * @param relativePath
 * @return ;
 */
public static String getAbsolutePath(String relativePath) {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL defaultUrl = buddle.getEntry(relativePath);
	String imagePath = relativePath;
	try {
		imagePath = new File(FileLocator.toFileURL(defaultUrl).getPath()).getAbsolutePath();
	} catch (IOException e) {
		LOGGER.error(Messages.getString("util.PluginUtil.logger1"), e);
		e.printStackTrace();
	}
	return imagePath;
}
 
源代码8 项目: birt   文件: EclipsePlatform.java
/**
 * setup logger used for tracing.
 * 
 * It reads ".options" in the plugin folder to get all the tracing items,
 * call the .getDebugOptions() to get the option values and setup the logger
 * use the values.
 * 
 * @param pluginId
 *            plugin id
 */
public void initializeTracing( String pluginId )
{

	Bundle bundle = org.eclipse.core.runtime.Platform.getBundle( pluginId );
	String debugFlag = pluginId + "/debug";
	if ( bundle != null )
	{

		try
		{
			URL optionUrl = bundle.getEntry( ".options" );
			InputStream in = optionUrl.openStream( );
			if ( in != null )
			{
				Properties options = new Properties( );
				options.load( in );
				Iterator entryIter = options.entrySet( ).iterator( );
				while ( entryIter.hasNext( ) )
				{
					Map.Entry entry = (Map.Entry) entryIter.next( );
					String option = (String) entry.getKey( );
					if ( !debugFlag.equals( option ) )
					{
						String value = org.eclipse.core.runtime.Platform
								.getDebugOption( option );
						setupLogger( option, value );
					}
				}
			}
		}
		catch ( Exception ex )
		{
			logger.log( Level.WARNING, ex.getMessage( ), ex );
		}
	}
}
 
源代码9 项目: translationstudio8   文件: OperateDBImpl.java
public OperateDBImpl() {
	metaData = new MetaDataImpl();
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
	metaData.setServerName(dbConfig.getDefaultServer());
	metaData.setPort(dbConfig.getDefaultPort());
	metaData.setDbType(dbConfig.getDefaultType());
}
 
源代码10 项目: tmxeditor8   文件: OperateDBImpl.java
public OperateDBImpl() {
	metaData = new MetaDataImpl();
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
	metaData.setServerName(dbConfig.getDefaultServer());
	metaData.setPort(dbConfig.getDefaultPort());
	metaData.setDbType(dbConfig.getDefaultType());
}
 
源代码11 项目: tmxeditor8   文件: OperateSystemDBImpl.java
public OperateSystemDBImpl() {
	metaData = new MetaDataImpl();
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
	metaData.setDbType(dbConfig.getDefaultType());
}
 
源代码12 项目: birt   文件: FontMappingManagerFactory.java
protected URL getConfigURL( String configName )
{
	// try to load the format specific configuration
	String fileName = configName + ".xml";
	Bundle bundle = Platform
			.getBundle( "org.eclipse.birt.report.engine.fonts" ); //$NON-NLS-1$
	if ( bundle != null )
	{
		return bundle.getEntry( fileName );
	}
	return getClass( ).getClassLoader( ).getResource( fileName );
}
 
源代码13 项目: tmxeditor8   文件: TMDatabaseImpl.java
/**
 * 构造函数
 */
public TMDatabaseImpl() {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
}
 
源代码14 项目: translationstudio8   文件: TMDatabaseImpl.java
/**
 * 构造函数
 */
public TMDatabaseImpl() {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
}
 
源代码15 项目: tmxeditor8   文件: TMDatabaseImpl.java
public TMDatabaseImpl() {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
}
 
源代码16 项目: netbeans   文件: Netigso.java
@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);
}
 
源代码17 项目: incubator-tamaya   文件: OSGIServiceLoader.java
private void processEntryPath(Bundle bundle, String entryPath) {
    try {
        String serviceName = entryPath.substring(META_INF_SERVICES.length());
        if (!serviceName.startsWith("org.apache.tamaya")) {
            // Ignore non Tamaya entries...
            return;
        }
        Class<?> serviceClass = bundle.loadClass(serviceName);
        URL child = bundle.getEntry(entryPath);
        InputStream inStream = child.openStream();
        LOG.info("Loading Services " + serviceClass.getName() + " from bundle...: " + bundle.getSymbolicName());
        try (BufferedReader br = new BufferedReader(new InputStreamReader(inStream, StandardCharsets.UTF_8))) {
            String line = br.readLine();
            while (line != null) {
                String implClassName = getImplClassName(line);
                if (implClassName.length() > 0) {
                    try {
                        // Load the service class
                        LOG.fine("Loading Class " + implClassName + " from bundle...: " + bundle.getSymbolicName());
                        Class<?> implClass = bundle.loadClass(implClassName);
                        if (!serviceClass.isAssignableFrom(implClass)) {
                            LOG.warning("Configured service: " + implClassName + " is not assignable to "
                                    + serviceClass.getName());
                            continue;
                        }
                        LOG.info("Loaded Service Factory (" + serviceName + "): " + implClassName);
                        // Provide service properties
                        Hashtable<String, String> props = new Hashtable<>();
                        props.put(Constants.VERSION_ATTRIBUTE, bundle.getVersion().toString());
                        String vendor = bundle.getHeaders().get(Constants.BUNDLE_VENDOR);
                        props.put(Constants.SERVICE_VENDOR, (vendor != null ? vendor : "anonymous"));
                        // Translate annotated @Priority into a service ranking
                        props.put(Constants.SERVICE_RANKING,
                                String.valueOf(PriorityServiceComparator.getPriority(implClass)));

                        // Register the service factory on behalf of the intercepted bundle
                        JDKUtilServiceFactory factory = new JDKUtilServiceFactory(implClass);
                        BundleContext bundleContext = bundle.getBundleContext();
                        bundleContext.registerService(serviceName, factory, props);
                        LOG.info("Registered Tamaya service class: " + implClassName + "(" + serviceName + ")");
                    } catch (NoClassDefFoundError | Exception err) {
                        LOG.log(Level.SEVERE, "Failed to load service: " + implClassName, err);
                    }
                }
                line = br.readLine();
            }
        }
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Failed to read services from: " + entryPath, e);
    }
}
 
源代码18 项目: tmxeditor8   文件: TMDatabaseImpl.java
/**
 * 构造函数
 */
public TMDatabaseImpl() {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
}
 
源代码19 项目: mobi   文件: AuthHttpContext.java
@Override
public URL getResource(String name) {
    final String normalizedName = normalizeResourcePath(rootPath + (name.startsWith("/") ? "" : "/") + name).trim();

    log.debug(String.format("Searching bundle " + bundle + " for resource [%s], normalized to [%s]",
            name, normalizedName));

    URL url = resourceCache.get(normalizedName);

    if (url == null && !normalizedName.isEmpty()) {
        url = bundle.getEntry(normalizedName);
        if (url == null) {
            log.debug("getEntry failed, trying with /META-INF/resources/ in bundle class space");
            // Search attached bundles for web-fragments
            Set<Bundle> bundlesInClassSpace = getBundlesInClassSpace(bundle, new HashSet<>());
            for (Bundle bundleInClassSpace : bundlesInClassSpace) {
                url = bundleInClassSpace.getEntry("/META-INF/resources/" + normalizedName);
                if (url != null) {
                    break;
                }
            }
        }
        // obviously still not found might be available from a attached bundle resource
        if (url == null) {
            log.debug("getEntry failed, fallback to getResource");
            url = bundle.getResource(normalizedName);
        }
        if (url == null) {
            log.debug("getResource failed, fallback to system bundle getResource");
            url = bundle.getClass().getClassLoader().getResource(normalizedName);
        }
        if (url == null) {
            url = NO_URL;
        }
        resourceCache.putIfAbsent(normalizedName, url);
    }

    if (url != null && url != NO_URL) {
        log.debug(String.format("Resource found as url [%s]", url));
    } else {
        log.debug("Resource not found");
        url = null;
    }
    return url;
}
 
源代码20 项目: packagedrone   文件: BundleResourceProvider.java
@Override
public URL getResource ( final String name )
{
    if ( !name.startsWith ( "/bundle/" ) )
    {
        return null;
    }

    final String toks[] = name.split ( "/", 4 );

    if ( toks.length != 4 )
    {
        logger.debug ( "Invalid format: {}", new Object[] { toks } );
        return null;
    }

    if ( !toks[1].equals ( "bundle" ) )
    {
        return null;
    }

    final long bundleId;
    try
    {
        bundleId = Long.parseLong ( toks[2] );
    }
    catch ( final NumberFormatException e )
    {
        logger.debug ( "Failed to parse bundle id", e );
        return null;
    }

    final Bundle bundle = findBundle ( bundleId );
    logger.trace ( "Target bundle: {}", bundle );
    if ( bundle == null )
    {
        return null;
    }

    final URL result = bundle.getEntry ( toks[3] );
    logger.trace ( "Resource entry ({}): {}", toks[3], result );
    if ( result == null )
    {
        return null;
    }

    logger.debug ( "Requesting resource: {}", result );

    return result;
}