org.yaml.snakeyaml.nodes.Tag类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(268)

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

Tag介绍

暂无

代码示例

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

Tag tag;
Tag customTag = classTags.get(javaBean.getClass());
tag = customTag != null ? customTag : new Tag(javaBean.getClass());
MappingNode node = new MappingNode(tag, value, FlowStyle.AUTO);
representedObjects.put(javaBean, node);
DumperOptions.FlowStyle bestStyle = FlowStyle.FLOW;
    continue;
  if (!((ScalarNode) tuple.getKeyNode()).isPlain()) {
    bestStyle = FlowStyle.BLOCK;
  Node nodeValue = tuple.getValueNode();
  if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).isPlain())) {
    bestStyle = FlowStyle.BLOCK;
  node.setFlowStyle(defaultFlowStyle);
} else {
  node.setFlowStyle(bestStyle);

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

keyNode = (ScalarNode) tuple.getKeyNode();
} else {
  throw new YAMLException(
      "Keys must be scalars but found: " + tuple.getKeyNode());
keyNode.setType(String.class);
String key = (String) constructObject(keyNode);
try {
  TypeDescription memberDescription = typeDefinitions.get(beanType);
      if (valueNode.getNodeId() == NodeId.sequence) {
        Class<?> t = arguments[0];
        SequenceNode snode = (SequenceNode) valueNode;
        Class<?> t = arguments[0];
        MappingNode mnode = (MappingNode) valueNode;
        mnode.setOnlyKeyType(t);
      : constructObject(valueNode);
  if (property.getType() == String.class && Tag.BINARY.equals(valueNode.getTag())
      && value instanceof byte[]) {
    value = new String((byte[]) value);

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

} else {
  this.serializedNodes.add(node);
  switch (node.getNodeId()) {
  case scalar:
    ScalarNode scalarNode = (ScalarNode) node;
    Tag detectedTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), true);
    Tag defaultTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), false);
    ImplicitTuple tuple = new ImplicitTuple(node.getTag().equals(detectedTag), node
        .getTag().equals(defaultTag));
    ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple,
        scalarNode.getValue(), null, null, scalarNode.getStyle());
    this.emitter.emit(event);
    break;
  case sequence:
    SequenceNode seqNode = (SequenceNode) node;
    boolean implicitS = node.getTag().equals(this.resolver.resolve(NodeId.sequence,
        null, true));
    this.emitter.emit(new SequenceStartEvent(tAlias, node.getTag().getValue(),
        implicitS, null, null, seqNode.getFlowStyle()));
    List<Node> list = seqNode.getValue();
  default:// instance of MappingNode
    Tag implicitTag = this.resolver.resolve(NodeId.mapping, null, true);
    boolean implicitM = node.getTag().equals(implicitTag);
    this.emitter.emit(new MappingStartEvent(tAlias, node.getTag().getValue(),
        implicitM, null, null, ((CollectionNode) node).getFlowStyle()));
    MappingNode mnode = (MappingNode) node;
    List<NodeTuple> map = mnode.getValue();
    for (NodeTuple row : map) {

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

public boolean useClassConstructor() {
  if (useClassConstructor == null) {
    if (!tag.isSecondary() && resolved && !Object.class.equals(type)
        && !tag.equals(Tag.NULL)) {
      return true;
    } else if (tag.isCompatible(getType())) {
      // the tag is compatible with the runtime class
      // the tag will be ignored
      return true;
    } else {
      return false;
    }
  }
  return useClassConstructor.booleanValue();
}

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

/**
 * Ensure that the stream contains a single document and construct it
 *
 * @param type the class of the instance being created
 * @return constructed instance
 * @throws ComposerException in case there are more documents in the stream
 */
public Object getSingleData(Class<?> type) {
  // Ensure that the stream contains a single document and construct it
  Node node = composer.getSingleNode();
  if (node != null && !Tag.NULL.equals(node.getTag())) {
    if (Object.class != type) {
      node.setTag(new Tag(type));
    } else if (rootTag != null) {
      node.setTag(rootTag);
    }
    return constructDocument(node);
  }
  return null;
}

代码示例来源:origin: CodeCrafter47/BungeeTabListPlus

@Override
@SneakyThrows
protected Object constructObject(Node node) {
  Class<?> target = node.getType();
  if (target == Object.class && node.getTag().startsWith(Tag.PREFIX) && !noClass.contains(node.getTag())) {
    try {
      target = Class.forName(node.getTag().getClassName());
    } catch (ClassNotFoundException ignored) {
  for (Subtype subtype : subtypes) {
    if (!subtype.tag().isEmpty()) {
      if (subtype.tag().equals(node.getTag().getValue())) {
        node.setType(subtype.type());
        node.setTag(new Tag(subtype.type()));
        defaultType = null;
        break TypeSelection;
      for (NodeTuple tuple : ((MappingNode) node).getValue()) {
        if (tuple.getKeyNode() instanceof ScalarNode) {
          tuple.getKeyNode().setType(String.class);
          String key = (String) constructObject(tuple.getKeyNode());
          if (subtype.property().equals(key)) {
            if (tuple.getValueNode() instanceof ScalarNode) {
              if (((ScalarNode) tuple.getValueNode()).getValue().equals(subtype.value())) {
                node.setType(subtype.type());
                node.setTag(new Tag(subtype.type()));
                defaultType = null;
                break TypeSelection;
    node.setType(defaultType);

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

Iterator<NodeTuple> iter = node.getValue().iterator();
while (iter.hasNext()) {
  final NodeTuple nodeTuple = iter.next();
  final Node keyNode = nodeTuple.getKeyNode();
  final Node valueNode = nodeTuple.getValueNode();
  if (keyNode.getTag().equals(Tag.MERGE)) {
    iter.remove();
    switch (valueNode.getNodeId()) {
    case mapping:
      MappingNode mn = (MappingNode) valueNode;
        if (!(subnode instanceof MappingNode)) {
          throw new ConstructorException("while constructing a mapping",
              node.getStartMark(),
              "expected a mapping for merging, but found "
                  + subnode.getNodeId(),
              subnode.getStartMark());
    default:
      throw new ConstructorException("while constructing a mapping",
          node.getStartMark(),
          "expected a mapping or list of mappings for merging, but found "
              + valueNode.getNodeId(),

代码示例来源:origin: com.sap.cloud.yaas.raml-parser/raml-parser

for (int i = 0; i < resourceNode.getValue().size(); i++)
  NodeTuple resourceTuple = resourceNode.getValue().get(i);
  if (resourceTuple.getKeyNode().getNodeId() != scalar)
  String key = ((ScalarNode) resourceTuple.getKeyNode()).getValue();
  if (key.equals(RESOURCE_TYPE_USE_KEY))
    templateReferences.typeReference = cloneNode(resourceTuple.getValueNode(), new HashMap<String, String>());
    removeParametersFromTemplateCall(resourceTuple);
    Node actionNode = resourceTuple.getValueNode();
    if (actionNode.getTag().equals(Tag.NULL))
    else if (actionNode.getTag().equals(INCLUDE_TAG))
      resourceNode.getValue().remove(i);
      resourceNode.getValue().add(i, new NodeTuple(resourceTuple.getKeyNode(), actionNode));
    for (NodeTuple actionTuple : ((MappingNode) actionNode).getValue())
      String actionTupleKey = ((ScalarNode) actionTuple.getKeyNode()).getValue();
      if (actionTupleKey.equals(TRAIT_USE_KEY) && expect(actionTuple.getValueNode(), sequence))

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

protected void processDuplicateKeys(MappingNode node) {
  List<NodeTuple> nodeValue = node.getValue();
  Map<Object, Integer> keys = new HashMap<Object, Integer>(nodeValue.size());
  TreeSet<Integer> toRemove = new TreeSet<Integer>();
  int i = 0;
  for (NodeTuple tuple : nodeValue) {
    Node keyNode = tuple.getKeyNode();
    if (!keyNode.getTag().equals(Tag.MERGE)) {
      Object key = constructObject(keyNode);
      if (key != null) {
              node.getStartMark(), "found unacceptable key " + key,
              tuple.getKeyNode().getStartMark(), e);
      if (prevIndex != null) {
        if (!isAllowDuplicateKeys()) {
          throw new DuplicateKeyException(node.getStartMark(), key,
              tuple.getKeyNode().getStartMark());

代码示例来源:origin: org.raml/raml-parser

private Node resolveInclude(Node node, Tag tag)
{
  if (node.getNodeId() == scalar && node.getTag().equals(INCLUDE_TAG))
  {
    if (tag != null && tag.startsWith(INCLUDE_APPLIED_TAG))
    {
      // for multiple levels of includes in the same template recalculate path using
      //  parent include applied tag path
      ScalarNode scalarNode = (ScalarNode) node;
      String parentPath = includeResolver.getContextPath().resolveRelativePath(tag);
      String includePathRecalculated = ContextPath.getPartentPath(parentPath) + scalarNode.getValue();
      node = new ScalarNode(scalarNode.getTag(), includePathRecalculated, node.getStartMark(), node.getEndMark(), scalarNode.getStyle());
    }
    return includeResolver.resolve(node, resourceLoader, nodeNandler);
  }
  return node;
}

代码示例来源:origin: openbaton/NFVO

if (node instanceof ScalarNode) {
 ScalarNode scalarNode = (ScalarNode) node;
 if (scalarNode.getTag().equals(Tag.FLOAT))
  return Double.parseDouble(scalarNode.getValue());
 else if (scalarNode.getTag().equals(Tag.INT))
  return Integer.parseInt(scalarNode.getValue());
 else if (scalarNode.getTag().equals(Tag.BOOL))
  return Boolean.parseBoolean(scalarNode.getValue());
 else return scalarNode.getValue();
 Map<String, Object> nodeMap = new HashMap<String, Object>();
 MappingNode mappingNode = (MappingNode) node;
 for (NodeTuple nodeTuple : mappingNode.getValue()) {
  if (nodeTuple.getKeyNode() instanceof ScalarNode) {
   String key = ((ScalarNode) nodeTuple.getKeyNode()).getValue();
   nodeMap.put(key, yamlNodeToMap(nodeTuple.getValueNode()));

代码示例来源:origin: com.plausiblelabs.warwizard/warwizard-core

final MappingNode mappingNode = (MappingNode) yaml;
  json.writeStartObject();
  for (NodeTuple tuple : mappingNode.getValue()) {
    if (tuple.getKeyNode() instanceof ScalarNode) {
      json.writeFieldName(((ScalarNode) tuple.getKeyNode()).getValue());
    build(tuple.getValueNode(), json);
} else if (yaml instanceof ScalarNode) {
  final ScalarNode scalarNode = (ScalarNode) yaml;
  final String className = scalarNode.getTag().getClassName();
  if ("bool".equals(className)) {
    json.writeBoolean(Boolean.parseBoolean(scalarNode.getValue()));
  } else if ("int".equals(className)) {
    json.writeNumber(Long.parseLong(scalarNode.getValue()));

代码示例来源:origin: cereda/arara

throws AraraException {
Representer representer = new Representer();
representer.addClassTag(Rule.class, new Tag("!config"));
Yaml yaml = new Yaml(new Constructor(Rule.class), representer);
Rule rule = null;
try {

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

private void processTypeMappingKeys(MappingNode mappingNode, ParsingContextExecution context, INodeParser<?> parser) {
  for (NodeTuple tuple : mappingNode.getValue()) {
    if (Tag.MERGE.equals(tuple.getKeyNode().getTag())) {
      MappingNode toMerge = (MappingNode) tuple.getValueNode();
      processTypeMappingKeys(toMerge, context, parser);
    } else {
      // process a mapping
      map(tuple, (TypeNodeParser) parser, context);
    }
  }
}

代码示例来源:origin: com.sap.cloud.yaas.raml-parser/raml-parser

private String resolveParameterValueInclude(ScalarNode valueNode)
{
  if (valueNode.getTag().equals(INCLUDE_TAG))
  {
    Node resolved = includeResolver.resolve(valueNode, resourceLoader, nodeNandler);
    if (resolved.getNodeId() != scalar)
    {
      addError("Resource type and traits parameters must be scalars", valueNode);
      return "";
    }
    valueNode = (ScalarNode) resolved;
  }
  return valueNode.getValue();
}

代码示例来源:origin: airbnb/okreplay

private boolean isNullValue(NodeTuple tuple) {
 return tuple.getValueNode().getTag().equals(Tag.NULL);
}

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

public Constructor(TypeDescription theRoot, Collection<TypeDescription> moreTDs) {
  if (theRoot == null) {
    throw new NullPointerException("Root type must be provided.");
  }
  this.yamlConstructors.put(null, new ConstructYamlObject());
  if (!Object.class.equals(theRoot.getType())) {
    rootTag = new Tag(theRoot.getType());
  }
  yamlClassConstructors.put(NodeId.scalar, new ConstructScalar());
  yamlClassConstructors.put(NodeId.mapping, new ConstructMapping());
  yamlClassConstructors.put(NodeId.sequence, new ConstructSequence());
  addTypeDescription(theRoot);
  if (moreTDs != null) {
    for (TypeDescription td : moreTDs) {
      addTypeDescription(td);
    }
  }
}

代码示例来源:origin: com.hotels/shunting-yard-replicator

@Override
protected NodeTuple representJavaBeanProperty(
  Object javaBean,
  Property property,
  Object propertyValue,
  Tag customTag) {
 NodeTuple nodeTuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
 Node valueNode = nodeTuple.getValueNode();
 if (Tag.NULL.equals(valueNode.getTag())) {
  return null; // skip 'null' values
 }
 if (valueNode instanceof CollectionNode) {
  if (Tag.SEQ.equals(valueNode.getTag())) {
   SequenceNode seq = (SequenceNode) valueNode;
   if (seq.getValue().isEmpty()) {
    return null; // skip empty lists
   }
  }
  if (Tag.MAP.equals(valueNode.getTag())) {
   MappingNode seq = (MappingNode) valueNode;
   if (seq.getValue().isEmpty()) {
    return null; // skip empty maps
   }
  }
 }
 Object name = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, property.getName());
 return new NodeTuple(representData(name), valueNode);
}

代码示例来源:origin: com.sap.cloud.yaas.raml-parser/raml-parser

NodeTuple tagInclude(NodeTuple tuple)
  {
    if (Tag.NULL.equals(tuple.getValueNode().getTag()))
    {
      return tuple;
    }
    if (templateInclude != null)
    {
      tuple.getValueNode().setTag(templateInclude);
    }
    return tuple;
  }
}

代码示例来源:origin: info.magnolia.core/magnolia-configuration

@Override
protected void constructMapping2ndStep(MappingNode node, Map<Object, Object> mapping) {
  List<NodeTuple> nodeValue = node.getValue();
  for (NodeTuple tuple : nodeValue) {
    if (Tag.INT.equals(tuple.getKeyNode().getTag())) {
      tuple.getKeyNode().setTag(Tag.STR);
    }
  }
  super.constructMapping2ndStep(node, mapping);
}

相关文章