Пример #1
0
 private ValidatorInfo parseValidator(ComponentCtrl compCtrl, String propName) {
   final Collection<Annotation> annos = compCtrl.getAnnotations(propName, VALIDATOR_ANNO);
   if (annos.size() == 0) return null;
   if (annos.size() > 1) {
     throw new IllegalSyntaxException(
         "Allow only one validator for " + propName + " of " + compCtrl);
   }
   final Annotation anno = annos.iterator().next();
   ValidatorInfo info = new ValidatorInfo();
   Map<String, String[]> args = null;
   for (final Iterator<Entry<String, String[]>> it = anno.getAttributes().entrySet().iterator();
       it.hasNext(); ) {
     final Entry<String, String[]> entry = it.next();
     final String tag = entry.getKey();
     final String[] tagExpr = entry.getValue();
     if ("value".equals(tag)) {
       info.expr = testString(compCtrl, propName, tag, tagExpr);
     } else { // other unknown tag, keep as arguments
       if (args == null) {
         args = new HashMap<String, String[]>();
       }
       args.put(tag, tagExpr);
     }
   }
   if (Strings.isBlank(info.expr)) {
     throw new IllegalSyntaxException(
         "Must specify a validator for " + propName + " of " + compCtrl);
   }
   info.args = args == null ? null : parsedArgs(args);
   return info;
 }