org.apache.tinkerpop.gremlin.util.config.YamlConfiguration类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(105)

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

YamlConfiguration介绍

[英]Apache Commons Configuration object for YAML. Adapted from code originally found here: https://github.com/PEXPlugins/SimpleConfigs
[中]用于YAML的Apache Commons配置对象。改编自最初在这里找到的代码:https://github.com/PEXPlugins/SimpleConfigs

代码示例

代码示例来源:origin: apache/tinkerpop

private static Configuration getConfiguration(final File configurationFile) {
    if (!configurationFile.isFile())
      throw new IllegalArgumentException(String.format("The location configuration must resolve to a file and [%s] does not", configurationFile));

    try {
      final String fileName = configurationFile.getName();
      final String fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);

      switch (fileExtension) {
        case "yml":
        case "yaml":
          final YamlConfiguration config = new YamlConfiguration();
          config.load(configurationFile);
          return config;
        case "xml":
          return new XMLConfiguration(configurationFile);
        default:
          return new PropertiesConfiguration(configurationFile);
      }
    } catch (final ConfigurationException e) {
      throw new IllegalArgumentException(String.format("Could not load configuration at: %s", configurationFile), e);
    }
  }
}

代码示例来源:origin: apache/tinkerpop

@Override
public void load(final Reader in) throws ConfigurationException {
  try {
    this.loadHierarchy(this.getRootNode(), yaml.load(in));
  } catch (Throwable e) {
    throw new ConfigurationException("Failed to load configuration: " + e.getMessage(), e);
  }
}

代码示例来源:origin: apache/tinkerpop

public YamlConfiguration() {
  super();
  initialize();
}

代码示例来源:origin: apache/tinkerpop

@Override
public void save(final Writer out) throws ConfigurationException {
  try {
    yaml.dump(this.saveHierarchy(this.getRootNode()), out);
  } catch (Throwable e) {
    throw new ConfigurationException("Failed to save configuration: " + e.getMessage(), e);
  }
}

代码示例来源:origin: hugegraph/hugegraph

public static void main(String[] args)
          throws ConfigurationException, InterruptedException {
  E.checkArgument(args.length == 1,
          "Init store only accept one config file.");
  E.checkArgument(args[0].endsWith(".yaml"),
          "Init store only accept yaml config file.");
  String confFile = args[0];
  RegisterUtil.registerBackends();
  YamlConfiguration config = new YamlConfiguration();
  config.load(confFile);
  List<ConfigurationNode> nodes = config.getRootNode()
                     .getChildren(GRAPHS);
  E.checkArgument(nodes.size() == 1,
          "Must contain one '%s' in config file '%s'",
          GRAPHS, confFile);
  List<ConfigurationNode> graphNames = nodes.get(0).getChildren();
  E.checkArgument(!graphNames.isEmpty(),
          "Must contain at least one graph");
  for (ConfigurationNode graphName : graphNames) {
    String configPath = graphName.getValue().toString();
    initGraph(configPath);
  }
  HugeGraph.shutdown(30L);
}

代码示例来源:origin: apache/tinkerpop

protected Object saveHierarchy(final ConfigurationNode parentNode) {
    if (parentNode.getChildrenCount() == 0)
      return parentNode.getValue();

    if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) {
      return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList());
    } else {
      final Map<String, Object> map = new LinkedHashMap<>();
      for (ConfigurationNode childNode : parentNode.getChildren()) {
        String nodeName = childNode.getName();
        if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0)
          nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue());

        map.put(nodeName, saveHierarchy(childNode));
      }

      return map;
    }
  }
}

代码示例来源:origin: apache/tinkerpop

protected void loadHierarchy(final ConfigurationNode parentNode, final Object obj) {
  final String parentName = parentNode.getName();
  if (obj instanceof Map<?, ?>) {
    for (Map.Entry<String, Object> entry : ((Map<String, Object>) obj).entrySet()) {
      final Node childNode = new Node(entry.getKey());
      // if parent node is look like "tableS", "userS" or "groupS"
      if (this.xmlCompatibility && parentName != null && parentName.endsWith("s")) {
        //this is done to have "users.user[@name='smith'] instead of "users.smith"
        childNode.setName(parentName.substring(0, parentName.length() - 1));
        childNode.addAttribute(new Node("name", entry.getKey()));
      }
      childNode.setReference(entry);
      loadHierarchy(childNode, entry.getValue());
      parentNode.addChild(childNode);
    }
  } else if (obj instanceof Collection) {
    for (Object child : (Collection) obj) {
      final Node childNode = new Node("item");
      childNode.setReference(child);
      loadHierarchy(childNode, child);
      parentNode.addChild(childNode);
    }
  }
  parentNode.setValue(obj);
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

@Override
public void save(final Writer out) throws ConfigurationException {
  try {
    yaml.dump(this.saveHierarchy(this.getRootNode()), out);
  } catch (Throwable e) {
    throw new ConfigurationException("Failed to save configuration: " + e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

protected Object saveHierarchy(final ConfigurationNode parentNode) {
    if (parentNode.getChildrenCount() == 0)
      return parentNode.getValue();

    if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) {
      return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList());
    } else {
      final Map<String, Object> map = new LinkedHashMap<>();
      for (ConfigurationNode childNode : parentNode.getChildren()) {
        String nodeName = childNode.getName();
        if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0)
          nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue());

        map.put(nodeName, saveHierarchy(childNode));
      }

      return map;
    }
  }
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

protected void loadHierarchy(final ConfigurationNode parentNode, final Object obj) {
  final String parentName = parentNode.getName();
  if (obj instanceof Map<?, ?>) {
    for (Map.Entry<String, Object> entry : ((Map<String, Object>) obj).entrySet()) {
      final Node childNode = new Node(entry.getKey());
      // if parent node is look like "tableS", "userS" or "groupS"
      if (this.xmlCompatibility && parentName != null && parentName.endsWith("s")) {
        //this is done to have "users.user[@name='smith'] instead of "users.smith"
        childNode.setName(parentName.substring(0, parentName.length() - 1));
        childNode.addAttribute(new Node("name", entry.getKey()));
      }
      childNode.setReference(entry);
      loadHierarchy(childNode, entry.getValue());
      parentNode.addChild(childNode);
    }
  } else if (obj instanceof Collection) {
    for (Object child : (Collection) obj) {
      final Node childNode = new Node("item");
      childNode.setReference(child);
      loadHierarchy(childNode, child);
      parentNode.addChild(childNode);
    }
  }
  parentNode.setValue(obj);
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

private static Configuration getConfiguration(final File configurationFile) {
    if (!configurationFile.isFile())
      throw new IllegalArgumentException(String.format("The location configuration must resolve to a file and [%s] does not", configurationFile));

    try {
      final String fileName = configurationFile.getName();
      final String fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);

      switch (fileExtension) {
        case "yml":
        case "yaml":
          final YamlConfiguration config = new YamlConfiguration();
          config.load(configurationFile);
          return config;
        case "xml":
          return new XMLConfiguration(configurationFile);
        default:
          return new PropertiesConfiguration(configurationFile);
      }
    } catch (final ConfigurationException e) {
      throw new IllegalArgumentException(String.format("Could not load configuration at: %s", configurationFile), e);
    }
  }
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

@Override
public void load(final Reader in) throws ConfigurationException {
  try {
    this.loadHierarchy(this.getRootNode(), yaml.load(in));
  } catch (Throwable e) {
    throw new ConfigurationException("Failed to load configuration: " + e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

public YamlConfiguration() {
  super();
  initialize();
}

相关文章