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