use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.
the class AuthenticatorService method createDCRApplication.
/**
* This method creates a DCR application.
*
* @param clientName Name of the application to be created
* @param callBackURL Call back URL of the application
* @param grantTypes List of grant types of the application
* @return OAUthApplicationInfo - An object with DCR Application information
* @throws APIManagementException When creating DCR application fails
*/
private OAuthApplicationInfo createDCRApplication(String clientName, String callBackURL, List<String> grantTypes) throws APIManagementException {
OAuthApplicationInfo oAuthApplicationInfo;
try {
// Here the keyType:"Application" will be passed as a default value
// for the oAuthAppRequest constructor argument.
// This value is not related to DCR application creation.
OAuthAppRequest oAuthAppRequest = new OAuthAppRequest(clientName, callBackURL, AuthenticatorConstants.APPLICATION_KEY_TYPE, grantTypes);
if (systemApplicationDao.isConsumerKeyExistForApplication(clientName)) {
String consumerKey = systemApplicationDao.getConsumerKeyForApplication(clientName);
oAuthApplicationInfo = getKeyManager().retrieveApplication(consumerKey);
} else {
oAuthApplicationInfo = getKeyManager().createApplication(oAuthAppRequest);
if (oAuthApplicationInfo != null) {
systemApplicationDao.addApplicationKey(clientName, oAuthApplicationInfo.getClientId());
}
}
} catch (KeyManagementException | APIMgtDAOException e) {
String errorMsg = "Error while creating the keys for OAuth application : " + clientName;
log.error(errorMsg, e, ExceptionCodes.OAUTH2_APP_CREATION_FAILED);
throw new APIManagementException(errorMsg, e, ExceptionCodes.OAUTH2_APP_CREATION_FAILED);
}
return oAuthApplicationInfo;
}
use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-business-process by wso2.
the class JsonNodeObject method jsonPath.
/**
* Function to evaluate jsonpath over JsonNodeObject
* @param jsonPathStr jsonpath
* @return returns the evaluation result. The returned Object can be a
* com.fasterxml.jackson.databind.JsonNode (in case the result is json object)
* com.fasterxml.jackson.databind.node.ArrayNode (in case the result is json array)
* Or main primitive data types (String, Integer, Byte, Character, Short, Long, Float, Double, Boolean)
* This function returns new Object representing the evaluation results, no a reference to a node
* @throws IOException
* @throws BPMNJsonException is thrown if the the resulting data type cannot be identified
*/
public Object jsonPath(String jsonPathStr) throws IOException, BPMNJsonException {
ObjectMapper mapper = new ObjectMapper();
Map map = mapper.convertValue(jsonNode, Map.class);
Object result = JsonPath.read(map, jsonPathStr);
JsonBuilder builder = new JsonBuilder(mapper);
if (result instanceof Map) {
// If the result is a Map, then it should be a json object
return builder.createJsonNodeFromMap((Map<String, Object>) result);
} else if (result instanceof List) {
// when result is a list, then it should be a json array
return builder.createJsonArrayFromMap((List<Object>) result);
} else if (result == null || result instanceof String || result instanceof Integer || result instanceof Byte || result instanceof Character || result instanceof Short || result instanceof Long || result instanceof Float || result instanceof Double || result instanceof Boolean) {
// If result is primitive data type, then return it as it is
return result;
} else {
// Un-filtered data type, considered as unknown types
throw new BPMNJsonException("Unknown type data type: " + result.getClass().getName() + " resulted while evaluating json path");
}
}
use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types 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.compiler.semantics.analyzer.Types in project ballerina by ballerina-lang.
the class ParserUtils method getBuiltinTypes.
/**
* Get the builtin types.
*
* @return {@link List} list of builtin types
*/
public static List<SymbolInformation> getBuiltinTypes() {
CompilerContext context = prepareCompilerContext("", "");
SymbolTable symbolTable = SymbolTable.getInstance(context);
List<SymbolInformation> symbolInformationList = new ArrayList<>();
// TODO: Need to fill the default values
symbolTable.rootScope.entries.forEach((key, value) -> {
if (value.symbol instanceof BTypeSymbol) {
SymbolInformation symbolInfo = new SymbolInformation();
String symbolName = value.symbol.getName().getValue();
if (!symbolName.equals(BuiltInType.INVALID_TYPE)) {
symbolInfo.setName(symbolName);
setDefaultValuesForType(symbolName, symbolInfo);
symbolInformationList.add(symbolInfo);
}
}
});
return symbolInformationList;
}
use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project ballerina by ballerina-lang.
the class SymbolResolver method visit.
public void visit(BLangUserDefinedType userDefinedTypeNode) {
// 1) Resolve the package scope using the package alias.
// If the package alias is not empty or null, then find the package scope,
// if not use the current package scope.
// 2) lookup the typename in the package scope returned from step 1.
// 3) If the symbol is not found, then lookup in the root scope. e.g. for types such as 'error'
BSymbol pkgSymbol = resolvePkgSymbol(userDefinedTypeNode.pos, this.env, names.fromIdNode(userDefinedTypeNode.pkgAlias));
if (pkgSymbol == symTable.notFoundSymbol) {
resultType = symTable.errType;
return;
}
Name typeName = names.fromIdNode(userDefinedTypeNode.typeName);
BSymbol symbol = symTable.notFoundSymbol;
// Only valued types and ANNOTATION type allowed.
if (env.scope.owner.tag == SymTag.ANNOTATION) {
symbol = lookupMemberSymbol(userDefinedTypeNode.pos, pkgSymbol.scope, this.env, typeName, SymTag.ANNOTATION);
}
// 3) Lookup the current package scope.
if (symbol == symTable.notFoundSymbol) {
symbol = lookupMemberSymbol(userDefinedTypeNode.pos, pkgSymbol.scope, this.env, typeName, SymTag.VARIABLE_NAME);
}
if (symbol == symTable.notFoundSymbol) {
// 4) Lookup the root scope for types such as 'error'
symbol = lookupMemberSymbol(userDefinedTypeNode.pos, symTable.rootScope, this.env, typeName, SymTag.VARIABLE_NAME);
}
if (symbol == symTable.notFoundSymbol) {
dlog.error(userDefinedTypeNode.pos, diagCode, typeName);
resultType = symTable.errType;
return;
}
if (symbol.kind == SymbolKind.CONNECTOR) {
userDefinedTypeNode.flagSet = EnumSet.of(Flag.CONNECTOR);
}
resultType = symbol.type;
}
Aggregations