Пример #1
0
  private static void processSingleFile(String fileName) {
    BaseSAXHandler handler = SAXHandlerFactory.getHandlerByTagInFile(fileName);
    if (handler != null) {
      XMLSAXParser parser = new BaseSAXParser();
      parser.parse(new File(fileName), handler);
      List list = handler.getParsedContent();

      AnnotationConfigApplicationContext applicationContext =
          new AnnotationConfigApplicationContext();
      applicationContext.register(AppConfig.class);
      applicationContext.refresh();
      BaseCLIClient client = new CAPStrikeProcessor(applicationContext);
      applicationContext.getAutowireCapableBeanFactory().autowireBean(client);
      client.execute(list);
    }
  }
  @Override
  public <T, U extends T> U newClassInstance(Class<T> classType, Class<U> classToInstantiate)
      throws InstantiationException, IllegalAccessException {

    if (preventSpringInjection && excludedFromInjection.contains(classType)) {
      logger.trace("Excluded from injection {}", classToInstantiate.getName());
      return classToInstantiate.newInstance();
    }

    String name = classToInstantiate.getSimpleName();
    if (!context.containsBeanDefinition(Introspector.decapitalize(name))) {
      context.register(classToInstantiate);
    }
    U t = context.getAutowireCapableBeanFactory().createBean(classToInstantiate);

    if (t == null) {
      logger.info(
          "Unable to find {}. Creating the object directly." + classToInstantiate.getName());
      return classToInstantiate.newInstance();
    }
    return t;
  }