Java Code Examples for org.yaml.snakeyaml.nodes.MappingNode#getStartMark()

The following examples show how to use org.yaml.snakeyaml.nodes.MappingNode#getStartMark() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseConstructor.java    From onedev with MIT License 6 votes vote down vote up
protected void constructSet2ndStep(MappingNode node, Set<Object> set) {
    List<NodeTuple> nodeValue = node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            try {
                key.hashCode();// check circular dependencies
            } catch (Exception e) {
                throw new ConstructorException("while constructing a Set", node.getStartMark(),
                        "found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e);
            }
        }
        if (keyNode.isTwoStepsConstruction()) {
            /*
             * if keyObject is created it 2 steps we should postpone putting
             * it into the set because it may have different hash after
             * initialization compared to clean just created one. And set of
             * course does not observe value hashCode changes.
             */
            sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));
        } else {
            set.add(key);
        }
    }
}
 
Example 2
Source File: BaseConstructor.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
protected void constructSet2ndStep(MappingNode node, Set<Object> set) {
    List<NodeTuple> nodeValue = (List<NodeTuple>) node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            try {
                key.hashCode();// check circular dependencies
            } catch (Exception e) {
                throw new ConstructorException("while constructing a Set", node.getStartMark(),
                        "found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e);
            }
        }
        if (keyNode.isTwoStepsConstruction()) {
            /*
             * if keyObject is created it 2 steps we should postpone putting
             * it into the set because it may have different hash after
             * initialization compared to clean just created one. And set of
             * course does not observe value hashCode changes.
             */
            sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));
        } else {
            set.add(key);
        }
    }
}
 
Example 3
Source File: BaseConstructor.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
protected void constructSet2ndStep(MappingNode node, Set<Object> set) {
    List<NodeTuple> nodeValue = (List<NodeTuple>) node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            try {
                key.hashCode();// check circular dependencies
            } catch (Exception e) {
                throw new ConstructorException("while constructing a Set", node.getStartMark(),
                        "found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e);
            }
        }
        if (keyNode.isTwoStepsConstruction()) {
            /*
             * if keyObject is created it 2 steps we should postpone putting
             * it into the set because it may have different hash after
             * initialization compared to clean just created one. And set of
             * course does not observe value hashCode changes.
             */
            sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));
        } else {
            set.add(key);
        }
    }
}
 
Example 4
Source File: YamlProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Map<Object, Object> constructMapping(MappingNode node) {
	try {
		return super.constructMapping(node);
	}
	catch (IllegalStateException ex) {
		throw new ParserException("while parsing MappingNode",
				node.getStartMark(), ex.getMessage(), node.getEndMark());
	}
}
 
Example 5
Source File: YamlProcessor.java    From canal with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<Object, Object> constructMapping(MappingNode node) {
    try {
        return super.constructMapping(node);
    } catch (IllegalStateException ex) {
        throw new ParserException("while parsing MappingNode",
            node.getStartMark(),
            ex.getMessage(),
            node.getEndMark());
    }
}
 
Example 6
Source File: YamlProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<Object, Object> constructMapping(MappingNode node) {
	try {
		return super.constructMapping(node);
	}
	catch (IllegalStateException ex) {
		throw new ParserException("while parsing MappingNode",
				node.getStartMark(), ex.getMessage(), node.getEndMark());
	}
}
 
Example 7
Source File: YamlParser.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<Object, Object> constructMapping(MappingNode node) {
  try {
    return super.constructMapping(node);
  } catch (IllegalStateException ex) {
    throw new ParserException("while parsing MappingNode", node.getStartMark(), ex.getMessage(), node.getEndMark());
  }
}
 
Example 8
Source File: SafeConstructor.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public Object construct(Node node) {
    // Note: we do not check for duplicate keys, because it's too
    // CPU-expensive.
    if (!(node instanceof SequenceNode)) {
        throw new ConstructorException("while constructing pairs", node.getStartMark(),
                "expected a sequence, but found " + node.getNodeId(), node.getStartMark());
    }
    SequenceNode snode = (SequenceNode) node;
    List<Object[]> pairs = new ArrayList<Object[]>(snode.getValue().size());
    for (Node subnode : snode.getValue()) {
        if (!(subnode instanceof MappingNode)) {
            throw new ConstructorException("while constructingpairs", node.getStartMark(),
                    "expected a mapping of length 1, but found " + subnode.getNodeId(),
                    subnode.getStartMark());
        }
        MappingNode mnode = (MappingNode) subnode;
        if (mnode.getValue().size() != 1) {
            throw new ConstructorException("while constructing pairs", node.getStartMark(),
                    "expected a single mapping item, but found " + mnode.getValue().size()
                            + " items", mnode.getStartMark());
        }
        Node keyNode = mnode.getValue().get(0).getKeyNode();
        Node valueNode = mnode.getValue().get(0).getValueNode();
        Object key = constructObject(keyNode);
        Object value = constructObject(valueNode);
        pairs.add(new Object[] { key, value });
    }
    return pairs;
}
 
