Example #1
0
  /**
   * 判断配置文件的类型是否正确
   *
   * @return
   */
  public static boolean isDisconfFileTypeRight(DisconfFile disconfFile) {

    String fileName = disconfFile.filename();

    if (!fileName.endsWith(".properties")) {

      LOGGER.error("now we only support .properites conf: " + disconfFile.toString());
      return false;
    }

    return true;
  }
Example #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);
  }