Search in sources :

Example 16 with BRefValueArray

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();
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Example 17 with BRefValueArray

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;
}
Also used : BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Example 18 with BRefValueArray

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;
}
Also used : BValue(org.ballerinalang.model.values.BValue) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Example 19 with BRefValueArray

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;
}
Also used : BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BXML(org.ballerinalang.model.values.BXML) BXMLSequence(org.ballerinalang.model.values.BXMLSequence)

Example 20 with BRefValueArray

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);
}
Also used : BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BXMLSequence(org.ballerinalang.model.values.BXMLSequence)

Aggregations

BRefValueArray (org.ballerinalang.model.values.BRefValueArray)83 BValue (org.ballerinalang.model.values.BValue)45 Test (org.testng.annotations.Test)40 BStruct (org.ballerinalang.model.values.BStruct)37 BString (org.ballerinalang.model.values.BString)22 BInteger (org.ballerinalang.model.values.BInteger)18 BXMLSequence (org.ballerinalang.model.values.BXMLSequence)9 BeforeTest (org.testng.annotations.BeforeTest)9 BIntArray (org.ballerinalang.model.values.BIntArray)7 BMap (org.ballerinalang.model.values.BMap)7 BStringArray (org.ballerinalang.model.values.BStringArray)7 BXML (org.ballerinalang.model.values.BXML)7 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)7 HashMap (java.util.HashMap)6 BStructType (org.ballerinalang.model.types.BStructType)6 BRefType (org.ballerinalang.model.values.BRefType)5 SQLDatasource (org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource)5 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)4 BFloatArray (org.ballerinalang.model.values.BFloatArray)4 IOException (java.io.IOException)3