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


Java SubTypesScanner類代碼示例

本文整理匯總了Java中org.reflections.scanners.SubTypesScanner的典型用法代碼示例。如果您正苦於以下問題:Java SubTypesScanner類的具體用法?Java SubTypesScanner怎麽用?Java SubTypesScanner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: GuiceApplication

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
protected GuiceApplication(String... basePackages) {
  final ConfigurationBuilder confBuilder = new ConfigurationBuilder();
  final FilterBuilder filterBuilder = new FilterBuilder();

  if (basePackages.length == 0) {
    basePackages = new String[] {};
  }

  logger.info("op=create, auto_scan_packages={}", (Object[]) basePackages);

  for (String pkg : basePackages) {
    confBuilder.addUrls(ClasspathHelper.forPackage(pkg));
    filterBuilder.include(FilterBuilder.prefix(pkg));
  }

  confBuilder.filterInputsBy(filterBuilder)
      .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());

  this.reflections = new Reflections(confBuilder);
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:21,代碼來源:GuiceApplication.java

示例2: prepareAndgetContextListener

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
/**
 * Prepares the logger context. Locates the context and
 * sets the configuration file.
 * @return the logger context
 */
private ServletContextListener prepareAndgetContextListener() {
    try {
        if (StringUtils.isNotBlank(this.loggerContextPackageName)) {
            final Collection<URL> set = ClasspathHelper.forPackage(this.loggerContextPackageName);
            final Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(set).setScanners(new SubTypesScanner()));
            final Set<Class<? extends ServletContextListener>> subTypesOf = reflections.getSubTypesOf(ServletContextListener.class);
            final ServletContextListener loggingContext = subTypesOf.iterator().next().newInstance();
            this.context.setInitParameter(this.logConfigurationField, this.logConfigurationFile.getURI().toString());
            return loggingContext;
        }
        return null;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:21,代碼來源:CasLoggerContextInitializer.java

示例3: getCasBannerInstance

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
/**
 * Gets cas banner instance.
 *
 * @return the cas banner instance
 */
public static Banner getCasBannerInstance() {
    final String packageName = CasEmbeddedContainerUtils.class.getPackage().getName();
    final Reflections reflections =
            new Reflections(new ConfigurationBuilder()
                    .filterInputsBy(new FilterBuilder().includePackage(packageName))
                    .setUrls(ClasspathHelper.forPackage(packageName))
                    .setScanners(new SubTypesScanner(true)));

    final Set<Class<? extends AbstractCasBanner>> subTypes = reflections.getSubTypesOf(AbstractCasBanner.class);
    subTypes.remove(DefaultCasBanner.class);
    
    if (subTypes.isEmpty()) {
        return new DefaultCasBanner();
    }
    try {
        final Class<? extends AbstractCasBanner> clz = subTypes.iterator().next();
        LOGGER.debug("Created banner [{}]", clz);
        return clz.newInstance();
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return new DefaultCasBanner();
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:29,代碼來源:CasEmbeddedContainerUtils.java

示例4: generateReport

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
public void generateReport(String packageName,List<String> flagList) throws IOException
{

    URL testClassesURL = Paths.get("target/test-classes").toUri().toURL();

    URLClassLoader classLoader = URLClassLoader.newInstance(new URL[]{testClassesURL},
            ClasspathHelper.staticClassLoader());

    reflections = new Reflections(new ConfigurationBuilder()
            .setUrls(ClasspathHelper.forPackage(packageName,classLoader))
            .addClassLoader(classLoader)
            .filterInputsBy(new FilterBuilder().includePackage(packageName))
            .setScanners(new MethodAnnotationsScanner(), new TypeAnnotationsScanner(), new SubTypesScanner())
    );


    List<Map<String, TestClass>> list = new ArrayList<>();

    for (String flag : flagList)
    {
        list.add(printMethods(flag));
    }

    Gson gson = new Gson();
    String overviewTemplate = IOUtils.toString(getClass().getResourceAsStream("/index.tpl.html"));


    String editedTemplate = overviewTemplate.replace("##TEST_DATA##", gson.toJson(list));

    FileUtils.writeStringToFile(new File("target/test-list-html-report/index.html"), editedTemplate);
    logger.info("report file generated");
}
 
開發者ID:cyildirim,項目名稱:Lahiya,代碼行數:33,代碼來源:LahiyaTestCaseReport.java

示例5: ReflectionsServiceDiscovery

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
public ReflectionsServiceDiscovery(String resourceSearchPackages, JsonServiceLocator locator) {
	this.locator = locator;

	ConfigurationBuilder builder = new ConfigurationBuilder();

	PreconditionUtil.assertNotNull("no resourceSearchPackage configured", resourceSearchPackages);

	FilterBuilder filter = new FilterBuilder();
	for (String resourceSearchPackage : resourceSearchPackages.split(",")) {
		builder = builder.addUrls(ClasspathHelper.forPackage(resourceSearchPackage));
		filter.includePackage(resourceSearchPackage);
	}
	filter.includePackage(Repository.class.getPackage().getName());
	filter.includePackage(ResourceRepository.class.getPackage().getName());
	builder = builder.filterInputsBy(filter);

	builder = builder.addUrls(ClasspathHelper.forClass(Repository.class));
	builder = builder.addUrls(ClasspathHelper.forClass(ResourceRepository.class));
	builder = builder.addUrls(ClasspathHelper.forClass(ResourceRepositoryV2.class));

	builder = builder.setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner());
	reflections = new Reflections(builder);
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:24,代碼來源:ReflectionsServiceDiscovery.java

示例6: CommandHandler

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
public CommandHandler() {
  try {
    Set<URL> classPathList = new HashSet<>();
    classPathList.addAll(ClasspathHelper.forJavaClassPath());
    Set<Class<? extends Command>> result = new Reflections(
        new ConfigurationBuilder().setScanners(new SubTypesScanner()).setUrls(classPathList))
        .getSubTypesOf(Command.class);

    for (Class<? extends Command> c : result) {
      String[] categoryString = c.getPackage().toString().split("\\.");
      String category = categoryString[categoryString.length - 1];
      if (category.equalsIgnoreCase("commands")) {
        category = "default";
      }
      Command command = c.newInstance();
      command.getSettings().setCategory(category);
      commands.add(command);
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
開發者ID:Svetroid,項目名稱:Hobbes-v1,代碼行數:23,代碼來源:CommandHandler.java

示例7: concreteSubTypesOf

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
private static <T> List<Class<? extends T>> concreteSubTypesOf(final Class<? extends T> clazz) {
    final ConfigurationBuilder conf = new ConfigurationBuilder()
            .setUrls(ClasspathHelper.forClass(clazz))
            .setScanners(new SubTypesScanner(true));
    final Reflections reflections = new Reflections(conf);
    final List<Class<? extends T>> result = new ArrayList<>();
    for (final Class<? extends T> type : reflections.getSubTypesOf(clazz)) {
        if (type.isInterface()) {
            continue;
        }

        if (Modifier.isAbstract(type.getModifiers())) {
            continue;
        }

        result.add(type);
    }

    return result;
}
 
開發者ID:bblfsh,項目名稱:java-driver,代碼行數:21,代碼來源:GoGen.java

示例8: query

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
@Override
public List<TreeItem<Pair<AnnotatedElement, Object>>> query() {
    final List<TreeItem<Pair<AnnotatedElement, Object>>> results = new ArrayList<>();
    final Predicate<String> childPredicate = Pattern.compile("^" + (pakkage != null ? "\\." + pakkage.getName() : "") + REGEX_CHILD_SUFFIX).asPredicate();
    Arrays.asList(Package.getPackages()).stream().filter(p -> childPredicate.test(p.getName())).map(PackageTreeItem::new).forEach(results::add);

    if (pakkage != null) {
        final Reflections reflections = new Reflections(pakkage.getName(), new SubTypesScanner(false));
        reflections.getStore().getSubTypesOf(Object.class.getName()).stream().map(s -> {
            try {
                return Class.forName(s);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            return null;
        }).map(c -> ((QueriableTreeItem) new ReflectiveTreeItem.StaticReflectiveTreeItem(c))).filter(qti -> !qti.query().isEmpty()).forEach(results::add);
    }
    return results;
}
 
開發者ID:ivan-gomes,項目名稱:runtime-explorer,代碼行數:20,代碼來源:PackageTreeItem.java

示例9: doPackage

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
private void doPackage(FilterBuilder fb, List<RuleFactory> resultL) throws Exception {
    List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
    classLoadersList.add(ClasspathHelper.contextClassLoader());
    classLoadersList.add(ClasspathHelper.staticClassLoader());

    Reflections reflections = new Reflections(new ConfigurationBuilder()
        .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
        .setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
        .filterInputsBy(fb));      
    
    Set<Class<? extends RuleFactory>> subTypes = reflections.getSubTypesOf(RuleFactory.class);        
    for(Class<? extends RuleFactory> clazz : subTypes) {
        RuleFactory factory = clazz.newInstance();
        resultL.add(factory);
    }
}
 
開發者ID:ianrae,項目名稱:dnal-lang,代碼行數:17,代碼來源:RuleFactoryFinder.java

示例10: testReflections

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
@Test
public void testReflections() throws Exception {
    List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
    classLoadersList.add(ClasspathHelper.contextClassLoader());
    classLoadersList.add(ClasspathHelper.staticClassLoader());

    String packageName = "org.dnal.core.world";
    Reflections reflections = new Reflections(new ConfigurationBuilder()
        .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
        .setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
        .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packageName))));      
    
    Set<String> types = reflections.getAllTypes();
    for(String s : types) {
        System.out.println(s);
    }

    Set<Class<? extends RuleFactory>> subTypes = reflections.getSubTypesOf(RuleFactory.class);        
    for(Class<? extends RuleFactory> clazz : subTypes) {
        System.out.println("sub: " + clazz.getName());
        RuleFactory factory = clazz.newInstance();
        RuleDeclaration decl = factory.getDeclaration();
        System.out.println("d: " + decl.ruleName);
    }
    
}
 
開發者ID:ianrae,項目名稱:dnal-lang,代碼行數:27,代碼來源:ReflectionTests.java

示例11: BeanScanner

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
public BeanScanner(final BeanManagerImpl beanManager, final ClassLoader classLoader, final String packageToScan)
{
    this.beanManager = beanManager;
    final ConfigurationBuilder config = new ConfigurationBuilder();

    config.setClassLoaders(new ClassLoader[] {classLoader});
    config.setUrls(ClasspathHelper.forPackage(packageToScan, classLoader));
    if (StringUtils.isNotEmpty(packageToScan))
    {
        config.filterInputsBy(new FilterBuilder().includePackage(packageToScan));
    }
    config.useParallelExecutor();
    config.setScanners(new SubTypesScanner(false));

    this.reflections = new Reflections(config);
}
 
開發者ID:Diorite,項目名稱:Diorite-old,代碼行數:17,代碼來源:BeanScanner.java

示例12: findAllPackagesStartingWith

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
/**
 * Finds all package names starting with prefix
 * @param prefix The package in which to start searching
 * @param statik True to statically return components names
 * @return a set of component name
 */
public List<String> findAllPackagesStartingWith(final String prefix, final boolean statik) {
    final List<ClassLoader> classLoadersList = new ArrayList<>();
    classLoadersList.add(ClasspathHelper.contextClassLoader());

    Reflections reflections = new Reflections(new ConfigurationBuilder()
            .setScanners(new SubTypesScanner(false), new ResourcesScanner())
            .setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[classLoadersList.size()])))
            .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(prefix))));
    Set<Class<?>> classes = reflections.getSubTypesOf(Object.class);

    final Set<String> packages = new HashSet<>();
    for (final Class classInstance : classes) {
        String packageName = classInstance.getPackage().getName();
        packageName = packageName.split("\\.")[packageName.split("\\.").length-1].toLowerCase();
        packages.add(packageName);
    }
    return new ArrayList<>(packages);
}
 
