use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class MimeUtil method getParserError.
/**
* Get parser error as a ballerina struct.
*
* @param context Represent ballerina context
* @param errMsg Error message in string form
* @return Ballerina struct with parse error
*/
public static BStruct getParserError(Context context, String errMsg) {
PackageInfo errorPackageInfo = context.getProgramFile().getPackageInfo(BUILTIN_PACKAGE);
StructInfo errorStructInfo = errorPackageInfo.getStructInfo(STRUCT_GENERIC_ERROR);
BStruct parserError = new BStruct(errorStructInfo.getType());
parserError.setStringField(0, errMsg);
return parserError;
}
use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class MimeUtil method createEntityError.
/**
* Get entity error as a ballerina struct.
*
* @param context Represent ballerina context
* @param msg Error message in string form
* @return Ballerina struct with entity error
*/
public static BStruct createEntityError(Context context, String msg) {
PackageInfo filePkg = context.getProgramFile().getPackageInfo(PROTOCOL_PACKAGE_MIME);
StructInfo entityErrInfo = filePkg.getStructInfo(ENTITY_ERROR);
return BLangVMStructs.createBStruct(entityErrInfo, msg);
}
use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class Hub method startUpHubService.
/**
* Method to compile and start up the default Ballerina WebSub Hub.
*/
public String startUpHubService() {
synchronized (this) {
if (!isStarted()) {
URI balxPath = URI.create(String.valueOf(Hub.class.getClassLoader().getResource("net.websub.hub.balx")));
ProgramFile hubProgramFile = readExecutableProgram(Paths.get(balxPath));
PackageInfo hubPackageInfo = hubProgramFile.getPackageInfo("net.websub.hub");
if (hubPackageInfo != null) {
hubPackageInfo.setProgramFile(hubProgramFile);
BLangProgramRunner.runService(hubProgramFile);
BValue[] args = {};
String webSubHubUrl = (BLangFunctions.invokeCallable(hubPackageInfo.getFunctionInfo("getHubUrl"), args)[0]).stringValue();
logger.info("Default Ballerina WebSub Hub started up at " + webSubHubUrl);
PrintStream console = System.out;
console.println("ballerina: Default Ballerina WebSub Hub started up at " + webSubHubUrl);
hubUrl = webSubHubUrl;
setHubProgramFile(hubProgramFile);
started = true;
BLangFunctions.invokeCallable(hubPackageInfo.getFunctionInfo("setupOnStartup"), args);
}
}
}
return hubUrl;
}
Aggregations