use of org.wso2.ballerinalang.programfile.DefaultValue in project ballerina by ballerina-lang.
the class PackageInfoWriter method writeAttributeInfo.
private static void writeAttributeInfo(DataOutputStream dataOutStream, AttributeInfo attributeInfo) throws IOException {
AttributeInfo.Kind attributeKind = attributeInfo.getKind();
dataOutStream.writeInt(attributeInfo.getAttributeNameIndex());
switch(attributeKind) {
case CODE_ATTRIBUTE:
CodeAttributeInfo codeAttributeInfo = (CodeAttributeInfo) attributeInfo;
dataOutStream.writeInt(codeAttributeInfo.codeAddrs);
dataOutStream.writeShort(codeAttributeInfo.maxLongLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxDoubleLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxStringLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxIntLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxByteLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxRefLocalVars);
dataOutStream.writeShort(codeAttributeInfo.maxLongRegs);
dataOutStream.writeShort(codeAttributeInfo.maxDoubleRegs);
dataOutStream.writeShort(codeAttributeInfo.maxStringRegs);
dataOutStream.writeShort(codeAttributeInfo.maxIntRegs);
dataOutStream.writeShort(codeAttributeInfo.maxByteRegs);
dataOutStream.writeShort(codeAttributeInfo.maxRefRegs);
break;
case VARIABLE_TYPE_COUNT_ATTRIBUTE:
VarTypeCountAttributeInfo varCountAttributeInfo = (VarTypeCountAttributeInfo) attributeInfo;
dataOutStream.writeShort(varCountAttributeInfo.getMaxLongVars());
dataOutStream.writeShort(varCountAttributeInfo.getMaxDoubleVars());
dataOutStream.writeShort(varCountAttributeInfo.getMaxStringVars());
dataOutStream.writeShort(varCountAttributeInfo.getMaxIntVars());
dataOutStream.writeShort(varCountAttributeInfo.getMaxByteVars());
dataOutStream.writeShort(varCountAttributeInfo.getMaxRefVars());
break;
case ERROR_TABLE:
ErrorTableAttributeInfo errTable = (ErrorTableAttributeInfo) attributeInfo;
ErrorTableEntry[] errorTableEntries = errTable.getErrorTableEntriesList().toArray(new ErrorTableEntry[0]);
dataOutStream.writeShort(errorTableEntries.length);
for (ErrorTableEntry errorTableEntry : errorTableEntries) {
dataOutStream.writeInt(errorTableEntry.ipFrom);
dataOutStream.writeInt(errorTableEntry.ipTo);
dataOutStream.writeInt(errorTableEntry.ipTarget);
dataOutStream.writeInt(errorTableEntry.priority);
dataOutStream.writeInt(errorTableEntry.errorStructCPIndex);
}
break;
case LOCAL_VARIABLES_ATTRIBUTE:
LocalVariableAttributeInfo localVarAttrInfo = (LocalVariableAttributeInfo) attributeInfo;
LocalVariableInfo[] localVarInfoArray = localVarAttrInfo.localVars.toArray(new LocalVariableInfo[0]);
dataOutStream.writeShort(localVarInfoArray.length);
for (LocalVariableInfo localVariableInfo : localVarInfoArray) {
writeLocalVariableInfo(dataOutStream, localVariableInfo);
}
break;
case LINE_NUMBER_TABLE_ATTRIBUTE:
LineNumberTableAttributeInfo lnNoTblAttrInfo = (LineNumberTableAttributeInfo) attributeInfo;
LineNumberInfo[] lineNumberInfoEntries = lnNoTblAttrInfo.getLineNumberInfoEntries();
dataOutStream.writeShort(lineNumberInfoEntries.length);
for (LineNumberInfo lineNumberInfo : lineNumberInfoEntries) {
writeLineNumberInfo(dataOutStream, lineNumberInfo);
}
break;
case DEFAULT_VALUE_ATTRIBUTE:
DefaultValueAttributeInfo defaultValAttrInfo = (DefaultValueAttributeInfo) attributeInfo;
writeDefaultValue(dataOutStream, defaultValAttrInfo.getDefaultValue());
break;
case PARAMETER_DEFAULTS_ATTRIBUTE:
ParamDefaultValueAttributeInfo paramDefaultValAttrInfo = (ParamDefaultValueAttributeInfo) attributeInfo;
DefaultValue[] defaultValues = paramDefaultValAttrInfo.getDefaultValueInfo();
dataOutStream.writeShort(defaultValues.length);
for (DefaultValue defaultValue : defaultValues) {
writeDefaultValue(dataOutStream, defaultValue);
}
break;
}
// TODO Support other types of attributes
}
use of org.wso2.ballerinalang.programfile.DefaultValue in project ballerina by ballerina-lang.
the class ParserUtils method createNewStruct.
/**
* Create new struct.
*
* @param name name of the struct
* @param fields field definiton statements
* @return {Function} function
*/
private static Struct createNewStruct(String name, List<BLangVariable> fields, String fileName) {
Struct struct = new Struct(name);
fields.forEach((field) -> {
String defaultValue = null;
if (field.getInitialExpression() != null) {
defaultValue = ((BLangLiteral) field.getInitialExpression()).getValue().toString();
}
StructField structField = createNewStructField(field.getName().getValue(), field.getTypeNode().type.toString(), defaultValue);
struct.addStructField(structField);
});
struct.setFileName(fileName);
return struct;
}
use of org.wso2.ballerinalang.programfile.DefaultValue in project ballerina by ballerina-lang.
the class CodeGenerator method getDefaultValueAttributeInfo.
private DefaultValueAttributeInfo getDefaultValueAttributeInfo(BLangLiteral literalExpr) {
DefaultValue defaultValue = getDefaultValue(literalExpr);
UTF8CPEntry defaultValueAttribUTF8CPEntry = new UTF8CPEntry(AttributeInfo.Kind.DEFAULT_VALUE_ATTRIBUTE.toString());
int defaultValueAttribNameIndex = currentPkgInfo.addCPEntry(defaultValueAttribUTF8CPEntry);
return new DefaultValueAttributeInfo(defaultValueAttribNameIndex, defaultValue);
}
use of org.wso2.ballerinalang.programfile.DefaultValue in project ballerina by ballerina-lang.
the class CodeGenerator method addParameterDefaultValues.
private void addParameterDefaultValues(BLangInvokableNode invokableNode, CallableUnitInfo callableUnitInfo) {
int paramDefaultsAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE.value());
ParamDefaultValueAttributeInfo paramDefaulValAttrInfo = new ParamDefaultValueAttributeInfo(paramDefaultsAttrNameIndex);
// Only named parameters can have default values.
for (BLangVariableDef param : invokableNode.defaultableParams) {
DefaultValue defaultVal = getDefaultValue((BLangLiteral) param.var.expr);
paramDefaulValAttrInfo.addParamDefaultValueInfo(defaultVal);
}
callableUnitInfo.addAttributeInfo(AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE, paramDefaulValAttrInfo);
}
use of org.wso2.ballerinalang.programfile.DefaultValue in project carbon-business-process by wso2.
the class HTRenderingApiImpl method getRenderingOutputElements.
/**
* Function to retrieve output rendering elements
*
* @param taskIdentifier interested task identifier
* @return set of output renderings wrapped within OutputType
* @throws IllegalArgumentFault error occured while retrieving renderings from task definition
* @throws IOException If an error occurred while reading from the input source
* @throws SAXException If the xml content in the input source is invalid
* @throws IllegalOperationFault
* @throws IllegalAccessFault
* @throws IllegalStateFault
* @throws XPathExpressionException If error occurred while xpath evaluation
* @throws GetRenderingsFaultException If unable to find unique id for the wso2:output rendering element
*/
private OutputType getRenderingOutputElements(URI taskIdentifier) throws IllegalArgumentFault, IOException, SAXException, IllegalOperationFault, IllegalAccessFault, IllegalStateFault, XPathExpressionException, GetRenderingsFaultException {
QName renderingType = new QName(htRenderingNS, "output", "wso2");
String outputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
// create output element
OutputType renderingOutputs = null;
// check availability of output renderings
if (outputRenderings != null && outputRenderings.length() > 0) {
// parse output renderings
Element outputRenderingsElement = DOMUtils.stringToDOM(outputRenderings);
// retrieve output rendering elements
NodeList outputElementList = outputRenderingsElement.getElementsByTagNameNS(htRenderingNS, "element");
if (outputElementList != null && outputElementList.getLength() > 0) {
int outputElementNum = outputElementList.getLength();
OutputElementType[] outputElements = new OutputElementType[outputElementNum];
// TODO get task output message from the cache
// (if not in the cache) retrieve saved output using HumanTaskClientAPI
String savedOutputMsg = (String) taskOps.getOutput(taskIdentifier, null);
// Element to hold parsed saved output message
Element savedOutputElement = null;
if (savedOutputMsg != null && savedOutputMsg.length() > 0) {
savedOutputElement = DOMUtils.stringToDOM(savedOutputMsg);
}
for (int i = 0; i < outputElementNum; i++) {
Element tempElement = (Element) outputElementList.item(i);
if (tempElement.hasAttribute("id")) {
// Retrieve element data
String elementID = tempElement.getAttribute("id");
String label = tempElement.getElementsByTagNameNS(htRenderingNS, "label").item(0).getTextContent();
String xpath = tempElement.getElementsByTagNameNS(htRenderingNS, "xpath").item(0).getTextContent();
String defaultValue = tempElement.getElementsByTagNameNS(htRenderingNS, "default").item(0).getTextContent();
// set the readOnly attribute if Exists, default false
String readOnly = "false";
if (tempElement.hasAttribute("readOnly")) {
readOnly = tempElement.getAttribute("readOnly");
}
// set element data in the response message
outputElements[i] = new OutputElementType();
// set ID
outputElements[i].setId(elementID);
// set label
outputElements[i].setLabel(label);
// set xpath
outputElements[i].setXpath(xpath);
// set value
Element valueElement = (Element) tempElement.getElementsByTagNameNS(htRenderingNS, "value").item(0);
outputElements[i].setValue(createOutRenderElementValue(valueElement));
if (readOnly.equals("true")) {
outputElements[i].setReadOnly(true);
} else {
outputElements[i].setReadOnly(false);
}
if (savedOutputElement != null) {
// resolve default value
String savedOutMessageValue = evaluateXPath(xpath, savedOutputElement, outputRenderingsElement.getOwnerDocument());
if (savedOutMessageValue == null) {
outputElements[i].set_default(defaultValue);
} else {
outputElements[i].set_default(savedOutMessageValue);
}
} else {
// add default value specified in the HT rendering definition
outputElements[i].set_default(defaultValue);
}
} else {
// no unique id for the element
log.error("Unable to find unique id for the wso2:output rendering element");
throw new GetRenderingsFaultException("Unable to find unique id for the wso2:output rendering element");
}
}
renderingOutputs = new OutputType();
renderingOutputs.setElement(outputElements);
}
}
return renderingOutputs;
}
Aggregations