Example 9
Source File: SafeConstructor.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public Object construct(Node node) {
    // Note: we do not check for duplicate keys, because it's too
    // CPU-expensive.
    Map<Object, Object> omap = new LinkedHashMap<Object, Object>();
    if (!(node instanceof SequenceNode)) {
        throw new ConstructorException("while constructing an ordered map",
                node.getStartMark(), "expected a sequence, but found " + node.getNodeId(),
                node.getStartMark());
    }
    SequenceNode snode = (SequenceNode) node;
    for (Node subnode : snode.getValue()) {
        if (!(subnode instanceof MappingNode)) {
            throw new ConstructorException("while constructing an ordered map",
                    node.getStartMark(), "expected a mapping of length 1, but found "
                            + subnode.getNodeId(), subnode.getStartMark());
        }
        MappingNode mnode = (MappingNode) subnode;
        if (mnode.getValue().size() != 1) {
            throw new ConstructorException("while constructing an ordered map",
                    node.getStartMark(), "expected a single mapping item, but found "
                            + mnode.getValue().size() + " items", mnode.getStartMark());
        }
        Node keyNode = mnode.getValue().get(0).getKeyNode();
        Node valueNode = mnode.getValue().get(0).getValueNode();
        Object key = constructObject(keyNode);
        Object value = constructObject(valueNode);
        omap.put(key, value);
    }
    return omap;
}
 
Example 10
Source File: BaseConstructor.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
protected void constructMapping2ndStep(MappingNode node, Map<Object, Object> mapping) {
    List<NodeTuple> nodeValue = (List<NodeTuple>) node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Node valueNode = tuple.getValueNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            try {
                key.hashCode();// check circular dependencies
            } catch (Exception e) {
                throw new ConstructorException("while constructing a mapping",
                        node.getStartMark(), "found unacceptable key " + key, tuple
                                .getKeyNode().getStartMark(), e);
            }
        }
        Object value = constructObject(valueNode);
        if (keyNode.isTwoStepsConstruction()) {
            /*
             * if keyObject is created it 2 steps we should postpone putting
             * it in map because it may have different hash after
             * initialization compared to clean just created one. And map of
             * course does not observe key hashCode changes.
             */
            maps2fill.add(0,
                    new RecursiveTuple<Map<Object, Object>, RecursiveTuple<Object, Object>>(
                            mapping, new RecursiveTuple<Object, Object>(key, value)));
        } else {
            mapping.put(key, value);
        }
    }
}
 
Example 11
Source File: YamlProcessor.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<Object, Object> constructMapping(MappingNode node) {
    try {
        return super.constructMapping(node);
    } catch (IllegalStateException ex) {
        throw new ParserException("while parsing MappingNode",
            node.getStartMark(),
            ex.getMessage(),
            node.getEndMark());
    }
}
 
Example 12
Source File: SafeConstructor.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public Object construct(Node node) {
    // Note: we do not check for duplicate keys, because it's too
    // CPU-expensive.
    if (!(node instanceof SequenceNode)) {
        throw new ConstructorException("while constructing pairs", node.getStartMark(),
                "expected a sequence, but found " + node.getNodeId(), node.getStartMark());
    }
    SequenceNode snode = (SequenceNode) node;
    List<Object[]> pairs = new ArrayList<Object[]>(snode.getValue().size());
    for (Node subnode : snode.getValue()) {
        if (!(subnode instanceof MappingNode)) {
            throw new ConstructorException("while constructingpairs", node.getStartMark(),
                    "expected a mapping of length 1, but found " + subnode.getNodeId(),
                    subnode.getStartMark());
        }
        MappingNode mnode = (MappingNode) subnode;
        if (mnode.getValue().size() != 1) {
            throw new ConstructorException("while constructing pairs", node.getStartMark(),
                    "expected a single mapping item, but found " + mnode.getValue().size()
                            + " items", mnode.getStartMark());
        }
        Node keyNode = mnode.getValue().get(0).getKeyNode();
        Node valueNode = mnode.getValue().get(0).getValueNode();
        Object key = constructObject(keyNode);
        Object value = constructObject(valueNode);
        pairs.add(new Object[] { key, value });
    }
    return pairs;
}
 
