gpt4 book ai didi

org.springframework.beans.factory.config.YamlProcessor类的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 14:41:31 26 4
gpt4 key购买 nike

本文整理了Java中org.springframework.beans.factory.config.YamlProcessor类的一些代码示例,展示了YamlProcessor类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlProcessor类的具体详情如下:
包路径:org.springframework.beans.factory.config.YamlProcessor
类名称:YamlProcessor

YamlProcessor介绍

[英]Base class for YAML factories.

Requires SnakeYAML 1.18 or higher, as of Spring Framework 5.0.6.
[中]YAML工厂的基类。
从Spring Framework 5.0.6开始,需要SnakeYAML 1.18或更高版本。

代码示例

代码示例来源:origin: spring-projects/spring-framework

private boolean process(MatchCallback callback, Yaml yaml, Resource resource) {
  int count = 0;
  try {
    if (logger.isDebugEnabled()) {
      logger.debug("Loading from YAML: " + resource);
    }
    Reader reader = new UnicodeReader(resource.getInputStream());
    try {
      for (Object object : yaml.loadAll(reader)) {
        if (object != null && process(asMap(object), callback)) {
          count++;
          if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND) {
            break;
          }
        }
      }
      if (logger.isDebugEnabled()) {
        logger.debug("Loaded " + count + " document" + (count > 1 ? "s" : "") +
            " from YAML resource: " + resource);
      }
    }
    finally {
      reader.close();
    }
  }
  catch (IOException ex) {
    handleProcessError(resource, ex);
  }
  return (count > 0);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return a flattened version of the given map, recursively following any nested Map
 * or Collection values. Entries from the resulting map retain the same order as the
 * source. When called with the Map from a {@link MatchCallback} the result will
 * contain the same values as the {@link MatchCallback} Properties.
 * @param source the source map
 * @return a flattened map
 * @since 4.1.3
 */
