Esempio n. 1
0
  /**
   * 复制parent broker中的值作为默认值,但不覆盖当前broker中已有的值。
   *
   * <p>子类应该覆盖此方法,以实现特定的init功能。
   */
  @Override
  protected void initDefaults(URIBroker parent) {
    if (type == null) {
      type = parent.getURIType();
    }

    if (baseURI == null) {
      baseURI = parent.baseURI;
    }

    if (serverScheme == null) {
      serverScheme = parent.getServerScheme();
    }

    if (serverName == null) {
      serverName = parent.getServerName();
    }

    if (serverPort <= 0) {
      serverPort = parent.getServerPort();
    }

    if (loginUser == null) {
      loginUser = parent.getLoginUser();
    }

    if (loginPassword == null) {
      loginPassword = parent.getLoginPassword();
    }

    if (reference == null) {
      reference = parent.getReference();
    }

    if (!parent.getQuery().isEmpty()) {
      // 合并query,包括合并query的值
      Map<String, Object> queryCopy = createLinkedHashMap();
      queryCopy.putAll(getQuery());

      clearQuery();
      getQuery().putAll(parent.getQuery());

      for (Map.Entry<String, Object> entry : queryCopy.entrySet()) {
        String id = entry.getKey();
        Object values = entry.getValue();

        if (values instanceof String) {
          addQueryData(id, values);
        } else if (values instanceof String[]) {
          for (String value : (String[]) values) {
            addQueryData(id, value);
          }
        }
      }
    }
  }
Esempio n. 2
0
  /**
   * 复制parent的状态。
   *
   * <p>子类应该覆盖此方法,以实现特定的reset功能。
   */
  @Override
  protected void copyFrom(URIBroker parent) {
    baseURI = parent.baseURI;
    setURIType(parent.getURIType());
    setServerScheme(parent.getServerScheme());
    setServerName(parent.getServerName());
    setServerPort(parent.getServerPort());
    setLoginUser(parent.getLoginUser());
    setLoginPassword(parent.getLoginPassword());
    setReference(parent.getReference());

    clearQuery();
    setQuery(parent.getQuery());
  }