Search in sources :

Example 46 with BType

use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.

the class TableOMDataSource method processStruct.

private void processStruct(XMLStreamWriter xmlStreamWriter, Object[] structData, BStructType.StructField[] structFields, int index) throws XMLStreamException {
    try {
        int i = 0;
        boolean structError = true;
        BType internaltType = structFields[index - 1].fieldType;
        if (internaltType.getTag() == TypeTags.STRUCT_TAG) {
            BStructType.StructField[] interanlStructFields = ((BStructType) internaltType).getStructFields();
            if (interanlStructFields != null) {
                for (Object val : structData) {
                    xmlStreamWriter.writeStartElement("", interanlStructFields[i].fieldName, "");
                    if (val instanceof Struct) {
                        processStruct(xmlStreamWriter, ((Struct) val).getAttributes(), interanlStructFields, i + 1);
                    } else {
                        xmlStreamWriter.writeCharacters(val.toString());
                    }
                    xmlStreamWriter.writeEndElement();
                    ++i;
                }
                structError = false;
            }
        }
        if (structError) {
            throw new BallerinaException("error in constructing the xml element from struct type data");
        }
    } catch (SQLException e) {
        throw new BallerinaException("error in retrieving struct data to construct the inner xml element:" + e.getMessage());
    }
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) SQLException(java.sql.SQLException) BType(org.ballerinalang.model.types.BType) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) Struct(java.sql.Struct)

Example 47 with BType

use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.

the class BLangVMStructs method createBConnector.

/**
 * Create BConnector with given values.
 *
 * @param connectorInfo {@link ConnectorInfo} of the {@link BConnector}
 * @param values        field values of the connector ( including args ).
 * @return BStruct instance.
 */
public static BConnector createBConnector(ConnectorInfo connectorInfo, Object... values) {
    BConnector bConnector = new BConnector(connectorInfo.getType());
    final LocalVariableAttributeInfo localVar = (LocalVariableAttributeInfo) connectorInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
    int i = 0;
    int[] indexes = new int[] { -1, -1, -1, -1, -1, -1 };
    for (LocalVariableInfo variableInfo : localVar.getLocalVariables()) {
        if (values.length < i + 1) {
            break;
        }
        final BType varType = variableInfo.getVariableType();
        setValue(bConnector, indexes, varType.getTag(), values[i]);
    }
    return bConnector;
}
Also used : BConnector(org.ballerinalang.model.values.BConnector) LocalVariableInfo(org.ballerinalang.util.codegen.LocalVariableInfo) LocalVariableAttributeInfo(org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo) BType(org.ballerinalang.model.types.BType)

Example 48 with BType

use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.

the class BLangVMWorkers method calculateWorkerReturnIndex.

private static WorkerReturnIndex calculateWorkerReturnIndex(BType[] retTypes) {
    WorkerReturnIndex index = new WorkerReturnIndex();
    index.retRegs = new int[retTypes.length];
    for (int i = 0; i < retTypes.length; i++) {
        BType retType = retTypes[i];
        switch(retType.getTag()) {
            case TypeTags.INT_TAG:
                index.retRegs[i] = index.longRegCount++;
                break;
            case TypeTags.FLOAT_TAG:
                index.retRegs[i] = index.doubleRegCount++;
                break;
            case TypeTags.STRING_TAG:
                index.retRegs[i] = index.stringRegCount++;
                break;
            case TypeTags.BOOLEAN_TAG:
                index.retRegs[i] = index.intRegCount++;
                break;
            case TypeTags.BLOB_TAG:
                index.retRegs[i] = index.byteRegCount++;
                break;
            default:
                index.retRegs[i] = index.refRegCount++;
                break;
        }
    }
    return index;
}
Also used : BType(org.ballerinalang.model.types.BType)

Aggregations

BType (org.ballerinalang.model.types.BType)48 BStructType (org.ballerinalang.model.types.BStructType)16 BString (org.ballerinalang.model.values.BString)16 BStruct (org.ballerinalang.model.values.BStruct)15 BValue (org.ballerinalang.model.values.BValue)13 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)12 BBoolean (org.ballerinalang.model.values.BBoolean)11 BArrayType (org.ballerinalang.model.types.BArrayType)7 BFloat (org.ballerinalang.model.values.BFloat)6 BInteger (org.ballerinalang.model.values.BInteger)6 BMapType (org.ballerinalang.model.types.BMapType)4 BRefType (org.ballerinalang.model.values.BRefType)4 SQLException (java.sql.SQLException)3 Struct (java.sql.Struct)3 ArrayList (java.util.ArrayList)3 CallableUnitCallback (org.ballerinalang.bre.bvm.CallableUnitCallback)3 BBlob (org.ballerinalang.model.values.BBlob)3 Message (org.ballerinalang.net.grpc.Message)3 StructFieldInfo (org.ballerinalang.util.codegen.StructFieldInfo)3 StructInfo (org.ballerinalang.util.codegen.StructInfo)3