Пример #1
0
  private IdGenerator createParameterizableIdGenerator(String expression) {
    Assert.hasText(expression);

    int paramIndex = expression.indexOf(PARAM_DELIM);
    if (paramIndex == -1) {
      // no parameters
      throw new IllegalArgumentException(expression + " is not valid expression.");
    }

    String name = expression.substring(0, paramIndex).trim();
    String parameters = expression.substring(paramIndex + 1, expression.length() - 1);

    ParameterEntry[] paramEntries = getParameterEntries(parameters);
    Class idGenClass = (Class) GENERATORS.get(name);
    if (idGenClass == null) {
      // custom implement
      idGenClass = ClassLoaderUtils.loadClass(name, PatternParser.class);
    }
    IdGenerator generator = (IdGenerator) ClassLoaderUtils.instantiate(idGenClass);

    for (int i = 0; i < paramEntries.length; i++) {
      try {
        // need type convertion
        BeanUtils.setProperty(generator, paramEntries[i].getName(), paramEntries[i].getValue());
      } catch (IllegalAccessException e) {
        throw new IdGenerationException(expression + " is not valid expression.", e);
      } catch (InvocationTargetException e) {
        throw new IdGenerationException(expression + " is not valid expression.", e);
      }
    }

    return generator;
  }
Пример #2
0
    public ParameterEntry(String nameValuePair) {
      String[] pairs = nameValuePair.split("=");
      Assert.isTrue(pairs.length == 2);

      this.name = pairs[0].trim();
      this.value = pairs[1].trim();
    }