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