protected final Map<String, Object> getFlattenedMap(Map<String, Object> source) {
  Map<String, Object> result = new LinkedHashMap<>();
  buildFlattenedMap(result, source, null);
  return result;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Provide an opportunity for subclasses to process the Yaml parsed from the supplied
 * resources. Each resource is parsed in turn and the documents inside checked against
 * the {@link #setDocumentMatchers(DocumentMatcher...) matchers}. If a document
 * matches it is passed into the callback, along with its representation as Properties.
 * Depending on the {@link #setResolutionMethod(ResolutionMethod)} not all of the
 * documents will be parsed.
 * @param callback a callback to delegate to once matching documents are found
 * @see #createYaml()
 */
protected void process(MatchCallback callback) {
  Yaml yaml = createYaml();
  for (Resource resource : this.resources) {
    boolean found = process(callback, yaml, resource);
    if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND && found) {
      return;
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testStringResource() {
  this.processor.setResources(new ByteArrayResource("foo # a document that is a literal".getBytes()));
  this.processor.process((properties, map) -> assertEquals("foo", map.get("document")));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@SuppressWarnings("unchecked")
public void flattenedMapIsSameAsPropertiesButOrdered() {
  this.processor.setResources(new ByteArrayResource("foo: bar\nbar:\n spam: bucket".getBytes()));
  this.processor.process((properties, map) -> {
    assertEquals("bucket", properties.get("bar.spam"));
    assertEquals(2, properties.size());
    Map<String, Object> flattenedMap = processor.getFlattenedMap(map);
    assertEquals("bucket", flattenedMap.get("bar.spam"));
    assertEquals(2, flattenedMap.size());
    assertTrue(flattenedMap instanceof LinkedHashMap);
    Map<String, Object> bar = (Map<String, Object>) map.get("bar");
    assertEquals("bucket", bar.get("spam"));
  });
}

代码示例来源:origin: spring-projects/spring-framework

private boolean process(Map<String, Object> map, MatchCallback callback) {
  Properties properties = CollectionFactory.createStringAdaptingProperties();
  properties.putAll(getFlattenedMap(map));

代码示例来源:origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
private Map<String, Object> asMap(Object object) {
  // YAML can have numbers as keys
  Map<String, Object> result = new LinkedHashMap<>();
  if (!(object instanceof Map)) {
    // A document can be a text literal
    result.put("document", object);
    return result;
  }
  Map<Object, Object> map = (Map<Object, Object>) object;
  map.forEach((key, value) -> {
    if (value instanceof Map) {
      value = asMap(value);
    }
    if (key instanceof CharSequence) {
      result.put(key.toString(), value);
    }
    else {
      // It has to be a map key in this case
      result.put("[" + key.toString() + "]", value);
    }
  });
  return result;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void integerDeepKeyBehaves() {
  this.processor.setResources(new ByteArrayResource("foo:\n  1: bar".getBytes()));
  this.processor.process((properties, map) -> {
    assertEquals("bar", properties.get("foo[1]"));
    assertEquals(1, properties.size());
  });
}

代码示例来源:origin: org.springframework/spring-beans

private boolean process(Map<String, Object> map, MatchCallback callback) {
  Properties properties = CollectionFactory.createStringAdaptingProperties();
  properties.putAll(getFlattenedMap(map));

代码示例来源:origin: org.springframework/spring-beans

@SuppressWarnings("unchecked")
private Map<String, Object> asMap(Object object) {
  // YAML can have numbers as keys
  Map<String, Object> result = new LinkedHashMap<>();
  if (!(object instanceof Map)) {
    // A document can be a text literal
    result.put("document", object);
    return result;
  }
  Map<Object, Object> map = (Map<Object, Object>) object;
  map.forEach((key, value) -> {
    if (value instanceof Map) {
      value = asMap(value);
    }
    if (key instanceof CharSequence) {
      result.put(key.toString(), value);
    }
    else {
      // It has to be a map key in this case
      result.put("[" + key.toString() + "]", value);
    }
  });
  return result;
}

代码示例来源:origin: org.springframework/spring-beans

private boolean process(MatchCallback callback, Yaml yaml, Resource resource) {
  int count = 0;
  try {
    if (logger.isDebugEnabled()) {
      logger.debug("Loading from YAML: " + resource);
    }
    Reader reader = new UnicodeReader(resource.getInputStream());
    try {
      for (Object object : yaml.loadAll(reader)) {
        if (object != null && process(asMap(object), callback)) {
          count++;
          if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND) {
            break;
          }
        }
      }
      if (logger.isDebugEnabled()) {
        logger.debug("Loaded " + count + " document" + (count > 1 ? "s" : "") +
            " from YAML resource: " + resource);
      }
    }
    finally {
      reader.close();
    }
  }
  catch (IOException ex) {
    handleProcessError(resource, ex);
  }
  return (count > 0);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void mapConvertedToIndexedBeanReference() {
  this.processor.setResources(new ByteArrayResource("foo: bar\nbar:\n spam: bucket".getBytes()));
  this.processor.process((properties, map) -> {
    assertEquals("bucket", properties.get("bar.spam"));
    assertEquals(2, properties.size());
  });
}

代码示例来源:origin: org.springframework/spring-beans

/**
 * Provide an opportunity for subclasses to process the Yaml parsed from the supplied
 * resources. Each resource is parsed in turn and the documents inside checked against
 * the {@link #setDocumentMatchers(DocumentMatcher...) matchers}. If a document
 * matches it is passed into the callback, along with its representation as Properties.
 * Depending on the {@link #setResolutionMethod(ResolutionMethod)} not all of the
 * documents will be parsed.
 * @param callback a callback to delegate to once matching documents are found
 * @see #createYaml()
 */
protected void process(MatchCallback callback) {
  Yaml yaml = createYaml();
  for (Resource resource : this.resources) {
    boolean found = process(callback, yaml, resource);
    if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND && found) {
      return;
    }
  }
}

代码示例来源:origin: org.springframework/spring-beans

/**
 * Return a flattened version of the given map, recursively following any nested Map
 * or Collection values. Entries from the resulting map retain the same order as the
 * source. When called with the Map from a {@link MatchCallback} the result will
 * contain the same values as the {@link MatchCallback} Properties.
 * @param source the source map
 * @return a flattened map
 * @since 4.1.3
 */
protected final Map<String, Object> getFlattenedMap(Map<String, Object> source) {
  Map<String, Object> result = new LinkedHashMap<>();
  buildFlattenedMap(result, source, null);
  return result;
}

代码示例来源:origin: apache/servicemix-bundles

private boolean process(Map<String, Object> map, MatchCallback callback) {
  Properties properties = CollectionFactory.createStringAdaptingProperties();
  properties.putAll(getFlattenedMap(map));

代码示例来源:origin: apache/servicemix-bundles

@SuppressWarnings("unchecked")
private Map<String, Object> asMap(Object object) {
  // YAML can have numbers as keys
  Map<String, Object> result = new LinkedHashMap<String, Object>();
  if (!(object instanceof Map)) {
    // A document can be a text literal
    result.put("document", object);
    return result;
  }
  Map<Object, Object> map = (Map<Object, Object>) object;
  for (Map.Entry<Object, Object> entry : map.entrySet()) {
    Object value = entry.getValue();
    if (value instanceof Map) {
      value = asMap(value);
    }
    Object key = entry.getKey();
    if (key instanceof CharSequence) {
      result.put(key.toString(), value);
    }
    else {
      // It has to be a map key in this case
      result.put("[" + key.toString() + "]", value);
    }
  }
  return result;
}

代码示例来源:origin: apache/servicemix-bundles

private boolean process(MatchCallback callback, Yaml yaml, Resource resource) {
  int count = 0;
  try {
    if (logger.isDebugEnabled()) {
      logger.debug("Loading from YAML: " + resource);
    }
    Reader reader = new UnicodeReader(resource.getInputStream());
    try {
      for (Object object : yaml.loadAll(reader)) {
        if (object != null && process(asMap(object), callback)) {
          count++;
          if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND) {
            break;
          }
        }
      }
      if (logger.isDebugEnabled()) {
        logger.debug("Loaded " + count + " document" + (count > 1 ? "s" : "") +
            " from YAML resource: " + resource);
      }
    }
    finally {
      reader.close();
    }
  }
  catch (IOException ex) {
    handleProcessError(resource, ex);
  }
  return (count > 0);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void integerKeyBehaves() {
  this.processor.setResources(new ByteArrayResource("foo: bar\n1: bar".getBytes()));
  this.processor.process((properties, map) -> {
    assertEquals("bar", properties.get("[1]"));
    assertEquals(2, properties.size());
  });
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Provide an opportunity for subclasses to process the Yaml parsed from the supplied
 * resources. Each resource is parsed in turn and the documents inside checked against
 * the {@link #setDocumentMatchers(DocumentMatcher...) matchers}. If a document
 * matches it is passed into the callback, along with its representation as Properties.
 * Depending on the {@link #setResolutionMethod(ResolutionMethod)} not all of the
 * documents will be parsed.
 * @param callback a callback to delegate to once matching documents are found
 * @see #createYaml()
 */
protected void process(MatchCallback callback) {
  Yaml yaml = createYaml();
  for (Resource resource : this.resources) {
    boolean found = process(callback, yaml, resource);
    if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND && found) {
      return;
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

buildFlattenedMap(result, map, key);
  int count = 0;
  for (Object object : collection) {
    buildFlattenedMap(result, Collections.singletonMap(
        "[" + (count++) + "]", object), key);

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com