Refine search
private void serializeNode(Node node, Node parent) throws IOException { if (node.getNodeId() == NodeId.anchor) { node = ((AnchorNode) node).getRealNode(); } 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; implicitM, null, null, ((CollectionNode) node).getFlowStyle())); MappingNode mnode = (MappingNode) node; List<NodeTuple> map = mnode.getValue(); for (NodeTuple row : map) { Node key = row.getKeyNode(); Node value = row.getValueNode(); serializeNode(key, mnode); serializeNode(value, mnode);
NodeId nodeId = nodeValue.getNodeId(); if (customTag == null) { if (nodeId == NodeId.scalar) { nodeValue.setTag(Tag.STR); if (property.getType() == propertyValue.getClass()) { if (!(propertyValue instanceof Map<?, ?>)) { if (!nodeValue.getTag().equals(Tag.SET)) { nodeValue.setTag(Tag.MAP); return new NodeTuple(nodeKey, nodeValue);
@Override public String toString() { String values; StringBuilder buf = new StringBuilder(); for (NodeTuple node : getValue()) { buf.append("{ key="); buf.append(node.getKeyNode()); buf.append("; value="); if (node.getValueNode() instanceof CollectionNode) { // to avoid overflow in case of recursive structures buf.append(System.identityHashCode(node.getValueNode())); } else { buf.append(node.toString()); } buf.append(" }"); } values = buf.toString(); return "<" + this.getClass().getName() + " (tag=" + getTag() + ", values=" + values + ")>"; }
public void setTypes(Class<? extends Object> keyType, Class<? extends Object> valueType) { for (NodeTuple nodes : value) { nodes.getValueNode().setType(valueType); nodes.getKeyNode().setType(keyType); } }
public static NodeTuple get(NodeTuple nodeTuple) { Node keyNode = nodeTuple.getKeyNode(); Node valueNode = nodeTuple.getValueNode(); return new NodeTuple(KeyScalarNode.get(keyNode), valueNode); }
protected Object constructJavaBean2ndStep(MappingNode node, Object object) { flattenMapping(node); Class<? extends Object> beanType = node.getType(); List<NodeTuple> nodeValue = node.getValue(); for (NodeTuple tuple : nodeValue) { ScalarNode keyNode; if (tuple.getKeyNode() instanceof ScalarNode) { keyNode = (ScalarNode) tuple.getKeyNode(); } else { throw new YAMLException( "Keys must be scalars but found: " + tuple.getKeyNode()); Node valueNode = tuple.getValueNode(); keyNode.setType(String.class); String key = (String) constructObject(keyNode); try { if (valueNode.getNodeId() == NodeId.sequence) { Class<?> t = arguments[0]; SequenceNode snode = (SequenceNode) valueNode; Class<?> t = arguments[0]; MappingNode mnode = (MappingNode) valueNode; mnode.setOnlyKeyType(t);
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(),
/** * Dirty hack - remove 'id' if it is present. * * @param node - the node to remove the coordinate from * @return removed coordinate if it was removed */ private String removeId(MappingNode node) { NodeTuple id = null; String scalar = null; for (NodeTuple tuple : node.getValue()) { ScalarNode keyNode = (ScalarNode) tuple.getKeyNode(); String key = keyNode.getValue(); if ("id".equals(key)) { id = tuple; ScalarNode valueNode = (ScalarNode) tuple.getValueNode(); scalar = valueNode.getValue(); } } if (id != null) { node.getValue().remove(id); } return scalar; } }
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); else if (key.equals(TRAIT_USE_KEY) && expect(resourceTuple.getValueNode(), sequence)) SequenceNode sequence = cloneSequenceNode((SequenceNode) resourceTuple.getValueNode(), new HashMap<String, String>()); templateReferences.traitsReference.put(ALL_ACTIONS, sequence); removeParametersFromTraitsCall(resourceTuple); Node actionNode = resourceTuple.getValueNode(); if (actionNode.getTag().equals(Tag.NULL)) resourceNode.getValue().remove(i); resourceNode.getValue().add(i, new NodeTuple(resourceTuple.getKeyNode(), actionNode)); String actionTupleKey = ((ScalarNode) actionTuple.getKeyNode()).getValue(); if (actionTupleKey.equals(TRAIT_USE_KEY) && expect(actionTuple.getValueNode(), sequence)) SequenceNode sequence = cloneSequenceNode((SequenceNode) actionTuple.getValueNode(), new HashMap<String, String>()); templateReferences.traitsReference.put(normalizeKey(key), sequence); removeParametersFromTraitsCall(actionTuple);
@Override protected Construct getConstructor(Node node) { if (node instanceof MappingNode) { MappingNode mnode = (MappingNode) node; List<NodeTuple> list = mnode.getValue(); if (list.size() == 1) { NodeTuple tuple = list.get(0); Node key = tuple.getKeyNode(); if (key instanceof ScalarNode) { ScalarNode scalar = (ScalarNode) key; if (GUESS_COMPACT.matcher(scalar.getValue()).matches()) { return getCompactConstruct(); } } } } else if (node instanceof ScalarNode) { ScalarNode scalar = (ScalarNode) node; if (GUESS_COMPACT.matcher(scalar.getValue()).matches()) { return getCompactConstruct(); } } return super.getConstructor(node); }
private MappingNode cloneMappingNode(MappingNode node, Map<String, String> parameters) { List<NodeTuple> tuples = new ArrayList<NodeTuple>(); for (NodeTuple tuple : node.getValue()) { if (tuple.getKeyNode().getNodeId() != scalar) { addError(NON_SCALAR_KEY_MESSAGE, tuple.getKeyNode()); break; } Node key = cloneScalarNode((ScalarNode) tuple.getKeyNode(), parameters); Node value = cloneNode(tuple.getValueNode(), parameters); tuples.add(new NodeTuple(key, value)); } return new MappingNode(node.getTag(), tuples, node.getFlowStyle()); }
if (!(node instanceof SequenceNode)) { throw new ConstructorException("while constructing an ordered map", node.getStartMark(), "expected a sequence, but found " + node.getNodeId(), node.getStartMark()); 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);
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());
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); } } }
String yamlType = null; INodeParser<?> parser = null; if (mappingNode.getValue().size() > 0) { NodeTuple tuple = mappingNode.getValue().get(0); yamlType = ParserUtils.getScalar(tuple.getKeyNode(), context); if (!(tuple.getValueNode() instanceof ScalarNode)) { log.debug("Ignore mapping for yaml type <" + yamlType + ">"); return null; String type = ParserUtils.getScalar(tuple.getValueNode(), context); if (type.startsWith("__")) { parser = getWrapperParser(type, mappingNode, context); mappingNode.getValue().add(0, new NodeTuple(new ScalarNode(new Tag(builder.getKey()), builder.getKey(), tuple.getKeyNode().getStartMark(), tuple.getKeyNode().getEndMark(), 'c'), tuple.getValueNode())); context.getParsingErrors().add(new ParsingError(ErrorCode.SYNTAX_ERROR, "Unable to process type mapping.", node.getStartMark(), "Mapping must be defined using a mapping node.", node.getEndMark(), ""));
if (node.getNodeId() == NodeId.sequence) { if (member != null) { if (t.equals(member.getClass())) if (childNode.getNodeId() == NodeId.mapping) { childNode.setTag(Tag.MAP); Class<?> t = arguments[0]; MappingNode mnode = (MappingNode) node; Iterator<NodeTuple> iter = mnode.getValue().iterator(); Set<?> set = (Set<?>) object; for (Object member : set) { NodeTuple tuple = iter.next(); Node keyNode = tuple.getKeyNode(); if (t.equals(member.getClass())) { if (keyNode.getNodeId() == NodeId.mapping) { Class<?> valueType = arguments[1]; MappingNode mnode = (MappingNode) node; for (NodeTuple tuple : mnode.getValue()) { resetTag(keyType, tuple.getKeyNode()); resetTag(valueType, tuple.getValueNode());
private String getTemplateName(Node templateReferenceNode) { Node templateNameNode = templateReferenceNode; if (templateReferenceNode.getNodeId() == mapping) { templateNameNode = ((MappingNode) templateReferenceNode).getValue().get(0).getKeyNode(); } return ((ScalarNode) templateNameNode).getValue(); }
@Override public Object parse(Node node, ParsingContextExecution context) { if (node instanceof MappingNode) { NodeTuple nodeTuple = ((MappingNode) node).getValue().get(0); if (nodeTuple.getKeyNode() instanceof ScalarNode) { String key = ((ScalarNode) nodeTuple.getKeyNode()).getValue(); context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNRECOGNIZED_PROPERTY, "Ignored field during import", nodeTuple.getKeyNode().getStartMark(), "tosca key is not recognized", nodeTuple.getValueNode().getEndMark(), key)); } } return null; } }
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()));
@Override public TupleRule<?, ?> getRuleForTuple(NodeTuple nodeTuple) { if (nodeTuple.getKeyNode().getNodeId() == scalar && nodeTuple.getValueNode().getNodeId() == scalar) { String schemaKey = ((ScalarNode) nodeTuple.getKeyNode()).getValue(); ScalarNode valueNode = (ScalarNode) nodeTuple.getValueNode(); schemas.put(schemaKey, valueNode); } return super.getRuleForTuple(nodeTuple); } }