Class UnloadableLazyWorkbookLoader

  • All Implemented Interfaces:
    WorkbookLoader

    public class UnloadableLazyWorkbookLoader
    extends Object
    implements WorkbookLoader
    Provides lazy loading access to the workbook. When getWorkbook() first time is called, it is loaded from file system and then is cached using WeakReference. If that workbook is used nowhere, it can at a certain moment be garbage collected, and after that if getWorkbook() is called, the workbook will be loaded again. If you want to prevent garbage collecting loaded Workbook instance, invoke setCanUnload(false).
    • Constructor Detail

      • UnloadableLazyWorkbookLoader

        public UnloadableLazyWorkbookLoader​(IOpenSourceCodeModule fileSource)
    • Method Detail

      • getWorkbook

        public org.apache.poi.ss.usermodel.Workbook getWorkbook()
        Get the workbook. Depending on isCanUnload() state, when this method is repeatedly called, it can (but mustn't) return different instances of workbook java object.
        Specified by:
        getWorkbook in interface WorkbookLoader
        Returns:
        loaded workbook
        See Also:
        isCanUnload()
      • loadWorkbook

        protected org.apache.poi.ss.usermodel.Workbook loadWorkbook()
      • getSheetLoader

        public SheetLoader getSheetLoader​(int sheetIndex)
        Get the sheet accessor
        Specified by:
        getSheetLoader in interface WorkbookLoader
        Parameters:
        sheetIndex - the sheet index in the workbook
        Returns:
        object that provides access to the specified sheet of current workbook
      • setCanUnload

        public void setCanUnload​(boolean canUnload)
        Set the flag that this workbook can or cannot be unloaded. If workbook cannot be unloaded (for example when we edit the workbook) internal implementation should always keep strong reference to workbook and WorkbookLoader.getWorkbook() always returns the same Workbook instance.
        Specified by:
        setCanUnload in interface WorkbookLoader
        Parameters:
        canUnload - the flag that this workbook can or cannot be unloaded
        See Also:
        WorkbookLoader.isCanUnload()
      • getNumberOfSheets

        public int getNumberOfSheets()
        Get number of sheets in current workbook.
        Specified by:
        getNumberOfSheets in interface WorkbookLoader
        Returns:
        the number of sheets in current workbook