Example 13
Source File: SafeConstructor.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public Object construct(Node node) {
    // Note: we do not check for duplicate keys, because it's too
    // CPU-expensive.
    Map<Object, Object> omap = new LinkedHashMap<Object, Object>();
    if (!(node instanceof SequenceNode)) {
        throw new ConstructorException("while constructing an ordered map",
                node.getStartMark(), "expected a sequence, but found " + node.getNodeId(),
                node.getStartMark());
    }
    SequenceNode snode = (SequenceNode) node;
    for (Node subnode : snode.getValue()) {
        if (!(subnode instanceof MappingNode)) {
            throw new ConstructorException("while constructing an ordered map",
                    node.getStartMark(), "expected a mapping of length 1, but found "
                            + subnode.getNodeId(), subnode.getStartMark());
        }
        MappingNode mnode = (MappingNode) subnode;
        if (mnode.getValue().size() != 1) {
            throw new ConstructorException("while constructing an ordered map",
                    node.getStartMark(), "expected a single mapping item, but found "
                            + mnode.getValue().size() + " items", mnode.getStartMark());
        }
        Node keyNode = mnode.getValue().get(0).getKeyNode();
        Node valueNode = mnode.getValue().get(0).getValueNode();
        Object key = constructObject(keyNode);
        Object value = constructObject(valueNode);
        omap.put(key, value);
    }
    return omap;
}
 
Example 14
Source File: BaseConstructor.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
protected void constructMapping2ndStep(MappingNode node, Map<Object, Object> mapping) {
    List<NodeTuple> nodeValue = (List<NodeTuple>) node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Node valueNode = tuple.getValueNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            try {
                key.hashCode();// check circular dependencies
            } catch (Exception e) {
                throw new ConstructorException("while constructing a mapping",
                        node.getStartMark(), "found unacceptable key " + key, tuple
                                .getKeyNode().getStartMark(), e);
            }
        }
        Object value = constructObject(valueNode);
        if (keyNode.isTwoStepsConstruction()) {
            /*
             * if keyObject is created it 2 steps we should postpone putting
             * it in map because it may have different hash after
             * initialization compared to clean just created one. And map of
             * course does not observe key hashCode changes.
             */
            maps2fill.add(0,
                    new RecursiveTuple<Map<Object, Object>, RecursiveTuple<Object, Object>>(
                            mapping, new RecursiveTuple<Object, Object>(key, value)));
        } else {
            mapping.put(key, value);
        }
    }
}
 
Example 15
Source File: DefaultYamlConfigParse.java    From nacos-spring-project with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<Object, Object> constructMapping(MappingNode node) {
	try {
		return super.constructMapping(node);
	}
	catch (IllegalStateException ex) {
		throw new ParserException("while parsing MappingNode",
				node.getStartMark(), ex.getMessage(), node.getEndMark());
	}
}
 
Example 16
Source File: BaseConstructor.java    From onedev with MIT License 5 votes vote down vote up
protected void constructMapping2ndStep(MappingNode node, Map<Object, Object> mapping) {
    List<NodeTuple> nodeValue = node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Node valueNode = tuple.getValueNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            try {
                key.hashCode();// check circular dependencies
            } catch (Exception e) {
                throw new ConstructorException("while constructing a mapping",
                        node.getStartMark(), "found unacceptable key " + key,
                        tuple.getKeyNode().getStartMark(), e);
            }
        }
        Object value = constructObject(valueNode);
        if (keyNode.isTwoStepsConstruction()) {
            /*
             * if keyObject is created it 2 steps we should postpone putting
             * it in map because it may have different hash after
             * initialization compared to clean just created one. And map of
             * course does not observe key hashCode changes.
             */
            maps2fill.add(0,
                    new RecursiveTuple<Map<Object, Object>, RecursiveTuple<Object, Object>>(
                            mapping, new RecursiveTuple<Object, Object>(key, value)));
        } else {
            mapping.put(key, value);
        }
    }
}
 