開發者ID:StephaneMangin,項目名稱:Synth,代碼行數:25,代碼來源:CoreController.java

示例13: getPackageTypes

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
private static Collection<? extends Class<?>> getPackageTypes(String packageToPase, Collection<URL> urls) {
    Set<Class<?>> classes = new HashSet<>();
    Reflections reflections = new Reflections(new ConfigurationBuilder()
            .setScanners(new SubTypesScanner(false /* exclude Object.class */), new ResourcesScanner(), new TypeElementsScanner())
            .setUrls(urls)
            .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packageToPase)).exclude("java.*")));

    Set<String> types;
    types = reflections.getStore().get("TypeElementsScanner").keySet();
    for (String type: types) {
        Class<?> aClass = TypesHelper.loadClass(type, CLASS_LOADER);
        boolean wantedElement = StringUtils.startsWith(type, packageToPase);
        if (null != aClass && wantedElement) {
            logger.log(Level.INFO, "looking up for type: " + type);
            classes.add(aClass);
        }
    }
    return classes;
}
 
開發者ID:juanmf,項目名稱:Java2PlantUML,代碼行數:20,代碼來源:Parser.java

示例14: scanForCommands

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
public static void scanForCommands() {
    //Populate all the cmds
    System.out.println("[EvenWurse] Reloading cmd list...");
    ArrayList<ClassLoader> classLoadersList = new ArrayList<>();
    classLoadersList.add(ClasspathHelper.contextClassLoader());
    classLoadersList.add(ClasspathHelper.staticClassLoader());
    Reflections reflections = new Reflections(
            new ConfigurationBuilder().setScanners(new SubTypesScanner(), new ResourcesScanner()).setUrls(
                    ClasspathHelper
                            .forClassLoader(classLoadersList.toArray(new ClassLoader[classLoadersList.size()]))));
    Set<Class<? extends Cmd>> classes = reflections.getSubTypesOf(Cmd.class);
    KNOWN_CMDS = new Class[classes.size()];
    for (int i = 0; i < classes.size(); i++) {
        KNOWN_CMDS[i] = (Class<? extends Cmd>) classes.toArray()[i];
        System.out.println("[EvenWurse] Found cmd: " + KNOWN_CMDS[i].getSimpleName() + "!");
    }
    System.out.println("[EvenWurse] Found " + KNOWN_CMDS.length + " cmds!");
}
 
