Пример #1
0
  private void resolveAndFillMapperConfiguration(String line, MapperConfiguration mapperConfig) {

    // 1. fill the line in the List of configs
    mapperConfig.getConfigurations().add(line);
    // 2. resolve null checks
    if (line.indexOf("=") > -1) {
      String arr[] = line.split("[[ ]*]+");
      mapperConfig
          .getResolvedObjectHierarchies()
          .put(arr[0], resolveNullChecksDestinationObj(arr[0], mapperConfig));
    }
  }
Пример #2
0
  private void getInputAndOutputClasses(String line, MapperConfiguration mapperConfig)
      throws ClassNotFoundException {

    if (line.startsWith("map_from")) {
      String arr[] = line.split("[[ ]*]+");
      mapperConfig.getInputClasses().put(arr[1], Class.forName(arr[3]));
    }

    if (line.startsWith("map_to")) {
      if (mapperConfig.getOutputClass() != null) {
        logger.error("Only one MappedClass is Allowed !");
        throw new RuntimeException("Only one MappedClass is Allowed !");
      }

      String arr[] = line.split("[[ ]*]+");
      mapperConfig.setOutputClass(Class.forName(arr[3]));
      ;
      mapperConfig.setOutputClassAlias((arr[1]));
      ;
    }
  }
Пример #3
0
  public void generateMapper(Path configFilePath, Path mapperGenPath) {

    String outputClassText = "";
    String currRHS = "";
    String currLHS = "";
    String currMode = "mapper";
    String mapperClassName = "";
    String mapperClassPackageName = "";
    MapperClassText mapperText = new MapperClassText();
    MapperConfiguration mapperConfig = new MapperConfiguration();
    // Read Config File
    try {
      BufferedReader reader = new BufferedReader(new FileReader(configFilePath.toFile()));

      String line = reader.readLine();

      if (!line.trim().equals("#mapper")) {
        logger.error("Mapper Genie Configuration should begin with #mapper");
        return;
      }

      line = reader.readLine();

      while (line != null) {
        currMode = determineMapperMode(line, currMode);

        // remove any comments and mapper section separators
        while (line.startsWith("#")) {
          line = reader.readLine();
        }
        switch (currMode) {
          case "mapper":
            mapperConfig.setMapperPackageName(getMapperPackageAndClassName(line)[0]);
            mapperConfig.setMapperClassName(getMapperPackageAndClassName(line)[1]);
            break;

          case "classes":
            getInputAndOutputClasses(line, mapperConfig);
            break;

          case "configuration":
            resolveAndFillMapperConfiguration(line, mapperConfig);
            break;
        }

        if (line.indexOf("=") == -1) {
          logger.debug("Mapper Command / Comment found {}", line);
        } else {
          logger.debug("Mapper Configuration found {}", line);
        }

        line = reader.readLine();
      }

    } catch (IOException e) {
      logger.error("Error Opening/Reading/writing Config/new class file !");
      e.printStackTrace();

    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Пример #4
0
 private List<ExpressionGetterSetterRow> resolveNullChecksDestinationObj(
     String lhsExpression, MapperConfiguration mapperConfig) {
   return BeanUtils.getAllSubExpressionsForLHS(mapperConfig.getOutputClass(), lhsExpression);
 }