/**
   * This processes the deployment dependencies, which are made available by the {@link
   * KieContainer} {@link ClassLoader}.
   *
   * @param kieContainer The {@link KieContainer}, used to get the {@link ClassLoader}
   * @param deployedUnit The {@link DeployedUnitImpl}, used to store the classes loaded
   */
  protected void processClassloader(KieContainer kieContainer, DeployedUnitImpl deployedUnit) {
    if (kieContainer.getClassLoader() instanceof ProjectClassLoader) {
      ClassLoader parentCl = kieContainer.getClassLoader().getParent();
      if (parentCl instanceof URLClassLoader) {
        URL[] urls = ((URLClassLoader) parentCl).getURLs();
        if (urls == null || urls.length == 0) {
          return;
        }
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.addUrls(urls);
        builder.addClassLoader(kieContainer.getClassLoader());

        Reflections reflections = new Reflections(builder);

        Set<Class<?>> xmlRootElemClasses = reflections.getTypesAnnotatedWith(XmlRootElement.class);
        Set<Class<?>> xmlTypeClasses = reflections.getTypesAnnotatedWith(XmlType.class);
        Set<Class<?>> remoteableClasses = reflections.getTypesAnnotatedWith(Remotable.class);

        Set<Class<?>> allClasses = new HashSet<Class<?>>();
        for (Set<Class<?>> classesToAdd :
            new Set[] {xmlRootElemClasses, xmlTypeClasses, remoteableClasses}) {
          if (classesToAdd != null) {
            allClasses.addAll(classesToAdd);
          }
        }

        for (Class<?> clazz : allClasses) {
          filterClassesAddedToDeployedUnit(deployedUnit, clazz);
        }
      }
    }
  }
 private Set<Class<?>> getAnnotatedClasses() {
   Reflections reflections;
   String classes = System.getProperty("operation_classes");
   if (classes != null) {
     String[] split = classes.split(",");
     Set<Class<?>> classSet = new HashSet<>(split.length);
     for (String className : split) {
       reflections = new Reflections(className);
       classSet.addAll(reflections.getTypesAnnotatedWith(OperationsClass.class));
     }
     return classSet;
   }
   reflections = new Reflections();
   return reflections.getTypesAnnotatedWith(OperationsClass.class);
 }
Beispiel #3
0
 public SlytherClient() {
   try {
     configuration = ConfigHandler.INSTANCE.readConfig(CONFIGURATION_FILE, ClientConfig.class);
     saveConfig();
   } catch (IOException e) {
     UIUtils.displayException("Unable to read config", e);
     Log.catching(e);
   }
   temporaryServerSelection = configuration.server;
   Reflections reflections = new Reflections("");
   Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Controller.class);
   for (Class<?> controller : annotated) {
     if (IController.class.isAssignableFrom(controller)) {
       try {
         Controller annotation = controller.getAnnotation(Controller.class);
         setController((IController) controller.getDeclaredConstructor().newInstance());
         Log.info("Using controller \"{}\" ({})", annotation.name(), controller.getSimpleName());
         break;
       } catch (Exception e) {
       }
     }
   }
   renderHandler = new RenderHandler(this);
   renderHandler.setup();
   setup();
 }
 @SuppressWarnings("unchecked") // apache commons collection api does not support generics
 public static Set<Class<? extends Page>> getAnnotatedWicketPage(
     String packageScanPath, Class<? extends Annotation> annotationClazz) {
   Reflections reflections = new Reflections(packageScanPath);
   return SetUtils.predicatedSet(
       reflections.getTypesAnnotatedWith(annotationClazz), PAGE_PREDICATE);
 }
  public static Set<Class<?>> getTypesAnnotatedWith(
      Class<? extends Annotation> annotation, ClassLoader... classLoaders) throws Exception {

    Set<Class<?>> implementations;
    implementations = (Set<Class<?>>) classesCache.get(annotation);

    ConfigurationBuilder cb =
        new ConfigurationBuilder()
            .setUrls(ClasspathHelper.forPackage("es.caib"))
            .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());

    if (classLoaders != null && classLoaders.length != 0) {
      cb.addClassLoaders(classLoaders);
    }

    if (implementations == null) {
      implementations = new HashSet<Class<?>>();
      Reflections ref = new Reflections(cb);

      Set<Class<?>> tmp = ref.getTypesAnnotatedWith(annotation);
      implementations.addAll(tmp);
      classesCache.put(annotation, implementations);
    }

    return implementations;
  }
  @Test
  public void jaxbClassesTest() throws Exception {
    Assume.assumeTrue(TestType.JAXB.equals(getType()));

    Set<Class<?>> jaxbClasses = reflections.getTypesAnnotatedWith(XmlRootElement.class);

    assertTrue("Not enough classes found! [" + jaxbClasses.size() + "]", jaxbClasses.size() > 20);

    String className = null;
    try {
      for (Class<?> jaxbClass : jaxbClasses) {
        if (jaxbClass.getDeclaringClass() != null
            && jaxbClass.getDeclaringClass().getSimpleName().endsWith("Test")) {
          continue;
        }
        className = jaxbClass.getName();
        Constructor<?> construct = jaxbClass.getConstructor(new Class[] {});
        Object jaxbInst = construct.newInstance(new Object[] {});
        testRoundTrip(jaxbInst);
      }
    } catch (Exception e) {
      e.printStackTrace();
      fail(className + ": " + e.getClass().getSimpleName() + " [" + e.getMessage() + "]");
    }
  }