開發者ID:null-dev,項目名稱:EvenWurse,代碼行數:19,代碼來源:CmdManager.java

示例15: scanForMods

import org.reflections.scanners.SubTypesScanner; //導入依賴的package包/類
public static void scanForMods() {
    //Populate all the mods
    System.out.println("[EvenWurse] Reloading mod list...");
    ArrayList<ClassLoader> classLoadersList = new ArrayList<>();
    classLoadersList.add(ClasspathHelper.contextClassLoader());
    classLoadersList.add(ClasspathHelper.staticClassLoader());
    Reflections reflections = new Reflections(
            new ConfigurationBuilder().setScanners(new SubTypesScanner(), new ResourcesScanner()).setUrls(
                    ClasspathHelper
                            .forClassLoader(classLoadersList.toArray(new ClassLoader[classLoadersList.size()]))));
    Set<Class<? extends Mod>> classes = reflections.getSubTypesOf(Mod.class);
    KNOWN_MODS = new Class[classes.size()];
    for (int i = 0; i < classes.size(); i++) {
        KNOWN_MODS[i] = (Class<? extends Mod>) classes.toArray()[i];
        System.out.println("[EvenWurse] Found mod: " + KNOWN_MODS[i].getSimpleName() + "!");
    }
    System.out.println("[EvenWurse] Found " + KNOWN_MODS.length + " mods!");
}
 
開發者ID:null-dev,項目名稱:EvenWurse,代碼行數:19,代碼來源:ModManager.java


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