Search in sources :

Example 1 with ResourceInfo

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);
}
Also used : ResourceInfo(org.ballerinalang.util.codegen.ResourceInfo) StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) ActionInfo(org.ballerinalang.util.codegen.ActionInfo) LineNumberInfo(org.ballerinalang.util.codegen.LineNumberInfo) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Example 2 with ResourceInfo

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);
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) ResourceInfo(org.ballerinalang.util.codegen.ResourceInfo) BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) LocalTransactionInfo(org.ballerinalang.util.transactions.LocalTransactionInfo)

Example 3 with ResourceInfo

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);
}
Also used : Path(io.swagger.models.Path) ResourceInfo(org.ballerinalang.util.codegen.ResourceInfo) HashMap(java.util.HashMap) Operation(io.swagger.models.Operation)

Example 4 with ResourceInfo

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);
}
Also used : ResourceInfo(org.ballerinalang.util.codegen.ResourceInfo) BStruct(org.ballerinalang.model.values.BStruct)

Aggregations

ResourceInfo (org.ballerinalang.util.codegen.ResourceInfo)4 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 HashMap (java.util.HashMap)1 WorkerExecutionContext (org.ballerinalang.bre.bvm.WorkerExecutionContext)1 BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)1 BStruct (org.ballerinalang.model.values.BStruct)1 ActionInfo (org.ballerinalang.util.codegen.ActionInfo)1 LineNumberInfo (org.ballerinalang.util.codegen.LineNumberInfo)1 PackageInfo (org.ballerinalang.util.codegen.PackageInfo)1 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)1 StructInfo (org.ballerinalang.util.codegen.StructInfo)1 LocalTransactionInfo (org.ballerinalang.util.transactions.LocalTransactionInfo)1