/** 创建指定的TypeFilter。 */
  private TypeFilter createTypeFilter(Element element, ClassLoader classLoader) {
    String filterType = defaultIfNull(trimToNull(element.getAttribute("type")), "wildcard");
    String expression =
        assertNotNull(
            trimToNull(element.getAttribute("expression")), "expression for %s" + filterType);

    try {
      if ("assignable".equals(filterType)) {
        return new AssignableTypeFilter(classLoader.loadClass(expression));
      } else if ("aspectj".equals(filterType)) {
        return new AspectJTypeFilter(expression, classLoader);
      } else if ("wildcard".equals(filterType)) {
        return new RegexPatternTypeFilter(
            ClassNameWildcardCompiler.compileClassName(
                expression, ClassNameWildcardCompiler.MATCH_PREFIX));
      } else if ("custom".equals(filterType)) {
        Class<?> filterClass = classLoader.loadClass(expression);

        assertTrue(
            TypeFilter.class.isAssignableFrom(filterClass),
            "Class is not assignable to TypeFilter: %s",
            expression);

        return (TypeFilter) BeanUtils.instantiateClass(filterClass);
      } else {
        unreachableCode("Unsupported filter type: %s", filterType);
        return null;
      }
    } catch (ClassNotFoundException e) {
      throw new FatalBeanException(
          "Failed to create TypeFilter of type " + filterType + ": " + expression, e);
    }
  }
Пример #2
0
  /** 添加query。 */
  public URIBroker addQueryData(String id, Object value) {
    id = assertNotNull(trimToNull(id), "empty query id");

    String strValue;

    if (value == null) {
      strValue = EMPTY_STRING;
    } else {
      assertTrue(!value.getClass().isArray(), "use setQueryData(array) instead");
      strValue = String.valueOf(value);
    }

    Object values = getQuery().get(id);

    if (values == null) {
      values = strValue;
    } else if (values instanceof String) {
      values = new String[] {(String) values, strValue};
    } else if (values instanceof String[]) {
      int length = ((String[]) values).length;
      String[] tmp = new String[length + 1];
      System.arraycopy(values, 0, tmp, 0, length);
      tmp[length] = strValue;
      values = tmp;
    } else {
      unreachableCode();
    }

    getQuery().put(id, values);

    renderer.updateQueryBuffer(id, strValue);

    return this;
  }