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