コード例 #1
0
  private void parseClassLevelOverrides(
      ClassType classType, Class<?> beanClass, String defaultPackage) {
    if (classType == null) {
      return;
    }

    // ignore annotation
    if (classType.getIgnoreAnnotations() != null) {
      annotationIgnores.setIgnoreAnnotationsOnClass(beanClass, classType.getIgnoreAnnotations());
    }

    // group sequence
    List<Class<?>> groupSequence =
        createGroupSequence(classType.getGroupSequence(), defaultPackage);
    if (!groupSequence.isEmpty()) {
      defaultSequences.put(beanClass, groupSequence);
    }

    // constraints
    for (ConstraintType constraint : classType.getConstraint()) {
      MetaConstraint<?> metaConstraint =
          createMetaConstraint(constraint, beanClass, null, defaultPackage);
      addMetaConstraint(beanClass, metaConstraint);
    }
  }
コード例 #2
0
  public final void parse(Set<InputStream> mappingStreams) {
    for (InputStream in : mappingStreams) {
      ConstraintMappingsType mapping = getValidationConfig(in);
      String defaultPackage = mapping.getDefaultPackage();

      parseConstraintDefinitions(mapping.getConstraintDefinition(), defaultPackage);

      for (BeanType bean : mapping.getBean()) {
        Class<?> beanClass = getClass(bean.getClazz(), defaultPackage);
        checkClassHasNotBeenProcessed(processedClasses, beanClass);
        annotationIgnores.setDefaultIgnoreAnnotation(beanClass, bean.getIgnoreAnnotations());
        parseClassLevelOverrides(bean.getClassType(), beanClass, defaultPackage);
        parseFieldLevelOverrides(bean.getField(), beanClass, defaultPackage);
        parsePropertyLevelOverrides(bean.getGetter(), beanClass, defaultPackage);
        processedClasses.add(beanClass);
      }
    }
  }
コード例 #3
0
  private void parsePropertyLevelOverrides(
      List<GetterType> getters, Class<?> beanClass, String defaultPackage) {
    List<String> getterNames = newArrayList();
    for (GetterType getterType : getters) {
      String getterName = getterType.getName();
      if (getterNames.contains(getterName)) {
        throw log.getIsDefinedTwiceInMappingXmlForBeanException(getterName, beanClass.getName());
      } else {
        getterNames.add(getterName);
      }
      boolean containsMethod =
          ReflectionHelper.containsMethodWithPropertyName(beanClass, getterName);
      if (!containsMethod) {
        throw log.getBeanDoesNotContainThePropertyException(beanClass.getName(), getterName);
      }
      final Method method = ReflectionHelper.getMethodFromPropertyName(beanClass, getterName);

      // ignore annotations
      boolean ignoreGetterAnnotation =
          getterType.getIgnoreAnnotations() == null ? false : getterType.getIgnoreAnnotations();
      if (ignoreGetterAnnotation) {
        annotationIgnores.setIgnoreAnnotationsOnMember(method);
      }

      // valid
      if (getterType.getValid() != null) {
        addCascadedMember(beanClass, method);
      }

      // constraints
      for (ConstraintType constraint : getterType.getConstraint()) {
        MetaConstraint<?> metaConstraint =
            createMetaConstraint(constraint, beanClass, method, defaultPackage);
        addMetaConstraint(beanClass, metaConstraint);
      }
    }
  }
コード例 #4
0
  private void parseFieldLevelOverrides(
      List<FieldType> fields, Class<?> beanClass, String defaultPackage) {
    List<String> fieldNames = newArrayList();
    for (FieldType fieldType : fields) {
      String fieldName = fieldType.getName();
      if (fieldNames.contains(fieldName)) {
        throw log.getIsDefinedTwiceInMappingXmlForBeanException(fieldName, beanClass.getName());
      } else {
        fieldNames.add(fieldName);
      }
      final boolean containsField = ReflectionHelper.containsDeclaredField(beanClass, fieldName);
      if (!containsField) {
        throw log.getBeanDoesNotContainTheFieldException(beanClass.getName(), fieldName);
      }
      final Field field = ReflectionHelper.getDeclaredField(beanClass, fieldName);

      // ignore annotations
      boolean ignoreFieldAnnotation =
          fieldType.getIgnoreAnnotations() == null ? false : fieldType.getIgnoreAnnotations();
      if (ignoreFieldAnnotation) {
        annotationIgnores.setIgnoreAnnotationsOnMember(field);
      }

      // valid
      if (fieldType.getValid() != null) {
        addCascadedMember(beanClass, field);
      }

      // constraints
      for (ConstraintType constraint : fieldType.getConstraint()) {
        MetaConstraint<?> metaConstraint =
            createMetaConstraint(constraint, beanClass, field, defaultPackage);
        addMetaConstraint(beanClass, metaConstraint);
      }
    }
  }