Example #1
0
  private Object resolveParameter(java.lang.annotation.Annotation[] parmAnnos, Class<?> paramType) {
    Object val = null;
    boolean hitResolver = false;
    Default defAnno = null;
    for (Annotation anno : parmAnnos) {
      Class<?> annotype = anno.annotationType();

      if (defAnno == null && annotype.equals(Default.class)) {
        defAnno = (Default) anno;
        continue;
      }
      ParamResolver<Annotation> resolver = _paramResolvers.get(annotype);
      if (resolver == null) continue;
      hitResolver = true;
      val = resolver.resolveParameter(anno, paramType);
      if (val != null) {
        break;
      }
      // don't break until get a value
    }
    if (val == null && defAnno != null) {
      val = Classes.coerce(paramType, defAnno.value());
    }

    // to compatible to rc2, do we have to?
    if (_mappingType && val == null && !hitResolver && _types != null) {
      for (Type type : _types) {
        if (type != null && paramType.isAssignableFrom(type.clz)) {
          val = type.value;
          break;
        }
      }
    }
    return val;
  }
 public ParamResolver supports(ParamMetaData metaData) {
   for (ParamResolver resolver : customerResolvers) {
     if (resolver.supports(metaData)) {
       return resolver;
     }
   }
   for (ParamResolver resolver : buildinResolvers) {
     if (resolver.supports(metaData)) {
       return resolver;
     }
   }
   return null;
 }
 public boolean supports(ParamMetaData metaData) {
   if (inner.supports(metaData)) {
     addIndexAliasParamNameIfNeccessary(metaData);
     return true;
   }
   return false;
 }
  public static String format(String format, ParamResolver resolver) {
    if (format == null) {
      return null;
    }

    StringBuffer s = new StringBuffer();
    Matcher m = paramPattern.matcher(format);

    while (m.find()) {
      String g = m.group();

      if (m.start(1) != -1) {
        // Match on group 1, which is our parameter pattern; append a single '?'
        m.appendReplacement(s, resolver.resolveParam(g.substring(1, g.length() - 1)));
      } else {
        // Match on quoted strings, which we just copy as-is
        m.appendReplacement(s, g);
      }
    }

    m.appendTail(s);

    return s.toString();
  }
 @Override
 public String toString() {
   return inner.toString();
 }
 public Object resolve(Invocation inv, ParamMetaData metaData) throws Exception {
   return inner.resolve(inv, metaData);
 }