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