use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class XMLUtils method parse.
/**
* Create a XML sequence from string inputstream.
*
* @param xmlStream XML imput stream
* @return XML Sequence
*/
@SuppressWarnings("unchecked")
public static BXML<?> parse(InputStream xmlStream) {
BRefValueArray elementsSeq = new BRefValueArray();
OMDocument doc;
try {
doc = OMXMLBuilderFactory.createOMBuilder(xmlStream).getDocument();
Iterator<OMNode> docChildItr = doc.getChildren();
int i = 0;
while (docChildItr.hasNext()) {
elementsSeq.add(i++, new BXMLItem(docChildItr.next()));
}
} catch (DeferredParsingException e) {
throw new BallerinaException(e.getCause().getMessage());
} catch (Throwable e) {
throw new BallerinaException("failed to create xml: " + e.getMessage());
}
return new BXMLSequence(elementsSeq);
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class MapInitializerExprTest method testComplexMapInit.
@Test
public void testComplexMapInit() {
BValue[] returns = BRunUtil.invoke(compileResult, "testComplexMapInit", new BValue[] {});
Assert.assertTrue(returns[0] instanceof BMap<?, ?>);
BMap<String, BValue> outerMap = (BMap<String, BValue>) returns[0];
Assert.assertEquals(outerMap.get("name").stringValue(), "Supun");
BValue adrsArray = outerMap.get("addressArray");
Assert.assertTrue(adrsArray instanceof BRefValueArray);
BRefValueArray addressArray = (BRefValueArray) adrsArray;
BValue adrs1 = addressArray.get(0);
Assert.assertTrue(adrs1 instanceof BMap<?, ?>);
BValue address = ((BMap) adrs1).get("address");
Assert.assertTrue(address instanceof BMap<?, ?>);
Assert.assertEquals(((BMap) address).get("city").stringValue(), "Colombo");
BValue adrs2 = addressArray.get(1);
Assert.assertTrue(adrs2 instanceof BMap<?, ?>);
address = ((BMap) adrs2).get("address");
Assert.assertTrue(address instanceof BMap<?, ?>);
Assert.assertEquals(((BMap) address).get("city").stringValue(), "Kandy");
BValue adrs3 = addressArray.get(2);
Assert.assertTrue(adrs3 instanceof BMap<?, ?>);
address = ((BMap) adrs3).get("address");
Assert.assertTrue(address instanceof BMap<?, ?>);
Assert.assertEquals(((BMap) address).get("city").stringValue(), "Galle");
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class BNullValueTest method testArrayOfNulls.
@Test(description = "Test array of null values")
public void testArrayOfNulls() {
BValue[] vals = BRunUtil.invoke(positiveCompileResult, "testArrayOfNulls", new BValue[] {});
BRefValueArray nullArray = (BRefValueArray) vals[0];
Assert.assertTrue(nullArray.get(0) instanceof BStruct);
Assert.assertEquals(nullArray.get(1), null);
Assert.assertEquals(nullArray.get(2), null);
Assert.assertTrue(nullArray.get(3) instanceof BStruct);
Assert.assertEquals(nullArray.get(4), null);
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class XMLLiteralTest method testElementLiteralWithNamespaces.
@Test
public void testElementLiteralWithNamespaces() {
BValue[] returns = BRunUtil.invoke(literalWithNamespacesResult, "testElementLiteralWithNamespaces");
Assert.assertTrue(returns[0] instanceof BXML);
Assert.assertEquals(returns[0].stringValue(), "<root xmlns=\"http://ballerina.com/\" xmlns:ns0=\"http://ballerina.com/a\" " + "xmlns:ns1=\"http://ballerina.com/c\" ns0:id=\"456\"><foo>123</foo>" + "<bar ns1:status=\"complete\"/></root>");
Assert.assertTrue(returns[1] instanceof BXML);
BXMLSequence seq = (BXMLSequence) returns[1];
Assert.assertEquals(seq.stringValue(), "<foo xmlns=\"http://ballerina.com/\" " + "xmlns:ns0=\"http://ballerina.com/a\" xmlns:ns1=\"http://ballerina.com/c\">123</foo>" + "<bar xmlns=\"http://ballerina.com/\" xmlns:ns0=\"http://ballerina.com/a\" " + "xmlns:ns1=\"http://ballerina.com/c\" ns1:status=\"complete\"/>");
BRefValueArray items = seq.value();
Assert.assertEquals(items.size(), 2);
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class XMLLiteralTest method testElementLiteralWithTemplateChildren.
@Test
public void testElementLiteralWithTemplateChildren() {
BValue[] returns = BRunUtil.invoke(result, "testElementLiteralWithTemplateChildren");
Assert.assertTrue(returns[0] instanceof BXML);
Assert.assertEquals(returns[0].stringValue(), "<root>hello aaa<bbb good morning <fname>John</fname> " + "<lname>Doe</lname>. Have a nice day!<foo>123</foo><bar/></root>");
Assert.assertTrue(returns[1] instanceof BXML);
BXMLSequence seq = (BXMLSequence) returns[1];
Assert.assertEquals(seq.stringValue(), "hello aaa<bbb good morning <fname>John</fname> <lname>Doe</lname>. " + "Have a nice day!<foo>123</foo><bar/>");
BRefValueArray items = seq.value();
Assert.assertEquals(items.size(), 7);
}
Aggregations