Ejemplo n.º 1
0
 private void executeMethod(ResourceMethod method, Object instance) {
   new Mirror()
       .on(instance)
       .invoke()
       .method(method.getMethod())
       .withArgs(
           provider.getParametersFor(method, new ArrayList<Message>(), localization.getBundle()));
 }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  public List<Message> validate(Object object) {
    List<Message> errors = new ArrayList<Message>();
    ClassValidator<Object> validator =
        (ClassValidator<Object>) locator.getValidator(object.getClass(), localization.getBundle());
    InvalidValue[] invalidValues = validator.getInvalidValues(object);

    for (InvalidValue value : invalidValues) {
      errors.add(new ValidationMessage(value.getMessage(), value.getPropertyPath()));
    }
    return errors;
  }
  @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);
  }