Search in sources :

Example 91 with BString

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

the class BalScheduleAppointment method execute.

public void execute(Context ctx) {
    FunctionRefCPEntry onTriggerFunctionRefCPEntry;
    FunctionRefCPEntry onErrorFunctionRefCPEntry = null;
    if (ctx.getLocalWorkerData().refRegs[0] != null && ctx.getLocalWorkerData().refRegs[0] instanceof BFunctionPointer) {
        onTriggerFunctionRefCPEntry = ((BFunctionPointer) ctx.getRefArgument(0)).value();
    } else {
        ctx.setReturnValues(new BString(""), BLangVMErrors.createError(ctx, 0, "The onTrigger function is not provided"));
        return;
    }
    if (ctx.getLocalWorkerData().refRegs[1] != null && ctx.getLocalWorkerData().refRegs[1] instanceof BFunctionPointer) {
        onErrorFunctionRefCPEntry = ((BFunctionPointer) ctx.getRefArgument(1)).value();
    }
    String schedule = ctx.getStringArgument(0);
    try {
        Appointment appointment = new Appointment(this, ctx, schedule, onTriggerFunctionRefCPEntry, onErrorFunctionRefCPEntry);
        ctx.setReturnValues(new BString(appointment.getId()));
    } catch (SchedulingException e) {
        ctx.setReturnValues(BLangVMErrors.createError(ctx, 0, e.getMessage()));
    }
}
Also used : FunctionRefCPEntry(org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) SchedulingException(org.ballerinalang.nativeimpl.task.SchedulingException) BFunctionPointer(org.ballerinalang.model.values.BFunctionPointer)

Example 92 with BString

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

the class BalScheduleTimer method execute.

public void execute(Context ctx) {
    FunctionRefCPEntry onTriggerFunctionRefCPEntry;
    FunctionRefCPEntry onErrorFunctionRefCPEntry = null;
    if (ctx.getLocalWorkerData().refRegs[0] != null && ctx.getLocalWorkerData().refRegs[0] instanceof BFunctionPointer) {
        onTriggerFunctionRefCPEntry = ((BFunctionPointer) ctx.getRefArgument(0)).value();
    } else {
        ctx.setReturnValues(new BString(""), BLangVMErrors.createError(ctx, 0, "The onTrigger function is not provided"));
        return;
    }
    if (ctx.getLocalWorkerData().refRegs[1] != null && ctx.getLocalWorkerData().refRegs[1] instanceof BFunctionPointer) {
        onErrorFunctionRefCPEntry = ((BFunctionPointer) ctx.getRefArgument(1)).value();
    }
    BStruct scheduler = (BStruct) ctx.getRefArgument(2);
    long delay = scheduler.getIntField(0);
    long interval = scheduler.getIntField(1);
    try {
        Timer timer = new Timer(this, ctx, delay, interval, onTriggerFunctionRefCPEntry, onErrorFunctionRefCPEntry);
        ctx.setReturnValues(new BString(timer.getId()));
    } catch (SchedulingException e) {
        ctx.setReturnValues(BLangVMErrors.createError(ctx, 0, e.getMessage()));
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) FunctionRefCPEntry(org.ballerinalang.util.codegen.cpentries.FunctionRefCPEntry) BString(org.ballerinalang.model.values.BString) SchedulingException(org.ballerinalang.nativeimpl.task.SchedulingException) BFunctionPointer(org.ballerinalang.model.values.BFunctionPointer)

Example 93 with BString

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

the class WeekDay method execute.

@Override
public void execute(Context context) {
    BStruct timeStruct = ((BStruct) context.getRefArgument(0));
    context.setReturnValues(new BString(getWeekDay(timeStruct)));
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BString(org.ballerinalang.model.values.BString)

Example 94 with BString

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

the class FormatTo method execute.

@Override
public void execute(Context context) {
    BStruct timeStruct = ((BStruct) context.getRefArgument(0));
    BEnumerator pattern = (BEnumerator) context.getRefArgument(1);
    switch(pattern.getName()) {
        case "RFC_1123":
            ZonedDateTime zonedDateTime = getZonedDateTime(timeStruct);
            String formattedDateTime = zonedDateTime.format(DateTimeFormatter.RFC_1123_DATE_TIME);
            context.setReturnValues(new BString(formattedDateTime));
            break;
        default:
            throw new BallerinaException("failed to format date/time: unrecognized time format");
    }
}
Also used : BEnumerator(org.ballerinalang.model.values.BEnumerator) BStruct(org.ballerinalang.model.values.BStruct) ZonedDateTime(java.time.ZonedDateTime) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 95 with BString

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

the class Base64Decode method execute.

@Override
public void execute(Context context) {
    String value = context.getStringArgument(0);
    byte[] decodedValue = Base64.getDecoder().decode(value.getBytes(Charset.defaultCharset()));
    context.setReturnValues(new BString(new String(decodedValue, Charset.defaultCharset())));
}
Also used : BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString)

Aggregations

BString (org.ballerinalang.model.values.BString)418 BValue (org.ballerinalang.model.values.BValue)339 Test (org.testng.annotations.Test)321 BInteger (org.ballerinalang.model.values.BInteger)77 BStruct (org.ballerinalang.model.values.BStruct)76 BMap (org.ballerinalang.model.values.BMap)37 BBoolean (org.ballerinalang.model.values.BBoolean)36 BFloat (org.ballerinalang.model.values.BFloat)34 BJSON (org.ballerinalang.model.values.BJSON)28 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)21 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)18 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)11 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)11 CompileResult (org.ballerinalang.launcher.util.CompileResult)11 BBlob (org.ballerinalang.model.values.BBlob)11 BStringArray (org.ballerinalang.model.values.BStringArray)11 BType (org.ballerinalang.model.types.BType)10 BIntArray (org.ballerinalang.model.values.BIntArray)9 BRefType (org.ballerinalang.model.values.BRefType)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7