Example 17
Source File: SafeConstructor.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
/**
 * Does merge for supplied mapping node.
 * 
 * @param node
 *            where to merge
 * @param isPreffered
 *            true if keys of node should take precedence over others...
 * @param key2index
 *            maps already merged keys to index from values
 * @param values
 *            collects merged NodeTuple
 * @return list of the merged NodeTuple (to be set as value for the
 *         MappingNode)
 */
private List<NodeTuple> mergeNode(MappingNode node, boolean isPreffered,
        Map<Object, Integer> key2index, List<NodeTuple> values) {
    List<NodeTuple> nodeValue = node.getValue();
    // reversed for http://code.google.com/p/snakeyaml/issues/detail?id=139
    Collections.reverse(nodeValue);
    for (Iterator<NodeTuple> iter = nodeValue.iterator(); 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;
                mergeNode(mn, false, key2index, values);
                break;
            case sequence:
                SequenceNode sn = (SequenceNode) valueNode;
                List<Node> vals = sn.getValue();
                for (Node subnode : vals) {
                    if (!(subnode instanceof MappingNode)) {
                        throw new ConstructorException("while constructing a mapping",
                                node.getStartMark(),
                                "expected a mapping for merging, but found "
                                        + subnode.getNodeId(), subnode.getStartMark());
                    }
                    MappingNode mnode = (MappingNode) subnode;
                    mergeNode(mnode, false, key2index, values);
                }
                break;
            default:
                throw new ConstructorException("while constructing a mapping",
                        node.getStartMark(),
                        "expected a mapping or list of mappings for merging, but found "
                                + valueNode.getNodeId(), valueNode.getStartMark());
            }
        } else {
            // we need to construct keys to avoid duplications
            Object key = constructObject(keyNode);
            if (!key2index.containsKey(key)) { // 1st time merging key
                values.add(nodeTuple);
                // keep track where tuple for the key is
                key2index.put(key, values.size() - 1);
            } else if (isPreffered) { // there is value for the key, but we
                                      // need to override it
                // change value for the key using saved position
                values.set(key2index.get(key), nodeTuple);
            }
        }
    }
    return values;
}
 
Example 18
Source File: SafeConstructor.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Does merge for supplied mapping node.
 * 
 * @param node
 *            where to merge
 * @param isPreffered
 *            true if keys of node should take precedence over others...
 * @param key2index
 *            maps already merged keys to index from values
 * @param values
 *            collects merged NodeTuple
 * @return list of the merged NodeTuple (to be set as value for the
 *         MappingNode)
 */
private List<NodeTuple> mergeNode(MappingNode node, boolean isPreffered,
        Map<Object, Integer> key2index, List<NodeTuple> values) {
    List<NodeTuple> nodeValue = node.getValue();
    // reversed for http://code.google.com/p/snakeyaml/issues/detail?id=139
    Collections.reverse(nodeValue);
    for (Iterator<NodeTuple> iter = nodeValue.iterator(); 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;
                mergeNode(mn, false, key2index, values);
                break;
            case sequence:
                SequenceNode sn = (SequenceNode) valueNode;
                List<Node> vals = sn.getValue();
                for (Node subnode : vals) {
                    if (!(subnode instanceof MappingNode)) {
                        throw new ConstructorException("while constructing a mapping",
                                node.getStartMark(),
                                "expected a mapping for merging, but found "
                                        + subnode.getNodeId(), subnode.getStartMark());
                    }
                    MappingNode mnode = (MappingNode) subnode;
                    mergeNode(mnode, false, key2index, values);
                }
                break;
            default:
                throw new ConstructorException("while constructing a mapping",
                        node.getStartMark(),
                        "expected a mapping or list of mappings for merging, but found "
                                + valueNode.getNodeId(), valueNode.getStartMark());
            }
        } else {
            // we need to construct keys to avoid duplications
            Object key = constructObject(keyNode);
            if (!key2index.containsKey(key)) { // 1st time merging key
                values.add(nodeTuple);
                // keep track where tuple for the key is
                key2index.put(key, values.size() - 1);
            } else if (isPreffered) { // there is value for the key, but we
                                      // need to override it
                // change value for the key using saved position
                values.set(key2index.get(key), nodeTuple);
            }
        }
    }
    return values;
}