Search in sources :

Example 21 with PackageInfo

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

the class SecureClientSocketTest method testOpenSecureClientSocket.

@Test(description = "Test connection open with properties")
public void testOpenSecureClientSocket() throws URISyntaxException {
    PackageInfo ioPackageInfo = socketClient.getProgFile().getPackageInfo("ballerina.io");
    StructInfo socketProperties = ioPackageInfo.getStructInfo("SocketProperties");
    BStruct propertyStruct = BLangVMStructs.createBStruct(socketProperties);
    URL resource = getClass().getClassLoader().getResource("datafiles/security/keyStore/ballerinaTruststore.p12");
    Assert.assertNotNull(resource, "Unable to find TrustStore.");
    propertyStruct.setStringField(2, Paths.get(resource.toURI()).toFile().getAbsolutePath());
    propertyStruct.setStringField(3, "ballerina");
    BValue[] args = { new BString("localhost"), new BInteger(port), propertyStruct };
    BRunUtil.invoke(socketClient, "openSocketConnection", args);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) URL(java.net.URL) Test(org.testng.annotations.Test)

Example 22 with PackageInfo

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

the class IOUtils method createError.

/**
 * Returns the error struct for the corresponding message.
 *
 * @param context context of the native function.
 * @param message error message.
 * @return error message struct.
 */
public static BStruct createError(Context context, String message) {
    PackageInfo ioPkg = context.getProgramFile().getPackageInfo(IO_PACKAGE);
    StructInfo error = ioPkg.getStructInfo(IO_ERROR_STRUCT);
    return BLangVMStructs.createBStruct(error, message);
}
Also used : StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 23 with PackageInfo

use of org.ballerinalang.util.codegen.PackageInfo 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 24 with PackageInfo

use of org.ballerinalang.util.codegen.PackageInfo 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 25 with PackageInfo

use of org.ballerinalang.util.codegen.PackageInfo 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)

Aggregations

PackageInfo (org.ballerinalang.util.codegen.PackageInfo)48 StructInfo (org.ballerinalang.util.codegen.StructInfo)35 BStruct (org.ballerinalang.model.values.BStruct)17 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)10 BValue (org.ballerinalang.model.values.BValue)6 BStructType (org.ballerinalang.model.types.BStructType)5 FunctionInfo (org.ballerinalang.util.codegen.FunctionInfo)5 Debugger (org.ballerinalang.util.debugger.Debugger)5 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)5 BInteger (org.ballerinalang.model.values.BInteger)2 BMap (org.ballerinalang.model.values.BMap)2 BString (org.ballerinalang.model.values.BString)2 SocketIOChannel (org.ballerinalang.nativeimpl.io.channels.SocketIOChannel)2 Channel (org.ballerinalang.nativeimpl.io.channels.base.Channel)2 TesterinaFunction (org.ballerinalang.testerina.core.entity.TesterinaFunction)2 Instruction (org.ballerinalang.util.codegen.Instruction)2 PackageVarInfo (org.ballerinalang.util.codegen.PackageVarInfo)2 BLangRuntimeException (org.ballerinalang.util.exceptions.BLangRuntimeException)2 Test (org.testng.annotations.Test)2 PrintStream (java.io.PrintStream)1