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;
}
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;
}
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));
}
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));
}
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);
}
}
Aggregations