Refine search
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.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); mnode.setUseClassConstructor(true); Class<?> valueType = arguments[1]; MappingNode mnode = (MappingNode) valueNode; mnode.setTypes(ketType, valueType); mnode.setUseClassConstructor(true); throw new ConstructorException( "Cannot create property=" + key + " for JavaBean=" + object, node.getStartMark(), e.getMessage(), valueNode.getStartMark(), e);
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);
protected void flattenMapping(MappingNode node) { // perform merging only on nodes containing merge node(s) processDuplicateKeys(node); if (node.isMerged()) { node.setValue(mergeNode(node, true, new HashMap<Object, Integer>(), new ArrayList<NodeTuple>())); } }
@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 + ")>"; }
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); omap.put(key, value);
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);
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)); if (actionNode.getNodeId() != mapping) for (NodeTuple actionTuple : ((MappingNode) actionNode).getValue()) String actionTupleKey = ((ScalarNode) actionTuple.getKeyNode()).getValue(); if (actionTupleKey.equals(TRAIT_USE_KEY) && expect(actionTuple.getValueNode(), sequence))
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; mergeNode(mn, false, key2index, values); break; case sequence: if (!(subnode instanceof MappingNode)) { throw new ConstructorException("while constructing a mapping", node.getStartMark(), "expected a mapping for merging, but found " + subnode.getNodeId(), subnode.getStartMark()); mergeNode(mnode, false, key2index, values); node.getStartMark(), "expected a mapping or list of mappings for merging, but found " + valueNode.getNodeId(),
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); } } }
@Override protected Object constructJavaBean2ndStep(MappingNode node, Object object) { Class<?> type = node.getType(); for (NodeTuple valueNode : node.getValue()) { Node keyNode = valueNode.getKeyNode(); Node childValueNode = valueNode.getValueNode(); if (keyNode instanceof ScalarNode && "configuration".equals(((ScalarNode) keyNode).getValue())) { childValueNode.setTag(XPP3DOM_TAG);
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()); }
private void doVisitMappingNode(MappingNode mappingNode) if (mappingNode.isMerged()) List<NodeTuple> tuples = mappingNode.getValue(); List<NodeTuple> updatedTuples = new ArrayList<NodeTuple>(); for (NodeTuple nodeTuple : tuples) Node keyNode = nodeTuple.getKeyNode(); Node originalValueNode = nodeTuple.getValueNode(); Tag tag = originalValueNode.getTag(); TagResolver currentTagResolver = getTagResolver(tag); Node resolvedNode = resolveTag(tag, currentTagResolver, originalValueNode); if (originalValueNode != resolvedNode) nodeTuple = new NodeTuple(keyNode, resolvedNode); mappingNode.setValue(updatedTuples);
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) { try { node.getStartMark(), "found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e); if (!isAllowDuplicateKeys()) { throw new DuplicateKeyException(node.getStartMark(), key, tuple.getKeyNode().getStartMark());
/** * 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; } }
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());
@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 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; } }