license.js

const fs = require("fs");
const {Buffer} = require("buffer");
const _MwWrapper = require("./_mwbridge/_mw-wrapper.js");
const BarcodeException = require("./barcode-exception");
const {JsLicense} = require("./_mwbridge/_mw-bridge");

/**
 * Provides methods to license the component.
 */
class License extends _MwWrapper
{
    /**
     * Initializes a new instance of this class.
     */
    constructor()
    {
        super(new JsLicense());
    }

    /**
     * Licenses the component.
     *
     * @param licensePath path to license file
     */
    setLicense(licensePath)
    {
        try
        {
            let file_data = License.openFile(licensePath);
            this.getJavaClass().setLicenseSync(file_data);
        } catch (ex)
        {
            throw new BarcodeException(ex);
        }
    }

    resetLicense()
    {
        try
        {
            let mwObject = this.getJavaClass();
            mwObject.resetLicenseSync();
        } catch (ex)
        {
            throw new BarcodeException(ex);
        }
    }

    isLicensed()
    {
        let is_licensed = this.getJavaClass().isLicensedSync();
        return is_licensed.toString();
    }

    static openFile(filename)
    {
        let buffer = Buffer.from(fs.readFileSync(filename, 'utf8'));
        let array = [];
        array.push('');
        for (let i = 0; i < buffer.length; i++)
        {
            array.push(buffer[i] + '');
        }
        return array;
    }

    _initializeWrapperMembers()
    {
//      do nothing
    }
}
module.exports = License;