use of com.hazelcast.internal.yaml.YamlNode in project hazelcast by hazelcast.
the class YamlMemberDomConfigProcessor method handleTrustedInterfaces.
@Override
protected void handleTrustedInterfaces(TrustedInterfacesConfigurable<?> tiConfig, Node n) {
YamlSequence yamlNode = getWrappedYamlSequence(n);
for (YamlNode interfaceNode : yamlNode.children()) {
String trustedInterface = asScalar(interfaceNode).nodeValue();
tiConfig.addTrustedInterface(trustedInterface);
}
super.handleTrustedInterfaces(tiConfig, n);
}
use of com.hazelcast.internal.yaml.YamlNode in project hazelcast by hazelcast.
the class YamlDomChecker method check.
/**
* Performs {code @null} checks on the provided YAML node recursively.
*
* @param node The YAML node to check for {@code null}s
*/
public static void check(YamlNode node) {
if (node instanceof YamlMapping) {
for (YamlNameNodePair nodePair : ((YamlMapping) node).childrenPairs()) {
YamlNode child = nodePair.childNode();
if (child == null) {
String path = YamlUtil.constructPath(node, nodePair.nodeName());
reportNullEntryOnConcretePath(path);
}
check(nodePair.childNode());
}
} else if (node instanceof YamlSequence) {
for (YamlNode child : ((YamlSequence) node).children()) {
if (child == null) {
throw new InvalidConfigurationException("There is a null configuration entry under sequence " + node.path() + ". Please check if the provided YAML configuration is well-indented and no blocks started without " + "sub-nodes.");
}
check(child);
}
} else {
if (((YamlScalar) node).nodeValue() == null) {
reportNullEntryOnConcretePath(node.path());
}
}
}
use of com.hazelcast.internal.yaml.YamlNode in project hazelcast by hazelcast.
the class W3cDomTest method testW3cDomAdapter.
@Test
public void testW3cDomAdapter() {
InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map-extended.yaml");
YamlNode yamlRoot = YamlLoader.load(inputStream, "root-map");
Node domRoot = W3cDomUtil.asW3cNode(yamlRoot);
NamedNodeMap rootAttributes = domRoot.getAttributes();
Node embeddedMap = rootAttributes.getNamedItem("embedded-map");
NamedNodeMap embeddedMapAttributes = embeddedMap.getAttributes();
String scalarString = embeddedMapAttributes.getNamedItem("scalar-str").getTextContent();
int scalarInt = Integer.parseInt(embeddedMapAttributes.getNamedItem("scalar-int").getTextContent());
double scalarDouble = Double.parseDouble(embeddedMapAttributes.getNamedItem("scalar-double").getTextContent());
boolean scalarBool = Boolean.parseBoolean(embeddedMapAttributes.getNamedItem("scalar-bool").getTextContent());
Node embeddedListNode = embeddedMapAttributes.getNamedItem("embedded-list");
NodeList embeddedList = embeddedListNode.getChildNodes();
String elItem0 = embeddedList.item(0).getTextContent();
Node elItem0AsNode = embeddedList.item(0);
int elItem1 = Integer.parseInt(embeddedList.item(1).getTextContent());
double elItem2 = Double.parseDouble(embeddedList.item(2).getTextContent());
boolean elItem3 = Boolean.parseBoolean(embeddedList.item(3).getTextContent());
NodeList embeddedList2 = embeddedMapAttributes.getNamedItem("embedded-list2").getChildNodes();
String el2Item0 = embeddedList2.item(0).getTextContent();
double el2Item1 = Double.parseDouble(embeddedList2.item(1).getTextContent());
String keysValue = embeddedList.item(4).getAttributes().getNamedItem("key").getTextContent();
String multilineStr = domRoot.getAttributes().getNamedItem("multiline-str").getTextContent();
assertEquals("embedded-map", embeddedMap.getNodeName());
assertEquals("scalar-str", embeddedMap.getChildNodes().item(0).getNodeName());
assertNull(embeddedMap.getChildNodes().item(NOT_EXISTING));
assertNull(embeddedMap.getTextContent());
assertEquals("embedded-list", embeddedMapAttributes.item(4).getNodeName());
assertEquals("embedded-list", embeddedListNode.getNodeName());
assertEquals("embedded-map", embeddedListNode.getParentNode().getNodeName());
assertSame(emptyNamedNodeMap(), embeddedListNode.getAttributes());
assertEquals(6, embeddedMap.getAttributes().getLength());
// root-map/embedded-map/scalars
assertEquals(6, embeddedMap.getChildNodes().getLength());
assertEquals("h4z3lc4st", scalarString);
assertEquals(123, scalarInt);
assertEquals(123.12312D, scalarDouble, 10E-5);
assertTrue(scalarBool);
// root-map/embedded-map/embedded-list
assertEquals("value1", elItem0);
assertEquals(NOT_EXISTING, elItem1);
assertEquals(42.42D, elItem2, 10E-2);
assertFalse(elItem3);
NodeList elItem0ChildNodes = elItem0AsNode.getChildNodes();
assertEquals(1, elItem0ChildNodes.getLength());
assertEquals("value1", elItem0ChildNodes.item(0).getNodeValue());
assertEquals("value1", elItem0AsNode.getNodeValue());
// root-map/embedded-map/embedded-list2
assertEquals(2, embeddedList2.getLength());
assertEquals("value2", el2Item0);
assertEquals(1D, el2Item1, 10E-1);
assertEquals("value", keysValue);
assertEquals("Hazelcast IMDG\n" + "The Leading Open Source In-Memory Data Grid:\n" + "Distributed Computing, Simplified.\n", multilineStr);
Element embeddedMapAsElement = (Element) embeddedMap;
String scalarStrAttr = embeddedMapAsElement.getAttribute("scalar-str");
assertEquals("h4z3lc4st", scalarStrAttr);
assertEquals("embedded-map", embeddedMapAsElement.getTagName());
assertTrue(embeddedMapAsElement.hasAttribute("scalar-str"));
assertEquals("", embeddedMapAsElement.getAttribute("non-existing"));
NodeList nodesByTagName = embeddedMapAsElement.getElementsByTagName("scalar-str");
assertEquals(1, nodesByTagName.getLength());
assertEquals("h4z3lc4st", nodesByTagName.item(0).getNodeValue());
}
use of com.hazelcast.internal.yaml.YamlNode in project hazelcast by hazelcast.
the class YamlMemberDomConfigProcessorTest method toNode.
private static Node toNode(String yaml) {
YamlMapping yamlRootNode = ((YamlMapping) YamlLoader.load(yaml));
YamlNode imdgRoot = yamlRootNode.childAsMapping(ConfigSections.HAZELCAST.getName());
if (imdgRoot == null) {
imdgRoot = yamlRootNode;
}
return asW3cNode(imdgRoot);
}
Aggregations