Search in sources :

Example 1 with BServiceType

use of org.ballerinalang.model.types.BServiceType in project ballerina by ballerina-lang.

the class BLangConnectorSPIUtil method getServiceRegistered.

/**
 * Returns Service registered.
 *
 * Note: Call this util method when service is required, in register server connector SPI function.
 *
 * @param context invocation Context
 * @return register service.
 */
public static Service getServiceRegistered(Context context) {
    BValue result = context.getRefArgument(1);
    if (result == null || result.getType().getTag() != TypeTags.TYPEDESC_TAG || ((BTypeDescValue) result).value().getTag() != TypeTags.SERVICE_TAG) {
        throw new BallerinaConnectorException("Can't get service reference");
    }
    final BServiceType serviceType = (BServiceType) ((BTypeDescValue) result).value();
    final ProgramFile programFile = context.getProgramFile();
    final Service service = getService(programFile, serviceType);
    BLangFunctions.invokeServiceInitFunction(service.getServiceInfo().getInitFunctionInfo());
    return service;
}
Also used : BValue(org.ballerinalang.model.values.BValue) BServiceType(org.ballerinalang.model.types.BServiceType) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Example 2 with BServiceType

use of org.ballerinalang.model.types.BServiceType in project ballerina by ballerina-lang.

the class ProgramFileReader method readServiceInfoEntries.

private void readServiceInfoEntries(DataInputStream dataInStream, PackageInfo packageInfo) throws IOException {
    int serviceCount = dataInStream.readShort();
    for (int i = 0; i < serviceCount; i++) {
        // Read connector name cp index
        int serviceNameCPIndex = dataInStream.readInt();
        UTF8CPEntry serviceNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(serviceNameCPIndex);
        int flags = dataInStream.readInt();
        // Read connector signature cp index;
        int endpointNameCPIndex = dataInStream.readInt();
        UTF8CPEntry endpointNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(endpointNameCPIndex);
        ServiceInfo serviceInfo = new ServiceInfo(packageInfo.getPkgNameCPIndex(), packageInfo.getPkgPath(), serviceNameCPIndex, serviceNameUTF8Entry.getValue(), flags, endpointNameCPIndex, endpointNameUTF8Entry.getValue());
        serviceInfo.setPackageInfo(packageInfo);
        packageInfo.addServiceInfo(serviceInfo.getName(), serviceInfo);
        serviceInfo.setType(new BServiceType(serviceInfo.getName(), packageInfo.getPkgPath()));
    }
}
Also used : UTF8CPEntry(org.ballerinalang.util.codegen.cpentries.UTF8CPEntry) BServiceType(org.ballerinalang.model.types.BServiceType)

Example 3 with BServiceType

use of org.ballerinalang.model.types.BServiceType in project ballerina by ballerina-lang.

the class ServiceTypeTest method testServiceType.

@Test
public void testServiceType() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testServiceType");
    Assert.assertTrue(returns[0] instanceof BTypeDescValue);
    Assert.assertEquals(returns[0].stringValue(), "HelloWorld");
    final BTypeDescValue value = (BTypeDescValue) returns[0];
    Assert.assertTrue(value.value() instanceof BServiceType);
}
Also used : BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) BValue(org.ballerinalang.model.values.BValue) BServiceType(org.ballerinalang.model.types.BServiceType) Test(org.testng.annotations.Test)

Example 4 with BServiceType

use of org.ballerinalang.model.types.BServiceType in project ballerina by ballerina-lang.

the class GetResourceAnnotations method execute.

@Override
public void execute(Context context) {
    BTypeDescValue bTypeValue = (BTypeDescValue) context.getRefArgument(0);
    if (!(bTypeValue.value() instanceof BServiceType)) {
        context.setReturnValues((BValue) null);
    }
    BServiceType serviceType = (BServiceType) bTypeValue.value();
    String key = serviceType.getName() + DOT + context.getStringArgument(0);
    context.setReturnValues(getAnnotationValue(context, serviceType.getPackagePath(), key));
}
Also used : BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) BServiceType(org.ballerinalang.model.types.BServiceType)

Example 5 with BServiceType

use of org.ballerinalang.model.types.BServiceType in project ballerina by ballerina-lang.

the class GetServiceAnnotations method execute.

@Override
public void execute(Context context) {
    BTypeDescValue bTypeValue = (BTypeDescValue) context.getRefArgument(0);
    if (!(bTypeValue.value() instanceof BServiceType)) {
        context.setReturnValues((BValue) null);
    }
    BServiceType serviceType = (BServiceType) bTypeValue.value();
    context.setReturnValues(getAnnotationValue(context, serviceType.getPackagePath(), serviceType.getName()));
}
Also used : BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) BServiceType(org.ballerinalang.model.types.BServiceType)

Aggregations

BServiceType (org.ballerinalang.model.types.BServiceType)5 BTypeDescValue (org.ballerinalang.model.values.BTypeDescValue)3 BValue (org.ballerinalang.model.values.BValue)2 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)1 UTF8CPEntry (org.ballerinalang.util.codegen.cpentries.UTF8CPEntry)1 Test (org.testng.annotations.Test)1