Search in sources :

Example 11 with Types

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;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) OAuthAppRequest(org.wso2.carbon.apimgt.core.models.OAuthAppRequest) OAuthApplicationInfo(org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo) KeyManagementException(org.wso2.carbon.apimgt.core.exception.KeyManagementException)

Example 12 with Types

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");
    }
}
Also used : BPMNJsonException(org.wso2.carbon.bpmn.core.types.datatypes.json.BPMNJsonException) List(java.util.List) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 13 with Types

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
}
Also used : VarTypeCountAttributeInfo(org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo) LineNumberTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo) CodeAttributeInfo(org.wso2.ballerinalang.programfile.attributes.CodeAttributeInfo) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) LineNumberTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo) ErrorTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo) AttributeInfo(org.wso2.ballerinalang.programfile.attributes.AttributeInfo) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) DefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo) VarTypeCountAttributeInfo(org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) DefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo) ErrorTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo) CodeAttributeInfo(org.wso2.ballerinalang.programfile.attributes.CodeAttributeInfo)

Example 14 with Types

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;
}
Also used : CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) ArrayList(java.util.ArrayList) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) SymbolInformation(org.ballerinalang.composer.service.ballerina.parser.service.model.SymbolInformation)

Example 15 with Types

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;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) Name(org.wso2.ballerinalang.compiler.util.Name)

Aggregations

ArrayList (java.util.ArrayList)20 Test (org.testng.annotations.Test)15 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 List (java.util.List)8 JsonObject (com.google.gson.JsonObject)5 Test (org.junit.Test)5 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)5 Arrays (java.util.Arrays)4 Collectors (java.util.stream.Collectors)4 JSONObject (org.json.simple.JSONObject)4 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 JsonElement (com.google.gson.JsonElement)3 Paths (java.nio.file.Paths)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 StringUtils (org.apache.commons.lang3.StringUtils)3