Search in sources :

Example 11 with Names

use of org.wso2.ballerinalang.compiler.util.Names in project ballerina by ballerina-lang.

the class TaintAnalyzer method visit.

public void visit(BLangXMLElementLiteral xmlElementLiteral) {
    SymbolEnv xmlElementEnv = SymbolEnv.getXMLElementEnv(xmlElementLiteral, env);
    // Visit in-line namespace declarations
    boolean inLineNamespaceTainted = false;
    for (BLangXMLAttribute attribute : xmlElementLiteral.attributes) {
        if (attribute.name.getKind() == NodeKind.XML_QNAME && ((BLangXMLQName) attribute.name).prefix.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
            attribute.accept(this);
            attribute.symbol.tainted = getObservedTaintedStatus();
            if (attribute.symbol.tainted) {
                inLineNamespaceTainted = true;
            }
        }
    }
    // Visit attributes.
    boolean attributesTainted = false;
    for (BLangXMLAttribute attribute : xmlElementLiteral.attributes) {
        if (attribute.name.getKind() == NodeKind.XML_QNAME && !((BLangXMLQName) attribute.name).prefix.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
            attribute.accept(this);
            attribute.symbol.tainted = getObservedTaintedStatus();
            if (attribute.symbol.tainted) {
                attributesTainted = true;
            }
        }
    }
    // Visit the tag names
    xmlElementLiteral.startTagName.accept(this);
    boolean startTagTaintedStatus = getObservedTaintedStatus();
    boolean endTagTaintedStatus = false;
    if (xmlElementLiteral.endTagName != null) {
        xmlElementLiteral.endTagName.accept(this);
        endTagTaintedStatus = getObservedTaintedStatus();
    }
    boolean tagNamesTainted = startTagTaintedStatus || endTagTaintedStatus;
    // Visit the children
    boolean childrenTainted = false;
    for (BLangExpression expr : xmlElementLiteral.children) {
        expr.accept(this);
        if (getObservedTaintedStatus()) {
            childrenTainted = true;
        }
    }
    setTaintedStatusList(inLineNamespaceTainted || attributesTainted || tagNamesTainted || childrenTainted);
}
Also used : BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 12 with Names

use of org.wso2.ballerinalang.compiler.util.Names in project ballerina by ballerina-lang.

the class TypeChecker method visit.

public void visit(BLangXMLElementLiteral bLangXMLElementLiteral) {
    SymbolEnv xmlElementEnv = SymbolEnv.getXMLElementEnv(bLangXMLElementLiteral, env);
    // Visit in-line namespace declarations
    bLangXMLElementLiteral.attributes.forEach(attribute -> {
        if (attribute.name.getKind() == NodeKind.XML_QNAME && ((BLangXMLQName) attribute.name).prefix.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
            checkExpr((BLangExpression) attribute, xmlElementEnv, Lists.of(symTable.noType));
        }
    });
    // Visit attributes.
    bLangXMLElementLiteral.attributes.forEach(attribute -> {
        if (attribute.name.getKind() != NodeKind.XML_QNAME || !((BLangXMLQName) attribute.name).prefix.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
            checkExpr((BLangExpression) attribute, xmlElementEnv, Lists.of(symTable.noType));
        }
    });
    Map<Name, BXMLNSSymbol> namespaces = symResolver.resolveAllNamespaces(xmlElementEnv);
    Name defaultNs = names.fromString(XMLConstants.DEFAULT_NS_PREFIX);
    if (namespaces.containsKey(defaultNs)) {
        bLangXMLElementLiteral.defaultNsSymbol = namespaces.remove(defaultNs);
    }
    bLangXMLElementLiteral.namespacesInScope.putAll(namespaces);
    // Visit the tag names
    validateTags(bLangXMLElementLiteral, xmlElementEnv);
    // Visit the children
    bLangXMLElementLiteral.modifiedChildren = concatSimilarKindXMLNodes(bLangXMLElementLiteral.children, xmlElementEnv);
    resultTypes = Lists.of(types.checkType(bLangXMLElementLiteral, symTable.xmlType, expTypes.get(0)));
}
Also used : BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 13 with Names

use of org.wso2.ballerinalang.compiler.util.Names in project ballerina by ballerina-lang.

the class EndpointDesugar method generateEndpointInitFunctionCall.

