當前位置: 首頁>>代碼示例>>Java>>正文


Java BundleWiring.listResources方法代碼示例

本文整理匯總了Java中org.osgi.framework.wiring.BundleWiring.listResources方法的典型用法代碼示例。如果您正苦於以下問題:Java BundleWiring.listResources方法的具體用法?Java BundleWiring.listResources怎麽用?Java BundleWiring.listResources使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.osgi.framework.wiring.BundleWiring的用法示例。


在下文中一共展示了BundleWiring.listResources方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isRequiredBundle

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
/**
 * Checks if is required bundle.
 *
 * @param bundle the bundle
 * @param className the class name
 * @return true, if is required bundle
 */
private boolean isRequiredBundle(Bundle bundle, String className) {
	
	// --- 1. Simply try to load the class ----------------------
	try {
		Class<?> classInstance = bundle.loadClass(className);
		if (classInstance!=null)  return true;
	
	} catch (ClassNotFoundException cnfEx) {
		//cnfEx.printStackTrace();
	}
	
	// --- 2. Try to check the resources of the bundle ----------
	String simpleClassName = className.substring(className.lastIndexOf(".")+1);
	String packagePath = className.substring(0, className.lastIndexOf("."));
	packagePath = packagePath.replace(".", "/");
	if (packagePath.startsWith("/")==false) packagePath = "/" + packagePath;
	if (packagePath.endsWith("/")  ==false) packagePath = packagePath + "/";
	
	BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
	Collection<String> resources = bundleWiring.listResources(packagePath, simpleClassName + ".class", BundleWiring.LISTRESOURCES_LOCAL);
	if (resources!=null && resources.size()>0) {
		return true;
	}
	return false;
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:33,代碼來源:AbstractClassLoadServiceUtilityImpl.java

示例2: findSubTypesOf

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
<T> List<Class<? extends T>> findSubTypesOf(Bundle bundle, Collection<Class<T>> superclasses) {
    BundleWiring wiring = bundle.adapt(BundleWiring.class);
    Collection<String> names = wiring
            .listResources("/", "*", BundleWiring.LISTRESOURCES_RECURSE);
    return names.stream().map(new Function<String, Class<?>>() {
        @Override @SneakyThrows
        public Class<?> apply(String name) {
            String n = name.replaceAll("\\.class$", "").replace('/', '.');
            try {
                return bundle.loadClass(n);
            } catch (ClassNotFoundException | NoClassDefFoundError e) {
                return null;
            }
        }
    }).filter(c -> c != null)
                .filter(c -> superclasses.stream().anyMatch(sc -> sc.isAssignableFrom(c)))
                .filter(c -> c.isAnnotationPresent(GraphQLMutation.class))
                .filter(c -> !c.isInterface() && !Modifier.isAbstract(c.getModifiers()))
                .map((Function<Class<?>, Class<? extends T>>) aClass -> (Class<? extends T>) aClass)
                .collect(Collectors.toList());
}
 
開發者ID:eventsourcing,項目名稱:es4j-graphql,代碼行數:22,代碼來源:OSGiMutationProvider.java

示例3: getClassNames

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
static Set<String> getClassNames(Bundle bundle) {
    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
    if (bundleWiring == null)
        return Collections.emptySet();
    Collection<String> resources = bundleWiring.listResources("/", "*.class", BundleWiring.LISTRESOURCES_RECURSE);
    Set<String> classNamesOfCurrentBundle = new HashSet<>();
    for (String resource : resources) {
        URL localResource = bundle.getEntry(resource);
        // Bundle.getEntry() returns null if the resource is not located in the specific bundle
        if (localResource != null) {
            String className = resource.replaceAll("/", ".").replaceAll("^(.*?)(\\.class)$", "$1");
            classNamesOfCurrentBundle.add(className);
        }
    }

    return classNamesOfCurrentBundle;
}
 
開發者ID:andyphillips404,項目名稱:awplab-core,代碼行數:18,代碼來源:JacksonManagerService.java

示例4: findSubTypesOf

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
private <T> List<Class<? extends T>> findSubTypesOf(Bundle bundle, Collection<Class<T>> superclasses) {
    BundleWiring wiring = bundle.adapt(BundleWiring.class);
    Collection<String> names = wiring
            .listResources("/", "*", BundleWiring.LISTRESOURCES_RECURSE);
    return names.stream().map(new Function<String, Class<?>>() {
        @Override @SneakyThrows
        public Class<?> apply(String name) {
            String n = name.replaceAll("\\.class$", "").replace('/', '.');
            try {
                return bundle.loadClass(n);
            } catch (ClassNotFoundException | NoClassDefFoundError e) {
                return null;
            }
        }
    }).filter(c -> c != null).filter(c -> superclasses.stream().anyMatch(sc -> sc.isAssignableFrom(c)))
                .filter(c -> !c.isInterface() && !Modifier.isAbstract(c.getModifiers()))
                .map((Function<Class<?>, Class<? extends T>>) aClass -> (Class<? extends T>) aClass)
                .collect(Collectors.toList());
}
 
開發者ID:eventsourcing,項目名稱:es4j,代碼行數:20,代碼來源:OSGiEntitiesProvider.java

示例5: loadPrograms

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private List<QProgram> loadPrograms(Bundle bundle, String basePackage) {
	
	List<QProgram> programs = new ArrayList<>();
	
	BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
	for(String resource: bundleWiring.listResources(basePackage.replace('.', '/'), null, BundleWiring.LISTRESOURCES_LOCAL)) {
		Class<?> klass = null;
		try {
			String resourceURI = resource.replace(".class", "").replace('/', '.');
			if(resourceURI.contains("$"))
				continue;
			klass = bundle.loadClass(resourceURI);
		} catch (ClassNotFoundException e) {
			continue;
		}
		if(QCallableProgram.class.isAssignableFrom(klass) || klass.getAnnotation(Program.class) != null)
			programs.add(buildProgram(bundle, (Class<QCallableProgram>)klass));
	}
	
	return programs;
}
 
開發者ID:asupdev,項目名稱:asup,代碼行數:23,代碼來源:E4BundleManagerImpl.java

示例6: loadModules

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private List<QModule> loadModules(Bundle bundle, String basePackage) {
	
	List<QModule> modules = new ArrayList<>();
	
	BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
	for(String resource: bundleWiring.listResources(basePackage.replace('.', '/'), null, BundleWiring.LISTRESOURCES_LOCAL)) {
		Class<?> klass = null;
		try {
			klass = bundle.loadClass(resource.replace(".class", "").replace('/', '.'));
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			continue;
		}
		if(QCallableProgram.class.isAssignableFrom(klass) || klass.getAnnotation(Module.class) != null)
			modules.add(buildModule(bundle, (Class<QCallableProgram>)klass));
	}
	
	return modules;
}
 
開發者ID:asupdev,項目名稱:asup,代碼行數:21,代碼來源:E4BundleManagerImpl.java

示例7: findPrivates

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
private Set<BundlePackage> findPrivates(BundleWiring wiring, Set<BundlePackage> exports) {
	if (wiring.getBundle().getBundleId() == 0) {
		return Collections.emptySet();
	}
	// TODO JPMS-ISSUE-002: (Low Priority) Need to scan for private packages.
	// Can the Layer API be enhanced to map a classloader to a default module to use? 

	Set<BundlePackage> results = new HashSet<>();

	// Look for private packages.  Each private package needs to be known
	// to the JPMS otherwise the classes in them will be associated with the
	// unknown module.
	// Discover packages the hard way
	// TODO could look the Private-Package header bnd produces
	Collection<String> classes = wiring.listResources("/", "*.class", BundleWiring.LISTRESOURCES_LOCAL | BundleWiring.LISTRESOURCES_RECURSE);
	for (String path : classes) {
		int beginIndex = 0;
		if (path.startsWith("/")) {
			beginIndex = 1;
		}
		int endIndex = path.lastIndexOf('/');
		if (endIndex >= 0) {
			path = path.substring(beginIndex, endIndex);
			results.add(BundlePackage.createSimplePackage(path.replace('/', '.')));
		}
	}
	results.removeAll(exports);
	return results;
}
 
開發者ID:tjwatson,項目名稱:osgi-jpms-layer,代碼行數:30,代碼來源:BundleWiringPrivates.java

示例8: getReader

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
private static ModuleReader getReader(BundleWiring wiring) {
	// Pretty sure this never used, but it is possible the
	// jpms layer above would want to get resources out of modules
	// in the bundle layer.  This code would provide that access.  
	return new ModuleReader() {
		@Override
		public Optional<URI> find(String name) throws IOException {
			int lastSlash = name.lastIndexOf('/');
			String path;
			String filePattern;
			if (lastSlash > 0) {
				path = name.substring(0, lastSlash);
				filePattern = name.substring(lastSlash + 1);
			} else {
				path = "";
				filePattern = name;
			}
			Collection<String> resources = wiring.listResources(path, filePattern, BundleWiring.LISTRESOURCES_LOCAL);
			URI uri;
			try {
				uri = resources.isEmpty() ? null : wiring.getClassLoader().getResource(name).toURI();
			} catch (URISyntaxException e) {
				uri = null;
			}
			return Optional.ofNullable(uri);
		}
		
		@Override
		public void close() throws IOException {
		}

		@Override
		public Stream<String> list() throws IOException {
			return Stream.empty();
		}
	};
}
 
開發者ID:tjwatson,項目名稱:osgi-jpms-layer,代碼行數:38,代碼來源:NodeFinder.java

示例9: getResources

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
@Override
public Resource[] getResources(String locationPattern) throws IOException {
    if (locationPattern.startsWith("classpath*:")) {
        String pattern = Strings.removeFromStart(locationPattern, "classpath*:");
        int ls = pattern.lastIndexOf('/');
        String path = pattern.substring(0, ls+1);
        String file = pattern.substring(ls+1);
        if (!path.startsWith("/")) path = "/"+ path;
        if (path.endsWith("**/")) path = Strings.removeFromEnd(path, "**/");
        if (Strings.isBlank(file)) file = "*";
        
        Bundle bundle = getBundle();
        if (bundle!=null) {
            BundleWiring wiring = bundle.adapt(BundleWiring.class);

            Collection<String> result1 = wiring.listResources(path, file, BundleWiring.LISTRESOURCES_LOCAL | BundleWiring.LISTRESOURCES_RECURSE);
            List<String> result = MutableList.copyOf(result1);

            LOG.debug("Osgi resolver found "+result.size()+" match(es) for "+locationPattern+" ("+path+" "+file+"): "+result);

            Resource[] resultA = new Resource[result1.size()];
            for (int i=0; i<result1.size(); i++) {
                resultA[i] = new ClassPathResource(result.get(i), getClassLoader());
            }

            return resultA;
        } else {
            throw new IllegalStateException("No OSGi bundle found for "+this+"; is this class exported correctly in OSGi?");
        }
    } else {
        LOG.debug("OSGi resolver "+this+" does not know pattern ("+locationPattern+"); passing to super");
    }
    return super.getResources(locationPattern);
}
 
開發者ID:cloudsoft,項目名稱:brooklyn-tosca,代碼行數:35,代碼來源:OsgiAwarePathMatchingResourcePatternResolver.java

示例10: loadImplementationsInBundle

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
private void loadImplementationsInBundle(final Test test, final String packageName) {
    //Do not remove the cast on the next line as removing it will cause a compile error on Java 7.
    final BundleWiring wiring = (BundleWiring) FrameworkUtil.getBundle(
            ResolverUtil.class).adapt(BundleWiring.class);
    final Collection<String> list = wiring.listResources(packageName, "*.class",
        BundleWiring.LISTRESOURCES_RECURSE);
    for (final String name : list) {
        addIfMatching(test, name);
    }
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:11,代碼來源:ResolverUtil.java

示例11: loadImplementationsInBundle

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
private void loadImplementationsInBundle(final Test test, final String packageName) {
    final BundleWiring wiring = FrameworkUtil.getBundle(ResolverUtil.class).adapt(BundleWiring.class);
    final Collection<String> list = wiring.listResources(packageName, "*.class",
            BundleWiring.LISTRESOURCES_RECURSE);
    for (final String name : list) {
        addIfMatching(test, name);
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:9,代碼來源:ResolverUtil.java

示例12: getComboBoxModel

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
/**
 * Gets the combo box model for the versions.
 * @return the combo box model
 */
private DefaultComboBoxModel<String> getComboBoxModel() {

	// --- Set default combo box model --------------------------
	DefaultComboBoxModel<String> cbm = new DefaultComboBoxModel<String>();

	// --- Find all files in the package 'agentgui/ -------------
	Vector<String> versionSites = new Vector<String>();

	// --- Use BundleWiring to get the html-changes sites ------- 
	Bundle bundle = Platform.getBundle(BundleProperties.PLUGIN_ID);
	BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
	if (bundleWiring!=null) {
		Collection<String> sitesFound = bundleWiring.listResources(this.changeFilesPackage, "*.html", BundleWiring.LISTRESOURCES_LOCAL);
		versionSites.addAll(sitesFound);
	}
	
	if (versionSites!=null) {
		// --- Files found - get the version files -------------- 
		Vector<String> versionNumbers = new Vector<String>();
		for (int i = 0; i < versionSites.size(); i++) {
			String fileName = versionSites.get(i);
			if (fileName.endsWith(".html")) {
				int cut1 = fileName.indexOf("build") + 6;
				int cut2 = fileName.indexOf("changes") - 1;
				String versionNumber = fileName.substring(cut1, cut2);
				versionNumbers.addElement(versionNumber);
			}
		}
		// --- Sort result descending ---------------------------
		Collections.sort(versionNumbers, new Comparator<String>() {
			public int compare(String version1, String version2) {
				int compared = 0;
				Integer buildNo1 = Integer.parseInt(version1.substring(version1.indexOf("-")+1));
				Integer buildNo2 = Integer.parseInt(version2.substring(version2.indexOf("-")+1));
				compared = buildNo1.compareTo(buildNo2);
				return compared*-1;
			};
		});
		// --- Fill the combo box model -------------------------
		cbm = new DefaultComboBoxModel<String>(versionNumbers);
		
		// --- set the current file -----------------------------
		this.loadBuildChanges(versionNumbers.get(0));
	}
	return cbm;
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:51,代碼來源:ChangeDialog.java

示例13: listResources

import org.osgi.framework.wiring.BundleWiring; //導入方法依賴的package包/類
private Collection<String> listResources( String classPathRoot ) {
  BundleWiring bundleWiring = bundle.adapt( BundleWiring.class );
  int options = BundleWiring.LISTRESOURCES_LOCAL | BundleWiring.LISTRESOURCES_RECURSE;
  return bundleWiring.listResources( classPathRoot, "*" + DOT_CLASS, options );
}
 
開發者ID:rherrmann,項目名稱:osgi-testsuite,代碼行數:6,代碼來源:ClassPathScanner.java


注:本文中的org.osgi.framework.wiring.BundleWiring.listResources方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。