Пример #1
0
  public void handle(Class<?> annotatedType) {
    if (!(Converter.class.isAssignableFrom(annotatedType)))
      throw new VRaptorException("converter does not implement Converter");

    @SuppressWarnings("unchecked")
    Class<? extends Converter<?>> converterType = (Class<? extends Converter<?>>) annotatedType;

    converters.register(converterType);
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  private Object load(String name, Class type) {
    String parameter = request.getParameter(name + ".id");
    if (parameter == null) {
      return null;
    }
    Field field = new Mirror().on(type).reflect().field("id");
    checkArgument(
        field != null,
        "Entity " + type.getSimpleName() + " must have an id property for @LoadObject.");

    Class<?> idType = field.getType();
    Converter<?> converter = converters.to(idType);
    checkArgument(
        converter != null,
        "Entity " + type.getSimpleName() + " id type " + idType + " must have a converter");

    Serializable id = (Serializable) converter.convert(parameter, type, localization.getBundle());
    return em.find(type, id);
  }