private BLangBlockStmt generateEndpointInitFunctionCall(BLangEndpoint endpoint, SymbolEnv env, BSymbol encSymbol, BSymbol varEncSymbol) {
    BLangBlockStmt temp = new BLangBlockStmt();
    if (endpoint.configurationExpr == null || endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
        return temp;
    }
    final String epName = endpoint.name.value;
    final DiagnosticPos pos = endpoint.pos;
    final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
    epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, names.fromString(epName), SymTag.VARIABLE);
    // EPConfigType ep_nameConf = { ep-config-expr };
    final BLangVariableDef epConfigNewStmt = ASTBuilderUtil.createVariableDefStmt(pos, temp);
    epConfigNewStmt.var = ASTBuilderUtil.createVariable(pos, epName + "Conf", endpoint.configurationExpr.type);
    epConfigNewStmt.var.expr = endpoint.configurationExpr;
    ASTBuilderUtil.defineVariable(epConfigNewStmt.var, varEncSymbol, names);
    List<BLangVariable> args = Lists.of(epConfigNewStmt.var);
    if (endpoint.symbol.initFunction != null && endpoint.symbol.initFunction.params.size() == 2) {
        // Endpoint is already desugared. Fix this correctly.
        args.add(0, epVariable);
    }
    // epName.init(ep_nameConf);
    final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
    final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, endpoint.symbol.initFunction, args, symResolver);
    if (endpoint.symbol.initFunction != null && endpoint.symbol.initFunction.params.size() != 2) {
        iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
    }
    expressionStmt.expr = iExpr;
    return temp;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 14 with Names

use of org.wso2.ballerinalang.compiler.util.Names in project charon by wso2.

the class ServerSideValidator method validateCreatedSCIMObject.

/*
     * Validate created SCIMObject according to the spec
     *
     * @param scimObject
     * @param resourceSchema
     * @throw CharonException
     * @throw BadRequestException
     * @throw NotFoundException
     */
public static void validateCreatedSCIMObject(AbstractSCIMObject scimObject, SCIMResourceTypeSchema resourceSchema) throws CharonException, BadRequestException, NotFoundException {
    if (scimObject instanceof User) {
        // set display names for complex multivalued attributes
        setDisplayNameInComplexMultiValuedAttributes(scimObject, resourceSchema);
    }
    // remove any read only attributes
    removeAnyReadOnlyAttributes(scimObject, resourceSchema);
    // add created and last modified dates
    String id = UUID.randomUUID().toString();
    scimObject.setId(id);
    Date date = new Date();
    // set the created date and time
    scimObject.setCreatedDate(AttributeUtil.parseDateTime(AttributeUtil.formatDateTime(date)));
    // creates date and the last modified are the same if not updated.
    scimObject.setLastModified(AttributeUtil.parseDateTime(AttributeUtil.formatDateTime(date)));
    // set location and resourceType
    if (resourceSchema.isSchemaAvailable(SCIMConstants.USER_CORE_SCHEMA_URI)) {
        String location = createLocationHeader(AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT), scimObject.getId());
        scimObject.setLocation(location);
        scimObject.setResourceType(SCIMConstants.USER);
    } else if (resourceSchema.isSchemaAvailable(SCIMConstants.GROUP_CORE_SCHEMA_URI)) {
        String location = createLocationHeader(AbstractResourceManager.getResourceEndpointURL(SCIMConstants.GROUP_ENDPOINT), scimObject.getId());
        scimObject.setLocation(location);
        scimObject.setResourceType(SCIMConstants.GROUP);
    }
    // check for required attributes
    validateSCIMObjectForRequiredAttributes(scimObject, resourceSchema);
    validateSchemaList(scimObject, resourceSchema);
}
Also used : User(org.wso2.charon3.core.objects.User) Date(java.util.Date)

Example 15 with Names

use of org.wso2.ballerinalang.compiler.util.Names in project charon by wso2.

the class Group method getMembersWithDisplayName.

/*
     * get the members of the group with their display names
     * @return
     */
public List<String> getMembersWithDisplayName() {
    ArrayList displayNames = new ArrayList();
    if (this.isAttributeExist(SCIMConstants.GroupSchemaConstants.MEMBERS)) {
        MultiValuedAttribute members = (MultiValuedAttribute) this.attributeList.get(SCIMConstants.GroupSchemaConstants.MEMBERS);
        List<Attribute> values = members.getAttributeValues();
        if (values != null) {
            List<Attribute> subValuesList = members.getAttributeValues();
            for (Attribute subValue : subValuesList) {
                ComplexAttribute complexAttribute = (ComplexAttribute) subValue;
                Map<String, Attribute> subAttributesList = complexAttribute.getSubAttributesList();
                if (subAttributesList != null && subAttributesList.containsKey(SCIMConstants.CommonSchemaConstants.DISPLAY)) {
                    displayNames.add(((SimpleAttribute) (subAttributesList.get(SCIMConstants.CommonSchemaConstants.DISPLAY))).getValue());
                }
            }
            return displayNames;
        }
    }
    return displayNames;
}
Also used : MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) Attribute(org.wso2.charon3.core.attributes.Attribute) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ArrayList(java.util.ArrayList) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Aggregations

ArrayList (java.util.ArrayList)10 Query (javax.persistence.Query)8 TaskStatus (org.wso2.carbon.humantask.core.dao.TaskStatus)8 Test (org.testng.annotations.Test)6 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 Name (org.wso2.ballerinalang.compiler.util.Name)5 Map (java.util.Map)4 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)4 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)4 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)3 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)3 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)3 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)3 Response (feign.Response)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Arrays (java.util.Arrays)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2