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);
protected Node composeScalarNode(String anchor) { ScalarEvent ev = (ScalarEvent) parser.getEvent(); String tag = ev.getTag(); boolean resolved = false; Tag nodeTag; if (tag == null || tag.equals("!")) { nodeTag = resolver.resolve(NodeId.scalar, ev.getValue(), ev.getImplicit().canOmitTagInPlainScalar()); resolved = true; } else { nodeTag = new Tag(tag); } Node node = new ScalarNode(nodeTag, resolved, ev.getValue(), ev.getStartMark(), ev.getEndMark(), ev.getScalarStyle()); if (anchor != null) { anchors.put(anchor, node); } return node; }
KeyScalarNode(ScalarNode node) { super(node.getTag(), node.getValue(), node.getStartMark(), node.getEndMark(), node.getScalarStyle()); }
public Object construct(Node nnode) { ScalarNode node = (ScalarNode) nnode; Class<?> type = node.getType(); || type == Character.class || type == BigInteger.class || type == BigDecimal.class || Enum.class.isAssignableFrom(type) || Tag.BINARY.equals(node.getTag()) || Calendar.class.isAssignableFrom(type) || type == UUID.class) { } catch (Exception e) { throw new YAMLException("Can't construct a java object for scalar " + node.getTag() + "; No String constructor found. Exception=" + e.getMessage(), e); } catch (Exception e) { throw new ConstructorException(null, null, "Can't construct a java object for scalar " + node.getTag() + "; exception=" + e.getMessage(), node.getStartMark(), e);
/** * 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; } }
@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); }
/** * Returns true if the argument can be identified as a JSON reference node. * * @param tuple * @return true if a reference node */ public static boolean isReference(NodeTuple tuple) { if (tuple.getKeyNode().getNodeId() == NodeId.scalar) { String value = ((ScalarNode) tuple.getKeyNode()).getValue(); return JsonReference.PROPERTY.equals(value) && tuple.getValueNode().getNodeId() == NodeId.scalar; } return false; }
@Override public Node resolve(Node node, ResourceLoader resourceLoader, NodeHandler nodeHandler) { String className = ((ScalarNode) node).getValue(); try { Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className); JAXBContext context = JAXBContext.newInstance(clazz); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); context.generateSchema(new SchemaOutputResolver() { @Override public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException { StreamResult result = new StreamResult(baos); result.setSystemId("001"); return result; } }); String schema = baos.toString(); return new ScalarNode(Tag.STR, schema, node.getStartMark(), node.getEndMark(), ((ScalarNode) node).getStyle()); } catch (Exception e) { throw new YAMLException(e); } }
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; }
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(); } else if (node instanceof MappingNode) { 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 protected NodeTuple representJavaBeanProperty(Object bean, Property property, Object value, Tag customTag) { NodeTuple tuple = super.representJavaBeanProperty(bean, property, value, customTag); if (isNullValue(tuple) || isEmptySequence(tuple) || isEmptyMapping(tuple)) { return null; } if ("body".equals(property.getName())) { ScalarNode n = (ScalarNode) tuple.getValueNode(); if (n.getStyle() == PLAIN.getChar()) { return tuple; } else { return new NodeTuple(tuple.getKeyNode(), new ScalarNode(n.getTag(), n.getValue(), n .getStartMark(), n.getEndMark(), LITERAL.getChar())); } } return tuple; }
@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);
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())); } else if ("float".equals(className)) { json.writeNumber(Double.parseDouble(scalarNode.getValue())); } else if ("null".equals(className)) { json.writeNull(); } else { json.writeString(scalarNode.getValue());
private ScalarNode cloneScalarNode(ScalarNode node, Map<String, String> parameters) { String value = node.getValue(); Matcher matcher = TEMPLATE_PARAMETER_PATTERN.matcher(value); StringBuffer sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, ""); sb.append(resolveParameter(matcher.group(), parameters, node)); } matcher.appendTail(sb); return new ScalarNode(node.getTag(), sb.toString(), node.getStartMark(), node.getEndMark(), node.getStyle()); }
public IncludeInfo(ScalarNode node, String parentPath) { this(node.getStartMark(), node.getEndMark(), resolveAbsolutePath(node.getValue(), parentPath)); }
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(); }
public Object construct(Node node) { ScalarNode tmpNode; if (node instanceof MappingNode) { // Compact Object Notation may contain only one entry MappingNode mnode = (MappingNode) node; NodeTuple nodeTuple = mnode.getValue().iterator().next(); node.setTwoStepsConstruction(true); tmpNode = (ScalarNode) nodeTuple.getKeyNode(); // return constructScalar((ScalarNode) keyNode); } else { tmpNode = (ScalarNode) node; } CompactData data = getCompactData(tmpNode.getValue()); if (data == null) { // TODO: Should we throw an exception here ? return constructScalar(tmpNode); } return constructCompactFormat(tmpNode, data); } }