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());
}
}
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;
}
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));
}
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()));
}
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);
}
}
Aggregations