use of org.wso2.siddhi.annotation.Parameter in project ballerina by ballerina-lang.
the class CodeGenerator method createActionInfoEntry.
private void createActionInfoEntry(BLangAction actionNode, ConnectorInfo connectorInfo) {
BInvokableSymbol actionSymbol = actionNode.symbol;
BInvokableType actionType = (BInvokableType) actionSymbol.type;
// Add action name as an UTFCPEntry to the constant pool
int actionNameCPIndex = addUTF8CPEntry(currentPkgInfo, actionNode.name.value);
ActionInfo actionInfo = new ActionInfo(currentPackageRefCPIndex, actionNameCPIndex);
actionInfo.paramTypes = actionType.paramTypes.toArray(new BType[0]);
actionInfo.retParamTypes = actionType.retTypes.toArray(new BType[0]);
actionInfo.flags = actionSymbol.flags;
// setParameterNames(actionNode, actionInfo);
actionInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(actionInfo.paramTypes, actionInfo.retParamTypes));
// Add worker info
this.addWorkerInfoEntries(actionInfo, actionNode.getWorkers());
// Add parameter default value info
addParameterDefaultValues(actionNode, actionInfo);
// Add action info to the connector info
connectorInfo.actionInfoMap.put(actionNode.name.getValue(), actionInfo);
}
use of org.wso2.siddhi.annotation.Parameter in project ballerina by ballerina-lang.
the class CodeGenerator method createFunctionInfoEntry.
/**
* Creates a {@code FunctionInfo} from the given function node in AST.
*
* @param funcNode function node in AST
*/
private void createFunctionInfoEntry(BLangFunction funcNode) {
BInvokableSymbol funcSymbol = funcNode.symbol;
BInvokableType funcType = (BInvokableType) funcSymbol.type;
// Add function name as an UTFCPEntry to the constant pool
int funcNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, funcNode.name.value);
FunctionInfo funcInfo = new FunctionInfo(currentPackageRefCPIndex, funcNameCPIndex);
funcInfo.paramTypes = funcType.paramTypes.toArray(new BType[0]);
funcInfo.retParamTypes = funcType.retTypes.toArray(new BType[0]);
funcInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(funcInfo.paramTypes, funcInfo.retParamTypes));
funcInfo.flags = funcSymbol.flags;
if (funcNode.receiver != null) {
funcInfo.attachedToTypeCPIndex = getTypeCPIndex(funcNode.receiver.type).value;
}
this.addWorkerInfoEntries(funcInfo, funcNode.getWorkers());
// Add parameter default value info
addParameterDefaultValues(funcNode, funcInfo);
this.currentPkgInfo.functionInfoMap.put(funcSymbol.name.value, funcInfo);
}
use of org.wso2.siddhi.annotation.Parameter in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangFunction funcNode) {
SymbolEnv fucEnv = SymbolEnv.createFunctionEnv(funcNode, funcNode.symbol.scope, env);
if (!funcNode.interfaceFunction) {
addReturnIfNotPresent(funcNode);
}
// To preserve endpoint code gen order.
Collections.reverse(funcNode.endpoints);
funcNode.endpoints = rewrite(funcNode.endpoints, fucEnv);
funcNode.body = rewrite(funcNode.body, fucEnv);
funcNode.workers = rewrite(funcNode.workers, fucEnv);
// the struct variable as the first parameter
if (funcNode.receiver != null) {
BInvokableSymbol funcSymbol = funcNode.symbol;
List<BVarSymbol> params = funcSymbol.params;
params.add(0, funcNode.receiver.symbol);
BInvokableType funcType = (BInvokableType) funcSymbol.type;
funcType.paramTypes.add(0, funcNode.receiver.type);
}
result = funcNode;
}
use of org.wso2.siddhi.annotation.Parameter in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangAction actionNode) {
String actionName = actionNode.getName().getValue();
BSymbol actionSymbol = actionNode.symbol;
SymbolEnv actionEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionSymbol.scope, symbolEnv);
if (this.isWithinParameterContext(actionName, NODE_TYPE_ACTION)) {
this.populateSymbols(this.resolveAllVisibleSymbols(actionEnv), actionEnv);
setTerminateVisitor(true);
} else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(actionNode.getPosition(), actionNode, this, this.documentServiceContext)) {
// TODO: Handle Annotation attachments
// Visit the endpoints
actionNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, actionEnv));
// Cursor position is calculated against the resource parameter scope resolver since both are similar
cursorPositionResolver = ResourceParamScopeResolver.class;
actionNode.workers.forEach(w -> this.acceptNode(w, actionEnv));
// Cursor position is calculated against the Block statement scope resolver
cursorPositionResolver = BlockStatementScopeResolver.class;
this.blockOwnerStack.push(actionNode);
acceptNode(actionNode.body, actionEnv);
this.blockOwnerStack.pop();
}
}
use of org.wso2.siddhi.annotation.Parameter in project charon by wso2.
the class GroupResourceManager method create.
/*
* Create group in the service provider given the submitted payload that contains the SCIM group
* resource, format and the handler to usermanager.
*
* @param scimObjectString - Payload of HTTP request, which contains the SCIM object.
* @param usermanager
* @param attributes
* @param excludeAttributes
* @return
*/
@Override
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
JSONEncoder encoder = null;
JSONDecoder decoder = null;
try {
// obtain the json encoder
encoder = getEncoder();
// obtain the json decoder
decoder = getDecoder();
// returns core-group schema
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
// get the URIs of required attributes which must be given a value
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
// decode the SCIM group object, encoded in the submitted payload.
Group group = (Group) decoder.decodeResource(scimObjectString, schema, new Group());
// validate decoded group
ServerSideValidator.validateCreatedSCIMObject(group, SCIMSchemaDefinitions.SCIM_GROUP_SCHEMA);
// handover the SCIM User object to the group usermanager provided by the SP.
Group createdGroup;
// need to send back the newly created group in the response payload
createdGroup = ((UserManager) userManager).createGroup(group, requiredAttributes);
// encode the newly created SCIM group object and add id attribute to Location header.
String encodedGroup;
Map<String, String> httpHeaders = new HashMap<String, String>();
if (createdGroup != null) {
encodedGroup = encoder.encodeSCIMObject(createdGroup);
// add location header
httpHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.GROUP_ENDPOINT) + "/" + createdGroup.getId());
httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
} else {
String message = "Newly created Group resource is null..";
throw new InternalErrorException(message);
}
// put the uri of the Group object in the response header parameter.
return new SCIMResponse(ResponseCodeConstants.CODE_CREATED, encodedGroup, httpHeaders);
} catch (InternalErrorException e) {
return encodeSCIMException(e);
} catch (BadRequestException e) {
return encodeSCIMException(e);
} catch (ConflictException e) {
return encodeSCIMException(e);
} catch (CharonException e) {
return encodeSCIMException(e);
} catch (NotFoundException e) {
return encodeSCIMException(e);
} catch (NotImplementedException e) {
return encodeSCIMException(e);
}
}
Aggregations