Package org.openl.rules.lang.xls.load
Class UnloadableLazyWorkbookLoader
- java.lang.Object
-
- org.openl.rules.lang.xls.load.UnloadableLazyWorkbookLoader
-
- All Implemented Interfaces:
WorkbookLoader
public class UnloadableLazyWorkbookLoader extends Object implements WorkbookLoader
Provides lazy loading access to the workbook. WhengetWorkbook()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 ifgetWorkbook()is called, the workbook will be loaded again. If you want to prevent garbage collecting loaded Workbook instance, invokesetCanUnload(false).
-
-
Constructor Summary
Constructors Constructor Description UnloadableLazyWorkbookLoader(IOpenSourceCodeModule fileSource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetNumberOfSheets()Get number of sheets in current workbook.SheetLoadergetSheetLoader(int sheetIndex)Get the sheet accessorSpreadsheetConstantsgetSpreadsheetConstants()org.apache.poi.ss.usermodel.WorkbookgetWorkbook()Get the workbook.booleanisCanUnload()If true - the workbook can (but mustn't) be unloaded (for example if there is no enough memory).protected org.apache.poi.ss.usermodel.WorkbookloadWorkbook()voidsetCanUnload(boolean canUnload)Set the flag that this workbook can or cannot be unloaded.
-
-
-
Constructor Detail
-
UnloadableLazyWorkbookLoader
public UnloadableLazyWorkbookLoader(IOpenSourceCodeModule fileSource)
-
-
Method Detail
-
getWorkbook
public org.apache.poi.ss.usermodel.Workbook getWorkbook()
Get the workbook. Depending onisCanUnload()state, when this method is repeatedly called, it can (but mustn't) return different instances of workbook java object.- Specified by:
getWorkbookin interfaceWorkbookLoader- 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:
getSheetLoaderin interfaceWorkbookLoader- Parameters:
sheetIndex- the sheet index in the workbook- Returns:
- object that provides access to the specified sheet of current workbook
-
isCanUnload
public boolean isCanUnload()
If true - the workbook can (but mustn't) be unloaded (for example if there is no enough memory). In this case when the
WorkbookLoader.getWorkbook()is repeatedly called, it can (but mustn't) return different instances of workbook java object.If false - the workbook is not unloaded and
WorkbookLoader.getWorkbook()always returns the same Workbook instance.- Specified by:
isCanUnloadin interfaceWorkbookLoader- Returns:
- the flag that this workbook can or cannot be unloaded.
- See Also:
WorkbookLoader.setCanUnload(boolean)
-
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 andWorkbookLoader.getWorkbook()always returns the same Workbook instance.- Specified by:
setCanUnloadin interfaceWorkbookLoader- 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:
getNumberOfSheetsin interfaceWorkbookLoader- Returns:
- the number of sheets in current workbook
-
getSpreadsheetConstants
public SpreadsheetConstants getSpreadsheetConstants()
- Specified by:
getSpreadsheetConstantsin interfaceWorkbookLoader
-
-