Пример #1
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;
  }
Пример #2
0
  /** 分析出配置文件与配置文件中的Field的Method的MAP */
  private void analysis4DisconfFile(ScanStaticModel scanModel) {

    Map<Class<?>, Set<Method>> disconfFileItemMap = new HashMap<Class<?>, Set<Method>>();

    //
    // 配置文件MAP
    //
    Set<Class<?>> classdata = scanModel.getDisconfFileClassSet();
    for (Class<?> classFile : classdata) {
      disconfFileItemMap.put(classFile, new HashSet<Method>());
    }

    //
    // 将配置文件与配置文件中的配置项进行关联
    //
    Set<Method> af1 = scanModel.getDisconfFileItemMethodSet();
    for (Method method : af1) {

      Class<?> thisClass = method.getDeclaringClass();

      if (disconfFileItemMap.containsKey(thisClass)) {
        Set<Method> fieldSet = disconfFileItemMap.get(thisClass);
        fieldSet.add(method);
        disconfFileItemMap.put(thisClass, fieldSet);

      } else {

        LOGGER.error(
            "cannot find CLASS ANNOTATION "
                + DisconfFile.class.getName()
                + " for disconf file item: "
                + method.toString());
      }
    }

    //
    // 最后的校验
    //
    Iterator<Class<?>> iterator = disconfFileItemMap.keySet().iterator();
    while (iterator.hasNext()) {

      Class<?> classFile = iterator.next();

      // 校验是否所有配置文件都含有配置
      if (disconfFileItemMap.get(classFile).isEmpty()) {
        LOGGER.warn("disconf file hasn't any items: " + classFile.getName());
        continue;
      }

      // 校验配置文件类型是否合适(目前只支持.properties类型)
      DisconfFile disconfFile = classFile.getAnnotation(DisconfFile.class);
      boolean fileTypeRight = ScanVerify.isDisconfFileTypeRight(disconfFile);
      if (!fileTypeRight) {
        LOGGER.warn("now do not support this file type" + disconfFile.toString());
        continue;
      }
    }

    // 设置
    scanModel.setDisconfFileItemMap(disconfFileItemMap);
  }