Search in sources :

Example 76 with BRefValueArray

use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.

the class AbstractAnnotationReader method createAnnotationStructArray.

private BRefValueArray createAnnotationStructArray(Context context, BValue map) {
    if (map == null || map.getType().getTag() != BTypes.typeMap.getTag()) {
        return null;
    }
    final PackageInfo packageInfo = context.getProgramFile().getPackageInfo(PKG_INTERNAL);
    final StructInfo structInfo = packageInfo.getStructInfo(STRUCT_ANNOTATION);
    BRefValueArray annotationArray = new BRefValueArray(structInfo.getType());
    BMap<String, BValue> annotationMap = (BMap<String, BValue>) map;
    long index = 0;
    for (String key : annotationMap.keySet()) {
        final String annotaionQName = key.split("\\$")[0];
        final String[] qNameParts = annotaionQName.split(":");
        final BStruct annotation = BLangVMStructs.createBStruct(structInfo, qNameParts[1], qNameParts[0], annotationMap.get(key));
        annotationArray.add(index++, annotation);
    }
    return annotationArray;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) BMap(org.ballerinalang.model.values.BMap) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) BValue(org.ballerinalang.model.values.BValue) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Example 77 with BRefValueArray

use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.

the class Read method readResponse.

/*
     * Function which will be notified on the response obtained after the async operation.
     *
     * @param result context of the callback.
     * @return Once the callback is processed we further return back the result.
     */
private static EventResult readResponse(EventResult<Integer, EventContext> result) {
    BStruct errorStruct;
    BRefValueArray contentTuple = new BRefValueArray(readTupleType);
    EventContext eventContext = result.getContext();
    Context context = eventContext.getContext();
    Throwable error = eventContext.getError();
    Integer numberOfBytes = result.getResponse();
    CallableUnitCallback callback = eventContext.getCallback();
    byte[] content = (byte[]) eventContext.getProperties().get(ReadBytesEvent.CONTENT_PROPERTY);
    if (null != error) {
        errorStruct = IOUtils.createError(context, error.getMessage());
        context.setReturnValues(errorStruct);
    } else {
        contentTuple.add(0, new BBlob(content));
        contentTuple.add(1, new BInteger(numberOfBytes));
        context.setReturnValues(contentTuple);
    }
    callback.notifySuccess();
    return result;
}
Also used : EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) Context(org.ballerinalang.bre.Context) EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) BInteger(org.ballerinalang.model.values.BInteger) BStruct(org.ballerinalang.model.values.BStruct) BInteger(org.ballerinalang.model.values.BInteger) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BBlob(org.ballerinalang.model.values.BBlob) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Example 78 with BRefValueArray

use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.

the class QueryTableWithJoinClause method execute.

/**
 * Where Native Function logic is implemented.
 *
 * @param context Current Context instance
 */
@Override
public void execute(Context context) {
    String query = context.getStringArgument(0);
    BTable fromTable = (BTable) context.getRefArgument(0);
    BTable joinTable = (BTable) context.getRefArgument(1);
    BRefValueArray array = (BRefValueArray) context.getRefArgument(2);
    BStruct tableTypeStruct = (BStruct) context.getRefArgument(3);
    context.setReturnValues(new BTable(query, fromTable, joinTable, tableTypeStruct.getType(), array));
}
Also used : BTable(org.ballerinalang.model.values.BTable) BStruct(org.ballerinalang.model.values.BStruct) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Example 79 with BRefValueArray

use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.

the class QueryTableWithoutJoinClause method execute.

/**
 * Where Native Function logic is implemented.
 *
 * @param context Current Context instance
 */
@Override
public void execute(Context context) {
    String query = context.getStringArgument(0);
    BTable fromTable = (BTable) context.getRefArgument(0);
    BRefValueArray array = (BRefValueArray) context.getRefArgument(1);
    BStruct tableTypeStruct = (BStruct) context.getRefArgument(2);
    context.setReturnValues(new BTable(query, fromTable, null, tableTypeStruct.getType(), array));
}
Also used : BTable(org.ballerinalang.model.values.BTable) BStruct(org.ballerinalang.model.values.BStruct) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Example 80 with BRefValueArray

use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.

the class EntityBodyHandler method setPartsToTopLevelEntity.

/**
 * Set ballerina body parts to it's top level entity.
 *
 * @param entity    Represent top level message's entity
 * @param bodyParts Represent ballerina body parts
 */
static void setPartsToTopLevelEntity(BStruct entity, ArrayList<BStruct> bodyParts) {
    if (!bodyParts.isEmpty()) {
        BStructType typeOfBodyPart = bodyParts.get(FIRST_BODY_PART_INDEX).getType();
        BStruct[] result = bodyParts.toArray(new BStruct[bodyParts.size()]);
        BRefValueArray partsArray = new BRefValueArray(result, typeOfBodyPart);
        entity.addNativeData(BODY_PARTS, partsArray);
    }
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BStruct(org.ballerinalang.model.values.BStruct) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

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