コード例 #1
0
  @Override
  public void handle(Context context, FaultMessage emsg, TideFaultEvent faultEvent) {
    Object[] invalidValues =
        emsg.getExtended() != null ? (Object[]) emsg.getExtended().get("invalidValues") : null;
    if (invalidValues != null) {
      Set<ConstraintViolation<?>> constraintViolations = new HashSet<ConstraintViolation<?>>();

      for (Object v : invalidValues) {
        InvalidValue iv = (InvalidValue) v;
        Object rootBean = context.getEntityManager().getCachedObject(iv.getRootBean(), true);
        Object leafBean = null;
        if (iv.getBean() != null) {
          leafBean = context.getEntityManager().getCachedObject(iv.getBean(), true);
          if (leafBean == null) {
            // Embedded ?
            Object bean = rootBean;
            String[] path = iv.getPath().split("\\.");
            for (int i = 0; i < path.length - 1; i++)
              bean = context.getDataManager().getPropertyValue(bean, path[i]);
            leafBean = bean;
          }
        }

        ServerConstraintViolation violation = new ServerConstraintViolation(iv, rootBean, leafBean);
        constraintViolations.add(violation);
      }

      NotifyingValidatorFactory notifyingValidatorFactory =
          context.byType(NotifyingValidatorFactory.class);
      if (notifyingValidatorFactory == null)
        throw new RuntimeException(
            "No suitable validator factory defined, cannot process validation events");

      notifyingValidatorFactory
          .getValidator()
          .notifyConstraintViolations(null, constraintViolations);
    }
  }
コード例 #2
0
 @Override
 public boolean accepts(FaultMessage emsg) {
   return emsg.getCode().equals(Code.VALIDATION_FAILED);
 }