Beispiel #7
0
  public List<VisTextButton> getButtons(Class<? extends Annotation> cls) {
    List<VisTextButton> btnList = new ArrayList<>();
    Reflections r = new Reflections("net.ncguy.impossible.graph.nodes");

    Set<Class<?>> clsSet = r.getTypesAnnotatedWith(cls);
    r.save("nodeBtns.bin");
    System.out.println("gfdsgfd");
    for (Class<?> c : clsSet) {
      VisTextButton btn = new VisTextButton("Add " + TextUtils.formatString(c.getSimpleName()));
      btn.addListener(
          new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
              super.clicked(event, x, y);
              try {
                BaseNode node = (BaseNode) c.getConstructor(GraphBase.class).newInstance(graphBase);
                addNode(node);
              } catch (Exception e) {
                e.printStackTrace();
              }
              graphBase.rebuildDnD();
            }
          });
      btnList.add(btn);
    }
    return btnList;
  }
 public Set<String> findServiceImplementations(
     Class<?> serviceClass, ClassLoader classpathResourceLoader) {
   return ImmutableSet.copyOf(
       transform(
           intersection(
               reflections.getTypesAnnotatedWith(markerAnnotation),
               reflections.getSubTypesOf(serviceClass)),
           new ClassToName()));
 }
  private List<Class<? extends Job>> getJobClasses(Class annotation) {
    Set<Class<? extends Job>> jobs =
        (Set<Class<? extends Job>>) reflections.getSubTypesOf(Job.class);
    Set<Class<?>> annotatedClasses = reflections.getTypesAnnotatedWith(annotation);

    return Sets.intersection(new HashSet<Class<? extends Job>>(jobs), annotatedClasses)
        .immutableCopy()
        .asList();
  }
  @Override
  public DioritePlugin loadPlugin(final File file) throws PluginException {
    try {
      final PluginClassLoader classLoader = new PluginClassLoader(file);

      final ConfigurationBuilder config = new ConfigurationBuilder();
      config.setClassLoaders(new PluginClassLoader[] {classLoader});
      config.setUrls(ClasspathHelper.forClassLoader(classLoader));

      final Reflections ref = new Reflections(config);
      final Set<Class<?>> annotated = ref.getTypesAnnotatedWith(Plugin.class);
      if (annotated.isEmpty()) {
        throw new PluginException("Plugin annotation doesn't found!");
      }
      if (annotated.size() > 1) {
        throw new PluginException("Plugin has more than one main class!");
      }

      final Class<?> mainClass = annotated.iterator().next();

      if (!DioritePlugin.class.isAssignableFrom(mainClass)) {
        throw new PluginException("Main class must extend PluginMainClass!");
      }

      final DioritePlugin dioritePlugin = (DioritePlugin) mainClass.newInstance();
      final Plugin pluginDescription = mainClass.getAnnotation(Plugin.class);

      if (ServerImpl.getInstance().getPluginManager().getPlugin(pluginDescription.name()) != null) {
        throw new PluginException("Plugin " + pluginDescription.name() + " is arleady loaded!");
      }

      dioritePlugin.init(
          classLoader,
          this,
          dioritePlugin,
          pluginDescription.name(),
          pluginDescription.version(),
          pluginDescription.author(),
          pluginDescription.description(),
          pluginDescription.website());
      System.out.println(
          "Loading "
              + pluginDescription.name()
              + " v"
              + pluginDescription.version()
              + " by "
              + pluginDescription.author()
              + " from file "
              + file.getName());
      dioritePlugin.onLoad();

      return dioritePlugin;
    } catch (final InstantiationException | IllegalAccessException | MalformedURLException e) {
      throw new PluginException("Exception while loading plugin from file " + file.getName(), e);
    }
  }
