Search in sources :

Example 6 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.

the class HttpUtil method getGenericError.

/**
 * Extract generic error message.
 *
 * @param context Represent ballerina context.
 * @param errMsg  Error message.
 * @return Generic error message.
 */
public static BStruct getGenericError(Context context, String errMsg) {
    PackageInfo errorPackageInfo = context.getProgramFile().getPackageInfo(PACKAGE_BUILTIN);
    StructInfo errorStructInfo = errorPackageInfo.getStructInfo(STRUCT_GENERIC_ERROR);
    BStruct genericError = new BStruct(errorStructInfo.getType());
    genericError.setStringField(0, errMsg);
    return genericError;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 7 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.

the class FileUtils method createIOError.

public static BStruct createIOError(Context context, String msg) {
    PackageInfo filePkg = context.getProgramFile().getPackageInfo(FILE_PACKAGE);
    StructInfo ioErrInfo = filePkg.getStructInfo(IO_ERROR);
    return BLangVMStructs.createBStruct(ioErrInfo, msg);
}
Also used : StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 8 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.

the class FileUtils method createFileStruct.

public static BStruct createFileStruct(Context context, String path) {
    PackageInfo filePkg = context.getProgramFile().getPackageInfo(FILE_PACKAGE);
    StructInfo fileInfo = filePkg.getStructInfo(FILE_STRUCT);
    return BLangVMStructs.createBStruct(fileInfo, path);
}
Also used : StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 9 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.

the class SQLDatasourceUtils method getSQLConnectorError.

public static BStruct getSQLConnectorError(Context context, Throwable throwable) {
    PackageInfo sqlPackageInfo = context.getProgramFile().getPackageInfo(Constants.SQL_PACKAGE_PATH);
    StructInfo errorStructInfo = sqlPackageInfo.getStructInfo(Constants.SQL_CONNECTOR_ERROR);
    BStruct sqlConnectorError = new BStruct(errorStructInfo.getType());
    if (throwable.getMessage() == null) {
        sqlConnectorError.setStringField(0, Constants.SQL_EXCEPTION_OCCURED);
    } else {
        sqlConnectorError.setStringField(0, throwable.getMessage());
    }
    return sqlConnectorError;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 10 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo in project ballerina by ballerina-lang.

the class Utils method createSpanContextStruct.

public static BStruct createSpanContextStruct(Context context, BMap spanContext) {
    PackageInfo observePackage = context.getProgramFile().getPackageInfo("ballerina.observe");
    StructInfo spanStructInfo = observePackage.getStructInfo("SpanContext");
    return BLangVMStructs.createBStruct(spanStructInfo, spanContext);
}
Also used : StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Aggregations

StructInfo (org.ballerinalang.util.codegen.StructInfo)40 PackageInfo (org.ballerinalang.util.codegen.PackageInfo)35 BStruct (org.ballerinalang.model.values.BStruct)21 BStructType (org.ballerinalang.model.types.BStructType)6 BString (org.ballerinalang.model.values.BString)4 BValue (org.ballerinalang.model.values.BValue)4 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)4 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)3 BType (org.ballerinalang.model.types.BType)2 BInteger (org.ballerinalang.model.values.BInteger)2 BMap (org.ballerinalang.model.values.BMap)2 SocketIOChannel (org.ballerinalang.nativeimpl.io.channels.SocketIOChannel)2 Channel (org.ballerinalang.nativeimpl.io.channels.base.Channel)2 StructFieldInfo (org.ballerinalang.util.codegen.StructFieldInfo)2 Test (org.testng.annotations.Test)2 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 URL (java.net.URL)1 ByteChannel (java.nio.channels.ByteChannel)1 SocketChannel (java.nio.channels.SocketChannel)1