Search in sources :

Example 46 with PackageInfo

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

Example 47 with PackageInfo

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

Example 48 with PackageInfo

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;
}
Also used : PrintStream(java.io.PrintStream) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) BValue(org.ballerinalang.model.values.BValue) URI(java.net.URI) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Aggregations

PackageInfo (org.ballerinalang.util.codegen.PackageInfo)48 StructInfo (org.ballerinalang.util.codegen.StructInfo)35 BStruct (org.ballerinalang.model.values.BStruct)17 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)10 BValue (org.ballerinalang.model.values.BValue)6 BStructType (org.ballerinalang.model.types.BStructType)5 FunctionInfo (org.ballerinalang.util.codegen.FunctionInfo)5 Debugger (org.ballerinalang.util.debugger.Debugger)5 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)5 BInteger (org.ballerinalang.model.values.BInteger)2 BMap (org.ballerinalang.model.values.BMap)2 BString (org.ballerinalang.model.values.BString)2 SocketIOChannel (org.ballerinalang.nativeimpl.io.channels.SocketIOChannel)2 Channel (org.ballerinalang.nativeimpl.io.channels.base.Channel)2 TesterinaFunction (org.ballerinalang.testerina.core.entity.TesterinaFunction)2 Instruction (org.ballerinalang.util.codegen.Instruction)2 PackageVarInfo (org.ballerinalang.util.codegen.PackageVarInfo)2 BLangRuntimeException (org.ballerinalang.util.exceptions.BLangRuntimeException)2 Test (org.testng.annotations.Test)2 PrintStream (java.io.PrintStream)1