use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class BLangVMErrors method getCasueStackTrace.
public static String getCasueStackTrace(BStruct error) {
StringBuilder sb = new StringBuilder();
// Get error type name and the message (if any)
String errorMsg = getErrorMessage(error);
sb.append(errorMsg).append("\n\tat ");
BStruct stackFrame = (BStruct) error.getNativeData(STRUCT_CALL_STACK_ELEMENT);
// Append function/action/resource name with package path (if any)
if (stackFrame.getStringField(1).isEmpty() || stackFrame.getStringField(1).equals(PACKAGE_BUILTIN)) {
sb.append(stackFrame.getStringField(0));
} else {
sb.append(stackFrame.getStringField(1)).append(":").append(stackFrame.getStringField(0));
}
// Append the filename
sb.append("(").append(stackFrame.getStringField(2));
// Append the line number
if (stackFrame.getIntField(0) > 0) {
sb.append(":").append(stackFrame.getIntField(0));
}
sb.append(")");
BRefValueArray cause = (BRefValueArray) error.getRefField(0);
if (cause != null && cause.size() > 0) {
sb.append("\ncaused by ").append(getCauseStackTraceArray(cause));
}
return sb.toString();
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class BLangVMErrors method generateCallStack.
public static BRefValueArray generateCallStack(WorkerExecutionContext context, CallableUnitInfo nativeCUI) {
BRefValueArray callStack = new BRefValueArray();
long index = 0;
if (nativeCUI != null) {
callStack.add(index, getStackFrame(nativeCUI, 0));
index++;
}
while (!context.isRootContext()) {
callStack.add(index, getStackFrame(context));
context = context.parent;
index++;
}
return callStack;
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class BRunUtil method spreadToBValueArray.
private static BValue[] spreadToBValueArray(BValue[] response) {
if (!(response != null && response.length > 0 && response[0] instanceof BRefValueArray)) {
return response;
}
BRefValueArray refValueArray = (BRefValueArray) response[0];
int length = (int) refValueArray.size();
BValue[] arr = new BValue[length];
for (int i = 0; i < length; i++) {
arr[i] = refValueArray.get(i);
}
return arr;
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class JSONUtils method convertToXML.
/**
* Converts given json object to the corresponding xml.
*
* @param json JSON object to get the corresponding xml
* @param attributePrefix String prefix used for attributes
* @param arrayEntryTag String used as the tag in the arrays
* @return BXML XML representation of the given json object
*/
@SuppressWarnings("rawtypes")
public static BXML convertToXML(BJSON json, String attributePrefix, String arrayEntryTag) {
BXML xml;
JsonNode jsonNode = json.value();
List<BXML> omElementArrayList = traverseTree(jsonNode, attributePrefix, arrayEntryTag);
if (omElementArrayList.size() == 1) {
xml = omElementArrayList.get(0);
} else {
// There is a multi rooted node and create xml sequence from it
BRefValueArray elementsSeq = new BRefValueArray();
int count = omElementArrayList.size();
for (int i = 0; i < count; i++) {
elementsSeq.add(i, omElementArrayList.get(i));
}
xml = new BXMLSequence(elementsSeq);
}
return xml;
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class XMLUtils method concatenate.
/**
* Concatenate two XML sequences and produce a single sequence.
*
* @param firstSeq First XML sequence
* @param secondSeq Second XML sequence
* @return Concatenated XML sequence
*/
public static BXML<?> concatenate(BXML<?> firstSeq, BXML<?> secondSeq) {
BRefValueArray concatSeq = new BRefValueArray();
int j = 0;
// Load the content fully before concat the two
firstSeq.build();
secondSeq.build();
// Add all the items in the first sequence
if (firstSeq.getNodeType() == XMLNodeType.SEQUENCE) {
BRefValueArray seq = ((BXMLSequence) firstSeq).value();
for (int i = 0; i < seq.size(); i++) {
concatSeq.add(j++, seq.get(i));
}
} else {
concatSeq.add(j++, firstSeq);
}
// Add all the items in the second sequence
if (secondSeq.getNodeType() == XMLNodeType.SEQUENCE) {
BRefValueArray seq = ((BXMLSequence) secondSeq).value();
for (int i = 0; i < seq.size(); i++) {
concatSeq.add(j++, seq.get(i));
}
} else {
concatSeq.add(j++, secondSeq);
}
return new BXMLSequence(concatSeq);
}
Aggregations