Package net.vidageek.mirror.dsl

Examples of net.vidageek.mirror.dsl.Mirror


          String[] items = path.split("\\.");
          Class<?> type = method.getParameterTypes()[i];
          for (int j = 1; j < items.length; j++) {
            String item = items[j];
            try {
              type = new Mirror().on(type).reflect().method("get" + upperFirst(item)).withoutArgs().getReturnType();
            } catch (Exception e) {
              throw new IllegalArgumentException("Parameters paths are invalid: " + Arrays.toString(parameterPaths) + " for method " + method, e);
            }
          }
          result.put(path, type);
View Full Code Here


  }

  private Class<?> getParentType(String name, Class<?> type) {
    String[] path = name.split("\\.");
    for (int i = 0; i < path.length - 1; i++) {
      type = getActualType(new Mirror().on(type).reflect().field(path[i]).getGenericType());
    }
    return type;
  }
View Full Code Here

    }
    return set;
  }

  private void excludeNonPrimitiveFields(Class<?> type) {
    for (Field field : new Mirror().on(type).reflectAll().fields()) {
      if (!isPrimitive(field.getType())) {
        excludes.put(type, field.getName());
      }
    }
  }
View Full Code Here

    for (String field : fields) {
      try {
        Set<Class<?>> parentTypes = getParentTypesFor(field);
        String fieldName = getNameFor(field);
        for (Class<?> parentType : parentTypes) {
          Type genericType = new Mirror().on(parentType).reflect().field(fieldName).getGenericType();
          Class<?> fieldType = getActualType(genericType);

          if (!excludes.containsKey(fieldType)) {
            excludeNonPrimitiveFields(fieldType);
          }
View Full Code Here

      result.use(page()).forward(referer);
    }
  }

  private void executeMethod(ResourceMethod method, Object instance) {
    new Mirror().on(instance).invoke().method(method.getMethod())
      .withArgs(provider.getParametersFor(method, new ArrayList<Message>(), localization.getBundle()));
  }
View Full Code Here

  private <T> MethodInvocation<T> throwValidationErrorOnFinalMethods(final Class<T> view, final List<Message> errors,
      final T viewInstance) {
    return new MethodInvocation<T>() {
      public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) {
        final Object instance = new Mirror().on(viewInstance).invoke().method(method).withArgs(args);
        if (method.getReturnType() == void.class) {
          throw new ValidationException(errors);
        }

        if (view.isAssignableFrom(method.getReturnType())) {
View Full Code Here

  private <T> MethodInvocation<T> throwValidationExceptionOnFirstInvocation(final List<Message> errors,
      final T instance) {
    return new MethodInvocation<T>() {
      public Object intercept(Object proxy, Method method, Object[] args, SuperMethod superMethod) {
        new Mirror().on(instance).invoke().method(method).withArgs(args);

        throw new ValidationException(errors);
      }
    };
  }
View Full Code Here

  private ConstraintValidatorContext context = Mockito.mock(ConstraintValidatorContext.class);

  @Test
  public void testThatNullIsValid() {
    StellaLengthValidator validator = new StellaLengthValidator();
    validator.initialize(new Mirror().on(AnnotatedModel.class).reflect().annotation(Length.class).atField("foo"));
    Assert.assertTrue(validator.isValid(null, context));
  }
View Full Code Here

  }

  @Test
  public void testThatIsInvalidIfStringIsSmallerThanParameter() {
    StellaLengthValidator validator = new StellaLengthValidator();
    validator.initialize(new Mirror().on(AnnotatedModel.class).reflect().annotation(Length.class).atField("s1"));
    Assert.assertFalse(validator.isValid("as", context));
  }
View Full Code Here

  }

  @Test
  public void testThatIsInvalidIfStringIsBiggerThanParameter() {
    StellaLengthValidator validator = new StellaLengthValidator();
    validator.initialize(new Mirror().on(AnnotatedModel.class).reflect().annotation(Length.class).atField("s2"));
    Assert.assertFalse(validator.isValid("12345678912", context));
  }
View Full Code Here

TOP

Related Classes of net.vidageek.mirror.dsl.Mirror

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.