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


Java Bundle.findEntries方法代码示例

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


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

示例1: getConfigurations

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public String[] getConfigurations(Bundle bundle) {
	String[] locations = ConfigUtils.getHeaderLocations(bundle.getHeaders());

	// if no location is specified in the header, try the defaults
	if (ObjectUtils.isEmpty(locations)) {
		// check the default locations if the manifest doesn't provide any info
		Enumeration defaultConfig = bundle.findEntries(CONTEXT_DIR, CONTEXT_FILES, false);
		if (defaultConfig != null && defaultConfig.hasMoreElements()) {
			return new String[] { DEFAULT_CONFIG };
		}
		else {
			return new String[0];
		}
	}
	else {
		return locations;
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:19,代码来源:DefaultConfigurationScanner.java

示例2: isResolved

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private static boolean isResolved(Bundle b) {
    if (b.getState() == Bundle.INSTALLED) {
        // try to ask for a known resource which is known to resolve 
        // the bundle
        b.findEntries("META-INF", "MANIFEST.MF", false); // NOI18N
    }
    return b.getState() != Bundle.INSTALLED;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:Netigso.java

示例3: unpackBundle

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public static void unpackBundle(Bundle bundle, File targetFolder) {
	// no need to use a recursive method since we get all resources directly
	Enumeration enm = bundle.findEntries(SLASH, null, true);
	while (enm != null && enm.hasMoreElements()) {

		// get only the path
		URL url = (URL) enm.nextElement();
		String entryPath = url.getPath();
		if (entryPath.startsWith(SLASH))
			entryPath = entryPath.substring(1);

		File targetFile = new File(targetFolder, entryPath);
		// folder are a special case, we have to create them rather then copy
		if (entryPath.endsWith("/"))
			targetFile.mkdirs();
		else {
			try {
				File parent = targetFile.getParentFile();
				if (!parent.exists()) {
					parent.mkdirs();
				}
				System.out.println(parent);

				OutputStream targetStream = new FileOutputStream(targetFile);
				System.err.println("Copying " + url + " to " + targetFile);
				FileCopyUtils.copy(url.openStream(), targetStream);
			}
			catch (IOException ex) {
				//
				System.err.println("Cannot copy resource " + entryPath + ex);
				throw (RuntimeException) new IllegalStateException("IO exception while unpacking bundle "
						+ OsgiStringUtils.nullSafeNameAndSymName(bundle)).initCause(ex);
			}
			// no need to close the streams - the utils already handles that
		}
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:38,代码来源:OSGI723Test.java

示例4: isSpringDMManaged

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
 * Determines if the given bundle, is Spring DM managed or not. This method
 * is used at startup, for waiting on all Spring DM contexts to be properly
 * started and published.
 * 
 * @param bundle bundle to check
 * @return boolean true if spring managed or false.
 */
protected boolean isSpringDMManaged(Bundle bundle) {
	if (!ObjectUtils.isEmpty(ConfigUtils.getHeaderLocations(bundle.getHeaders()))) {
		return true;
       }
       // TODO: do we need to check for blueprint?
	Enumeration<URL> enm = bundle.findEntries("META-INF/spring", "*.xml", false);
	return (enm != null && enm.hasMoreElements());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:17,代码来源:AbstractSynchronizedOsgiTests.java

示例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;
}
 
开发者ID:occiware,项目名称:OCCI-Studio,代码行数:49,代码来源:GenerateAll.java

示例6: findBlueprintPaths

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
static List<Object> findBlueprintPaths(final Bundle bundle) {
    Enumeration<?> rntries = bundle.findEntries(BLUEPRINT_FILE_PATH, BLUEPRINT_FLE_PATTERN, false);
    if (rntries == null) {
        return Collections.emptyList();
    } else {
        return Collections.list((Enumeration)rntries);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:BlueprintBundleTracker.java

示例7: 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();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:74,代码来源:ExternalDirectoryTest.java

示例8: 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;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:60,代码来源:GenerateAll.java

示例9: tstFindEntriesOnMetaInfEntryOnSystemBundle

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public void tstFindEntriesOnMetaInfEntryOnSystemBundle() throws Exception {
	Bundle sysBundle = bundleContext.getBundle(0);
	Enumeration enm = sysBundle.findEntries("/", "META-INF", false);
	assertNotNull("system bundle doesn't return META-INF", enm);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:6,代码来源:BundleClassPathTest.java

示例10: maybeAddNamespaceHandlerFor

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
 * Registers the namespace plugin handler if this bundle defines handler mapping or schema mapping resources.
 * 
 * <p/> This method considers only the bundle space and not the class space.
 * 
 * @param bundle target bundle
 * @param isLazyBundle indicator if the bundle analyzed is lazily activated
 */
public void maybeAddNamespaceHandlerFor(Bundle bundle, boolean isLazyBundle) {
	// Ignore system bundle
	if (OsgiBundleUtils.isSystemBundle(bundle)) {
		return;
	}

	// Ignore non-wired Spring DM bundles
	if ("org.eclipse.gemini.blueprint.core".equals(bundle.getSymbolicName())
			&& !bundle.equals(BundleUtils.getDMCoreBundle(context))) {
		return;
	}

	boolean debug = log.isDebugEnabled();
	boolean trace = log.isTraceEnabled();
	// FIXME: Blueprint uber bundle temporary hack
	// since embedded libraries are not discovered by findEntries and inlining them doesn't work
	// (due to resource classes such as namespace handler definitions)
	// we use getResource

	boolean hasHandlers = false, hasSchemas = false;

	if (trace) {
		log.trace("Inspecting bundle " + bundle + " for Spring namespaces");
	}
	// extender/RFC 124 bundle
	if (context.getBundle().equals(bundle)) {

		try {
			Enumeration<?> handlers = bundle.getResources(META_INF + SPRING_HANDLERS);
			Enumeration<?> schemas = bundle.getResources(META_INF + SPRING_SCHEMAS);

			hasHandlers = handlers != null;
			hasSchemas = schemas != null;

			if (hasHandlers && debug) {
				log.debug("Found namespace handlers: " + Collections.list(schemas));
			}
		} catch (IOException ioe) {
			log.warn("Cannot discover own namespaces", ioe);
		}
	} else {
		hasHandlers = bundle.findEntries(META_INF, SPRING_HANDLERS, false) != null;
		hasSchemas = bundle.findEntries(META_INF, SPRING_SCHEMAS, false) != null;
	}

	// if the bundle defines handlers
	if (hasHandlers) {

		if (trace)
			log.trace("Bundle " + bundle + " provides Spring namespace handlers...");

		if (isLazyBundle) {
			this.namespacePlugins.addPlugin(bundle, isLazyBundle, true);
		} else {
			// check type compatibility between the bundle's and spring-extender's spring version
			if (hasCompatibleNamespaceType(bundle)) {
				this.namespacePlugins.addPlugin(bundle, isLazyBundle, false);
			} else {
				if (debug)
					log.debug("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle)
							+ "] declares namespace handlers but is not compatible with extender [" + extenderInfo
							+ "]; ignoring...");
			}
		}
	} else {
		// bundle declares only schemas, add it though the handlers might not be compatible...
		if (hasSchemas) {
			this.namespacePlugins.addPlugin(bundle, isLazyBundle, false);
			if (trace)
				log.trace("Bundle " + bundle + " provides Spring schemas...");
		}
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:82,代码来源:NamespaceManager.java

示例11: checkBundleForClass

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private static Version checkBundleForClass(Bundle bundle, String name, Version iversion) {
	String packageName = name.substring(0, name.lastIndexOf('.'));
	Version hasExport = hasExport(bundle, packageName);

	// log.info("Examining Bundle [" + bundle.getBundleId() + ": " + bname +
	// "]");
	// Check for version matching
	if (hasExport != null && !hasExport.equals(iversion)) {
		log.trace("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] exports [" + packageName
				+ "] as version [" + hasExport + "] but version [" + iversion + "] was required");
		return hasExport;
	}
	// Do more detailed checks
	String cname = name.substring(packageName.length() + 1) + ".class";
	Enumeration e = bundle.findEntries("/" + packageName.replace('.', '/'), cname, false);
	if (e == null) {
		if (hasExport != null) {
			URL url = checkBundleJarsForClass(bundle, name);
			if (url != null) {
				log.trace("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] contains [" + cname
						+ "] in embedded jar [" + url.toString() + "] but exports the package");
			}
			else {
				log.trace("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] does not contain ["
						+ cname + "] but exports the package");
			}
		}

		String root = "/";
		String fileName = packageName;
		if (packageName.lastIndexOf(".") >= 0) {
			root = root + packageName.substring(0, packageName.lastIndexOf(".")).replace('.', '/');
			fileName = packageName.substring(packageName.lastIndexOf(".") + 1).replace('.', '/');
		}
		Enumeration pe = bundle.findEntries(root, fileName, false);
		if (pe != null) {
			if (hasExport != null) {
				log.trace("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] contains package ["
						+ packageName + "] and exports it");
			}
			else {
				log.trace("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] contains package ["
						+ packageName + "] but does not export it");
			}

		}
	}
	// Found the resource, check that it is exported.
	else {
		if (hasExport != null) {
			log.trace("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] contains resource [" + cname
					+ "] and it is correctly exported as version [" + hasExport + "]");
			Class<?> c = null;
			try {
				c = bundle.loadClass(name);
			}
			catch (ClassNotFoundException e1) {
				// Ignored
			}
			log.trace("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] loadClass [" + cname
					+ "] returns [" + c + "]");
		}
		else {
			log.trace("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] contains resource [" + cname
					+ "] but its package is not exported");
		}
	}
	return hasExport;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:70,代码来源:DebugUtils.java

示例12: doRetrieveMatchingBundleEntries

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
 * Searches each level inside the bundle for entries based on the search strategy chosen.
 * 
 * @param bundle the bundle to do the lookup
 * @param fullPattern matching pattern
 * @param dir directory inside the bundle
 * @param result set of results (used to concatenate matching sub dirs)
 * @param searchType the search strategy to use
 * @throws IOException
 */
private void doRetrieveMatchingBundleEntries(Bundle bundle, String fullPattern, String dir, Set<Resource> result,
		int searchType) throws IOException {

	Enumeration<?> candidates;

	switch (searchType) {
	case OsgiResourceUtils.PREFIX_TYPE_NOT_SPECIFIED:
	case OsgiResourceUtils.PREFIX_TYPE_BUNDLE_SPACE:
		// returns an enumeration of URLs
		candidates = bundle.findEntries(dir, null, false);
		break;
	case OsgiResourceUtils.PREFIX_TYPE_BUNDLE_JAR:
		// returns an enumeration of Strings
		candidates = bundle.getEntryPaths(dir);
		break;
	case OsgiResourceUtils.PREFIX_TYPE_CLASS_SPACE:
		// returns an enumeration of URLs
		throw new IllegalArgumentException("class space does not support pattern matching");
	default:
		throw new IllegalArgumentException("unknown searchType " + searchType);
	}

	// entries are relative to the root path - miss the leading /
	if (candidates != null) {
		boolean dirDepthNotFixed = (fullPattern.indexOf(FOLDER_WILDCARD) != -1);
		while (candidates.hasMoreElements()) {
			Object path = candidates.nextElement();
			String currPath;

			if (path instanceof String)
				currPath = handleString((String) path);
			else
				currPath = handleURL((URL) path);

			if (!currPath.startsWith(dir)) {
				// Returned resource path does not start with relative
				// directory:
				// assuming absolute path returned -> strip absolute path.
				int dirIndex = currPath.indexOf(dir);
				if (dirIndex != -1) {
					currPath = currPath.substring(dirIndex);
				}
			}

			if (currPath.endsWith(FOLDER_SEPARATOR)
					&& (dirDepthNotFixed || StringUtils.countOccurrencesOf(currPath, FOLDER_SEPARATOR) < StringUtils
							.countOccurrencesOf(fullPattern, FOLDER_SEPARATOR))) {
				// Search subdirectories recursively: we manually get the
				// folders on only one level

				doRetrieveMatchingBundleEntries(bundle, fullPattern, currPath, result, searchType);
			}
			if (getPathMatcher().match(fullPattern, currPath)) {
				if (path instanceof URL)
					result.add(new UrlContextResource((URL) path, currPath));
				else
					result.add(new OsgiBundleResource(bundle, currPath));

			}
		}
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:73,代码来源:OsgiBundleResourcePatternResolver.java


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