Search in sources :

Example 36 with StructInfo

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

the class ConnectorUtils method createAndGetStruct.

/**
 * This method is used to create a struct given the context and required struct details.
 *
 * @param context to get program file.
 * @param packagePath of the struct.
 * @param structName of the struct.
 * @return created struct.
 * @throws BallerinaConnectorException if an error occurs
 */
public static BStruct createAndGetStruct(Context context, String packagePath, String structName) throws BallerinaConnectorException {
    PackageInfo packageInfo = context.getProgramFile().getPackageInfo(packagePath);
    if (packageInfo == null) {
        throw new BallerinaConnectorException("package - " + packagePath + " does not exist");
    }
    StructInfo structInfo = packageInfo.getStructInfo(structName);
    if (structInfo == null) {
        throw new BallerinaConnectorException("struct - " + structName + " does not exist");
    }
    BStructType structType = structInfo.getType();
    BStruct bStruct = new BStruct(structType);
    return bStruct;
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 37 with StructInfo

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

the class FileUtils method createAccessDeniedError.

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

Example 38 with StructInfo

use of org.ballerinalang.util.codegen.StructInfo 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;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) BMap(org.ballerinalang.model.values.BMap) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) BValue(org.ballerinalang.model.values.BValue) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Example 39 with StructInfo

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

the class MimeUtil method getParserError.

/**
 * Get parser error as a ballerina struct.
 *
 * @param context Represent ballerina context
 * @param errMsg  Error message in string form
 * @return Ballerina struct with parse error
 */
public static BStruct getParserError(Context context, String errMsg) {
    PackageInfo errorPackageInfo = context.getProgramFile().getPackageInfo(BUILTIN_PACKAGE);
    StructInfo errorStructInfo = errorPackageInfo.getStructInfo(STRUCT_GENERIC_ERROR);
    BStruct parserError = new BStruct(errorStructInfo.getType());
    parserError.setStringField(0, errMsg);
    return parserError;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 40 with StructInfo

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

the class MimeUtil method createEntityError.

/**
 * Get entity error as a ballerina struct.
 *
 * @param context Represent ballerina context
 * @param msg     Error message in string form
 * @return Ballerina struct with entity error
 */
public static BStruct createEntityError(Context context, String msg) {
    PackageInfo filePkg = context.getProgramFile().getPackageInfo(PROTOCOL_PACKAGE_MIME);
    StructInfo entityErrInfo = filePkg.getStructInfo(ENTITY_ERROR);
    return BLangVMStructs.createBStruct(entityErrInfo, msg);
}
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