Пример #1
0
  /**
   * Validates the assignment of a property of an instance of a class to a value against the
   * deserialization validator. If the assignment is not valid, SerializationException is thrown.
   *
   * @param obj The class instance whose property is being assigned to a value.
   * @param propName The name of the property that is being assigned.
   * @param value The value that the property is being assigned to.
   * @throws SerializationException if the value assignment is not valid.
   */
  public static void validateAssignment(Object obj, String propName, Object value) {
    SerializationContext context = SerializationContext.getSerializationContext();
    DeserializationValidator validator = context.getDeserializationValidator();
    if (validator == null) return;

    boolean valid = true;
    try {
      valid = validator.validateAssignment(obj, propName, value);
    } catch (Exception e) {
      // Assignment validation of the object with type '{0}' for the property '{1}' failed.
      SerializationException se = new SerializationException();
      se.setMessage("10312");
      // se.setMessage(10312, new Object[]{obj == null? NULL : obj.getClass().getName(), propName});
      se.setRootCause(e);
      throw se;
    }
    if (!valid) {
      SerializationException se = new SerializationException();
      se.setMessage("10312");
      // se.setMessage(10312, new Object[]{obj == null? NULL : obj.getClass().getName(), propName});
      throw se;
    }
  }
Пример #2
0
  /**
   * Validates the creation of the class instance against the deserialization validator, if one
   * exists. If the class creation is not valid, SerializationException is thrown.
   *
   * @param cls The class to validate.
   * @throws SerializationException if the class creation is not valid.
   */
  public static void validateCreation(Class<?> cls) {
    SerializationContext context = SerializationContext.getSerializationContext();
    DeserializationValidator validator = context.getDeserializationValidator();
    if (validator == null) return;

    boolean valid = true;
    try {
      valid = validator.validateCreation(cls);
    } catch (Exception e) {
      // Creation validation for class '{0}' failed.
      SerializationException se = new SerializationException();
      se.setMessage("10311");
      // se.setMessage(10311, new Object[]{cls == null? NULL : cls.getName()});
      se.setRootCause(e);
      throw se;
    }
    if (!valid) {
      // Creation validation for class '{0}' failed.
      SerializationException se = new SerializationException();
      se.setMessage("10311");
      // se.setMessage(10311, new Object[]{cls == null? NULL : cls.getName()});
      throw se;
    }
  }