コード例 #1
0
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(getClass().getSimpleName()).append("\n");
   if (_initMessages.isEmpty() == false) {
     sb.append("Initialization message:\n");
     _initMessages.appendTo(sb);
   }
   sb.append("Validators:\n");
   for (Map.Entry<Object, List<Validator>> e : _cache.entrySet()) {
     sb.append("  ");
     Object key = e.getKey();
     if (key instanceof RecordDataSchema.Field) {
       sb.append(((RecordDataSchema.Field) key).getName()).append(" (field)");
     } else if (key instanceof NamedDataSchema) {
       sb.append(((NamedDataSchema) key).getFullName()).append(" (named schema)");
     } else {
       sb.append(key.toString());
     }
     sb.append("\n");
     for (Validator v : e.getValue()) {
       sb.append("    ").append(v).append("\n");
     }
   }
   return sb.toString();
 }
コード例 #2
0
ファイル: DataTranslator.java プロジェクト: saeta/rest.li
 protected void checkMessageListForErrorsAndThrowDataTranslationException()
     throws DataTranslationException {
   if (_messageList.isEmpty() == false) {
     Object[] firstErrorPath = _messageList.get(0).getPath();
     throw new DataTranslationException(
         "Error processing " + pathToString(Arrays.asList(firstErrorPath)), _messageList);
   }
 }
コード例 #3
0
 /**
  * Initialize the {@link DataSchemaAnnotationValidator} with the provided {@link DataSchema} and
  * key to {@link Validator} class map.
  *
  * <p>This method causes the "validate" properties of the schema and referenced schemas to be
  * parsed and appropriate instances of {@link Validator}'s to be constructed.
  *
  * <p>This method does not throw an exception if there is an initialization error. The client
  * should check the return value for initialization errors.
  *
  * @param schema to be parsed to compute the {@link Validator}'s that have to be created.
  * @param classMap provides the map of the keys to {@link Validator}s that is looked up first
  *     before looking for classes with names derived from the key.
  * @return true if initialization is successful, else return false, additional information may be
  *     obtained using {@link #getInitMessages()}.
  */
 public boolean init(DataSchema schema, Map<String, Class<? extends Validator>> classMap) {
   _initMessages.clear();
   _schema = schema;
   _classMap = classMap;
   _cache = cacheValidators(_schema);
   return isInitOk();
 }
コード例 #4
0
ファイル: DataTranslator.java プロジェクト: saeta/rest.li
 @Override
 public void appendMessage(String format, Object... args) {
   _messageList.add(new Message(_path.toArray(), format, args));
 }
コード例 #5
0
 private void addMessage(List<String> path, boolean error, String format, Object... args) {
   _initMessages.add(new Message(path.toArray(), error, format, args));
 }
コード例 #6
0
 /**
  * Return whether initialization is successful.
  *
  * @return true if initialization is successful.
  */
 public boolean isInitOk() {
   return _initMessages.isError() == false;
 }