use of org.ballerinalang.util.codegen.ResourceInfo in project ballerina by ballerina-lang.
the class BLangVMErrors method getStackFrame.
public static BStruct getStackFrame(CallableUnitInfo callableUnitInfo, int ip) {
if (callableUnitInfo == null) {
return null;
}
ProgramFile progFile = callableUnitInfo.getPackageInfo().getProgramFile();
PackageInfo runtimePackage = progFile.getPackageInfo(PACKAGE_RUNTIME);
StructInfo callStackElement = runtimePackage.getStructInfo(STRUCT_CALL_STACK_ELEMENT);
int currentIP = ip - 1;
Object[] values;
values = new Object[4];
String parentScope = "";
if (callableUnitInfo instanceof ResourceInfo) {
parentScope = ((ResourceInfo) callableUnitInfo).getServiceInfo().getName() + ".";
} else if (callableUnitInfo instanceof ActionInfo) {
parentScope = ((ActionInfo) callableUnitInfo).getConnectorInfo().getName() + ".";
}
values[0] = parentScope + callableUnitInfo.getName();
values[1] = callableUnitInfo.getPkgPath();
if (callableUnitInfo.isNative()) {
values[2] = "<native>";
values[3] = 0;
} else {
LineNumberInfo lineNumberInfo = callableUnitInfo.getPackageInfo().getLineNumberInfo(currentIP);
if (lineNumberInfo != null) {
values[2] = lineNumberInfo.getFileName();
values[3] = lineNumberInfo.getLineNumber();
}
}
return BLangVMStructs.createBStruct(callStackElement, values);
}
use of org.ballerinalang.util.codegen.ResourceInfo in project ballerina by ballerina-lang.
the class ResourceExecutor method execute.
/**
* This method will execute the resource, given required details.
* And it will use the callback to notify interested parties about the
* outcome of the execution.
*
* @param resource to be executed.
* @param responseCallback to notify.
* @param properties to be passed to context.
* @param tracer to be passed to context.
* @param bValues for parameters.
*/
public static void execute(Resource resource, CallableUnitCallback responseCallback, Map<String, Object> properties, Tracer tracer, BValue... bValues) throws BallerinaConnectorException {
if (resource == null || responseCallback == null) {
throw new BallerinaConnectorException("invalid arguments provided");
}
ResourceInfo resourceInfo = resource.getResourceInfo();
WorkerExecutionContext context = new WorkerExecutionContext(resourceInfo.getPackageInfo().getProgramFile());
if (properties != null) {
context.globalProps.putAll(properties);
if (properties.get(Constants.GLOBAL_TRANSACTION_ID) != null) {
context.setLocalTransactionInfo(new LocalTransactionInfo(properties.get(Constants.GLOBAL_TRANSACTION_ID).toString(), properties.get(Constants.TRANSACTION_URL).toString(), "2pc"));
}
}
BLangVMUtils.initServerConnectorTrace(context, resource, tracer);
BLangVMUtils.setServiceInfo(context, resourceInfo.getServiceInfo());
BLangFunctions.invokeCallable(resourceInfo, context, bValues, responseCallback);
}
use of org.ballerinalang.util.codegen.ResourceInfo in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method mapResourcesToPathPaths.
/**
* This method will convert ballerina resource to swagger path objects.
*
* @param resources Resource array to be convert.
*/
void mapResourcesToPathPaths(ResourceInfo[] resources) {
Map<String, Path> map = new HashMap<>();
for (ResourceInfo subResource : resources) {
OperationAdaptor operationAdaptor = this.convertResourceToOperation(subResource);
Path path = map.get(operationAdaptor.getPath());
// TODO this check need to be improve to avoid repetition checks and http head support need to add.
if (path == null) {
path = new Path();
map.put(operationAdaptor.getPath(), path);
}
String httpOperation = operationAdaptor.getHttpOperation();
Operation operation = operationAdaptor.getOperation();
switch(httpOperation) {
case HttpConstants.ANNOTATION_METHOD_GET:
path.get(operation);
break;
case HttpConstants.ANNOTATION_METHOD_PUT:
path.put(operation);
break;
case HttpConstants.ANNOTATION_METHOD_POST:
path.post(operation);
break;
case HttpConstants.ANNOTATION_METHOD_DELETE:
path.delete(operation);
break;
case HttpConstants.ANNOTATION_METHOD_OPTIONS:
path.options(operation);
break;
case HttpConstants.ANNOTATION_METHOD_PATCH:
path.patch(operation);
break;
case "HEAD":
path.head(operation);
break;
default:
break;
}
}
this.swaggerDefinition.setPaths(map);
}
use of org.ballerinalang.util.codegen.ResourceInfo in project ballerina by ballerina-lang.
the class RetrieveAnnotations method execute.
@Override
public void execute(Context context) {
BStruct annotationStruct = null;
if (context.getParentWorkerExecutionContext().parent.callableUnitInfo instanceof ResourceInfo) {
annotationStruct = (BStruct) BLangConnectorSPIUtil.getService(context.getProgramFile(), ((ResourceInfo) context.getParentWorkerExecutionContext().parent.callableUnitInfo).getServiceInfo().getType()).getAnnotationList(WebSubSubscriberConstants.WEBSUB_PACKAGE_PATH, WebSubSubscriberConstants.ANN_NAME_WEBSUB_SUBSCRIBER_SERVICE_CONFIG).get(0).getValue().getVMValue();
}
context.setReturnValues(annotationStruct);
}
Aggregations