Search in sources :

Example 36 with BStructType

use of org.ballerinalang.model.types.BStructType 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 37 with BStructType

use of org.ballerinalang.model.types.BStructType 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 38 with BStructType

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

the class GetFieldAnnotations method execute.

@Override
public void execute(Context context) {
    BTypeDescValue bTypeValue = (BTypeDescValue) context.getRefArgument(0);
    if (!(bTypeValue.value() instanceof BStructType)) {
        context.setReturnValues((BValue) null);
        ;
    }
    BStructType structType = (BStructType) bTypeValue.value();
    String key = structType.getName() + DOT + context.getStringArgument(0);
    context.setReturnValues(getAnnotationValue(context, structType.getPackagePath(), key));
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue)

Example 39 with BStructType

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

the class GetStructAnnotations method execute.

@Override
public void execute(Context context) {
    BTypeDescValue bTypeValue = (BTypeDescValue) context.getRefArgument(0);
    if (!(bTypeValue.value() instanceof BStructType)) {
        context.setReturnValues((BValue) null);
    }
    BStructType structType = (BStructType) bTypeValue.value();
    context.setReturnValues(getAnnotationValue(context, structType.getPackagePath(), structType.getName()));
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue)

Example 40 with BStructType

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

the class EntityBodyHandler method setPartsToTopLevelEntity.

/**
 * Set ballerina body parts to it's top level entity.
 *
 * @param entity    Represent top level message's entity
 * @param bodyParts Represent ballerina body parts
 */
static void setPartsToTopLevelEntity(BStruct entity, ArrayList<BStruct> bodyParts) {
    if (!bodyParts.isEmpty()) {
        BStructType typeOfBodyPart = bodyParts.get(FIRST_BODY_PART_INDEX).getType();
        BStruct[] result = bodyParts.toArray(new BStruct[bodyParts.size()]);
        BRefValueArray partsArray = new BRefValueArray(result, typeOfBodyPart);
        entity.addNativeData(BODY_PARTS, partsArray);
    }
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BStruct(org.ballerinalang.model.values.BStruct) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Aggregations

BStructType (org.ballerinalang.model.types.BStructType)40 BStruct (org.ballerinalang.model.values.BStruct)24 BType (org.ballerinalang.model.types.BType)13 BString (org.ballerinalang.model.values.BString)11 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)11 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)7 BValue (org.ballerinalang.model.values.BValue)7 StructInfo (org.ballerinalang.util.codegen.StructInfo)7 BRefType (org.ballerinalang.model.values.BRefType)6 BBoolean (org.ballerinalang.model.values.BBoolean)5 BJSON (org.ballerinalang.model.values.BJSON)5 BTypeDescValue (org.ballerinalang.model.values.BTypeDescValue)5 Struct (java.sql.Struct)4 BFloat (org.ballerinalang.model.values.BFloat)4 BInteger (org.ballerinalang.model.values.BInteger)4 PackageInfo (org.ballerinalang.util.codegen.PackageInfo)4 BigDecimal (java.math.BigDecimal)3 SQLException (java.sql.SQLException)3 BMapType (org.ballerinalang.model.types.BMapType)3 BMap (org.ballerinalang.model.values.BMap)3