Exemplo n.º 1
0
  private void fillFieldContent(Object object, Map<String, Object> properties, Class<?> clazz) {

    if (clazz != AbstractGatewayPacket.class && clazz != Object.class && clazz != null) {
      Field[] fields = clazz.getDeclaredFields();
      for (int i = 0; i < fields.length; i++) {
        String name = fields[i].getName();
        if ((fields[i].getModifiers() & Modifier.STATIC) == 0
            && (fields[i].getModifiers() & Modifier.PUBLIC) != 0) {
          Object value = properties.get(name);

          if (value != null) {
            try {
              if (ParameterMapping.isPrimitiveType(fields[i].getType())) {
                value = ParameterMapping.deStringize(fields[i].getType(), (String) value);
                fields[i].setAccessible(true);
                fields[i].set(object, value);
              } else {
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
      }
      fillFieldContent(object, properties, clazz.getSuperclass());
    }
  }
  public static void main(String[] args) throws Exception {
    try {
      requestOption.setRequired(true);
      parser.parse(args);
      Boolean value = (Boolean) parser.getOptionValue(helpOption, false);
      if (value != null && value.booleanValue()) {
        parser.printUsage();
        System.exit(2);
      }
      parser.checkRequired();
    } catch (CmdLineParser.OptionException e) {
      System.err.println(e.getMessage());
      parser.printUsage();
      System.exit(2);
    }
    ParameterMapping.registerTransfer(
        BSONObject.class,
        new PropertyTransfer<BSONObject>() {
          @Override
          public BSONObject transfer(String inputString) {
            String json =
                ConfigUtil.filterWtihOGNL(
                    inputString, AbstractBenchmark.getInstance().getNextRequestContextMap());
            return (BSONObject) JSON.parse(json);
          }
        });

    ParameterMapping.registerTransfer(
        BSONObject[].class,
        new PropertyTransfer<BSONObject[]>() {
          @Override
          public BSONObject[] transfer(String inputString) {
            String[] items = StringUtils.splitByWholeSeparator(inputString, "//--");
            BSONObject[] list = new BSONObject[items.length];
            for (int i = 0; i < items.length; i++) {
              String json =
                  ConfigUtil.filterWtihOGNL(
                      items[i].trim(), AbstractBenchmark.getInstance().getNextRequestContextMap());
              list[i] = (BSONObject) JSON.parse(json);
            }
            return list;
          }
        });

    AbstractBenchmark.setBenchmark(new MongoDBBenchmark());
    AbstractBenchmark.main(args);
  }
  public Object makeObject() throws Exception {
    QueryResponse object = new QueryResponse();
    MessageHandlerRunner runner = messageHandlerRunner.newInstance();

    ParameterMapping.mappingObject(runner, runnerParameters, null);

    if (runner instanceof Initialisable) {
      ((Initialisable) runner).init();
    }

    object.setMessageHandlerRunner(runner);
    if (object instanceof Initialisable) {
      ((Initialisable) object).init();
    }
    return object;
  }