Beispiel #11
0
  /** 扫描基本信息 */
  private ScanStaticModel scanBasicInfo(List<String> packNameList) {

    ScanStaticModel scanModel = new ScanStaticModel();

    //
    // 扫描对象
    //
    Reflections reflections = getReflection(packNameList);
    scanModel.setReflections(reflections);

    //
    // 获取DisconfFile class
    //
    Set<Class<?>> classdata = reflections.getTypesAnnotatedWith(DisconfFile.class);
    scanModel.setDisconfFileClassSet(classdata);

    //
    // 获取DisconfFileItem method
    //
    Set<Method> af1 = reflections.getMethodsAnnotatedWith(DisconfFileItem.class);
    scanModel.setDisconfFileItemMethodSet(af1);

    //
    // 获取DisconfItem method
    //
    af1 = reflections.getMethodsAnnotatedWith(DisconfItem.class);
    scanModel.setDisconfItemMethodSet(af1);

    //
    // 获取DisconfActiveBackupService
    //
    classdata = reflections.getTypesAnnotatedWith(DisconfActiveBackupService.class);
    scanModel.setDisconfActiveBackupServiceClassSet(classdata);

    //
    // 获取DisconfUpdateService
    //
    classdata = reflections.getTypesAnnotatedWith(DisconfUpdateService.class);
    scanModel.setDisconfUpdateService(classdata);

    return scanModel;
  }
 /**
  * Find all the Java classes that have proper @ClientDtoFactoryVisitor annotation.
  *
  * @throws java.io.IOException
  */
 @SuppressWarnings("unchecked")
 private static void findDtoFactoryVisitors() throws IOException {
   Reflections reflection = new Reflections(getConfigurationBuilder());
   Set<Class<?>> classes = reflection.getTypesAnnotatedWith(ClientDtoFactoryVisitor.class);
   int i = 0;
   for (Class clazz : classes) {
     dtoFactoryVisitors.put(clazz.getCanonicalName(), "provider_" + i++);
     System.out.println(
         String.format("New DtoFactoryVisitor found: %s", clazz.getCanonicalName()));
   }
   System.out.println(String.format("Found: %d DtoFactoryVisitor(s)", dtoFactoryVisitors.size()));
 }
Beispiel #13
0
 public static void loadMaps(String packageName) {
   Reflections reflections = new Reflections(packageName);
   Set<Class<?>> classes = reflections.getTypesAnnotatedWith(MapConfig.class);
   for (Class<?> clazz : classes) {
     try {
       Object map = clazz.newInstance();
       maps.add((Map) map);
     } catch (Exception e) {
       logger.severe("Unable to load map: " + clazz.getName());
       e.printStackTrace();
     }
   }
 }
Beispiel #14
0
 @Test
 public void findAllClasses() {
   Reflections reflections = new Reflections("example.module.workflow");
   Set<Class<? extends Object>> classes =
       reflections.getTypesAnnotatedWith(
           example.module.workflow.annotation.WorkflowDefinition.class);
   Iterator<Class<? extends Object>> iterator = classes.iterator();
   while (iterator.hasNext()) {
     Class<? extends Object> cls = iterator.next();
     System.out.println(cls.getName());
   }
   System.out.println("end");
 }
  public static Test suite() throws Exception {
    TestSuite mainSuite = new TestSuite("LexBIG validation tests");

    Reflections reflections =
        new Reflections(
            "org.LexGrid.LexBIG", new TypeAnnotationsScanner(), new SubTypesScanner(false));

    Set<Class<? extends Object>> allClasses =
        reflections.getTypesAnnotatedWith(RemoteApiSafeTest.class);

    for (Class test : allClasses) {
      mainSuite.addTestSuite(test);
    }

    return mainSuite;
  }
Beispiel #16
0
  static {
    final Map<DungeonType, Class<?>> builderMap = new HashMap<DungeonType, Class<?>>();
    final Reflections reflections =
        Identifier.isDebugMode()
            ? new Reflections(DungeonFactory.class.getPackage())
            : Reflections.collect();
    final Set<Class<?>> builders = reflections.getTypesAnnotatedWith(Builds.class);

    for (final Class<?> clazz : builders) {
      final DungeonType dungeonType = clazz.getAnnotation(Builds.class).value();
      if (builderMap.containsKey(dungeonType)) {
        throw new DuplicateKeyException(
            "DungeonType '"
                + dungeonType
                + "' is registered by more than one "
                + DungeonBuilder.class.getSimpleName()
                + ".");
      }

      // Create an instance now to verify that it is of the right type for later
      Object instance = null;
      try {
        instance = clazz.newInstance();
      } catch (final ReflectiveOperationException e) {
        throw new UnsupportedOperationException(e);
      }

      if (!(instance instanceof AbstractDungeonBuilder)) {
        throw new UnsupportedOperationException(
            "Class '"
                + clazz.getSimpleName()
                + "' does not extend "
                + AbstractDungeonBuilder.class.getSimpleName()
                + ".");
      }

      // Store the class so we can generate new instances on demand later
      builderMap.put(dungeonType, clazz);
    }

    BUILDER_MAP = Collections.unmodifiableMap(builderMap);
  }
 public static List<Class<?>> getAllDaoClasses() {
   Reflections reflections = new Reflections("");
   Set<Class<?>> allClasses = reflections.getTypesAnnotatedWith(DatabaseTable.class);
   return new ArrayList<Class<?>>(allClasses);
 }