Class ExcelHelper
- java.lang.Object
-
- com.nomagic.magicdraw.simulation.excelimport.ExcelHelper
-
@OpenApiAll public class ExcelHelper extends java.lang.Object
The helper class being used in the scripts for handling data transformation and other utilities between fUML runtime object and Excel file.- Since:
- CST 18.0
-
-
Field Summary
Fields Modifier and Type Field Description private fUML.Semantics.Classes.Kernel.Object_
context
The context that ALH is evaluated.private com.nomagic.magicdraw.simulation.execution.session.ESimulationSession
ownerSession
The running session of this instance.private Element
scriptContainer
The script container
-
Constructor Summary
Constructors Constructor Description ExcelHelper(SimulationSession session)
constructor.ExcelHelper(SimulationSession session, Element scriptContainer)
constructor.ExcelHelper(fUML.Semantics.Classes.Kernel.Object_ context)
constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private Element
findElement(java.lang.String keyword, java.lang.Class[] types)
java.lang.Object
getCellValue(java.lang.String fileName, java.lang.String sheetName, java.lang.Number atRow, java.lang.Number atCol)
get value by specific row and column in the excel file.private fUML.Semantics.Classes.Kernel.Object_
getContext()
private Element
getElement()
int
getLatestRowNum(java.lang.String fileName, java.lang.String sheetName)
Get the latest row number of the sheet in the excel file.private fUML.Semantics.Classes.Kernel.ValueList
getSavingValue(java.lang.Object object)
Check and create the valueList for saving to excel file.private Element
getScriptContainer()
private static boolean
isClassMapping(Element ele)
private static boolean
isMappingElement(Element element)
private static boolean
isSupportMapping(Element element)
fUML.Semantics.Classes.Kernel.ValueList
readObjectFromSpreadSheet(java.lang.String fileName, java.lang.Number rowIndex)
Read the excel file and create the fUML ValueList.fUML.Semantics.Classes.Kernel.ValueList
readObjectFromSpreadSheet(java.lang.String fileName, java.lang.Number rowIndex, java.lang.Object mappingClass)
Read the excel file and create the fUML ValueList.fUML.Semantics.Classes.Kernel.ValueList
readObjectFromSpreadSheet(java.lang.String fileName, java.lang.String sheetName, java.lang.Number rowIndex)
Read the excel file and create the fUML ValueList.fUML.Semantics.Classes.Kernel.ValueList
readObjectFromSpreadSheet(java.lang.String fileName, java.lang.String sheetName, java.lang.Number rowIndex, java.lang.Object mappingClass)
Read the excel file and create the fUML ValueList.fUML.Semantics.Classes.Kernel.ValueList
readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.Number startRow, java.lang.Number endRow)
Read the excel file and create the fUML ValueList.fUML.Semantics.Classes.Kernel.ValueList
readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.Number startRow, java.lang.Number endRow, java.lang.Object mappingClass)
Read the excel file and create the fUML ValueList.fUML.Semantics.Classes.Kernel.ValueList
readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.Object mappingClass)
Read the excel file and create the fUML ValueList for all rows in excel.fUML.Semantics.Classes.Kernel.ValueList
readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.String name)
Read the excel file and create the fUML ValueList for all rows in excel.fUML.Semantics.Classes.Kernel.ValueList
readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.String sheetName, java.lang.Number startRow, java.lang.Number endRow)
Read the excel file and create the fUML ValueList.fUML.Semantics.Classes.Kernel.ValueList
readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.String sheetName, java.lang.Number startRow, java.lang.Number endRow, java.lang.Object mappingClass)
Read the excel file and create the fUML ValueList.fUML.Semantics.Classes.Kernel.ValueList
readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.String sheetName, java.lang.Object mappingClass)
Read the excel file and create the fUML ValueList for all rows in excel.void
setCellValue(java.lang.Object object, java.lang.String fileName, java.lang.String sheetName, java.lang.Number atRow, java.lang.Number atCol)
Set fUML runtime value to specific row and column in the excel file.void
updatefUMLValueFromSpreadSheet(fUML.Semantics.Classes.Kernel.StructuredValue value, java.lang.String fileName, java.lang.Number rowIndex)
update the value of SpreadSheet to fUML runtime object.void
updatefUMLValueFromSpreadSheet(fUML.Semantics.Classes.Kernel.StructuredValue value, java.lang.String fileName, java.lang.Number rowIndex, java.lang.Object mappingClass)
update the value of SpreadSheet to fUML runtime object.void
updatefUMLValueFromSpreadSheet(fUML.Semantics.Classes.Kernel.StructuredValue value, java.lang.String fileName, java.lang.String sheetName, java.lang.Number rowIndex)
update the value of SpreadSheet to fUML runtime object.void
updatefUMLValueFromSpreadSheet(fUML.Semantics.Classes.Kernel.StructuredValue value, java.lang.String fileName, java.lang.String sheetName, java.lang.Number rowIndex, java.lang.Object mappingClass)
update the value of SpreadSheet to fUML runtime object.void
writeObjectsToSpreadSheet(java.lang.Object object, java.lang.String fileName, java.lang.Number atRow, boolean isReplace)
Write the fUML runtime value to the excel file.void
writeObjectsToSpreadSheet(java.lang.Object object, java.lang.String fileName, java.lang.Number atRow, boolean isReplace, java.lang.Object mappingClass)
Write the fUML runtime value to the excel file.void
writeObjectsToSpreadSheet(java.lang.Object object, java.lang.String fileName, java.lang.String sheetName, java.lang.Number atRow, boolean isReplace)
Write the fUML runtime value to the excel file.void
writeObjectsToSpreadSheet(java.lang.Object object, java.lang.String fileName, java.lang.String sheetName, java.lang.Number atRow, boolean isReplace, java.lang.Object mappingClass)
Write the fUML runtime value to the excel file.
-
-
-
Field Detail
-
context
private fUML.Semantics.Classes.Kernel.Object_ context
The context that ALH is evaluated. It same context as the context of script engine.
-
ownerSession
private final com.nomagic.magicdraw.simulation.execution.session.ESimulationSession ownerSession
The running session of this instance.
-
scriptContainer
private Element scriptContainer
The script container
-
-
Constructor Detail
-
ExcelHelper
public ExcelHelper(SimulationSession session)
constructor.- Parameters:
session
- the running session.
-
ExcelHelper
public ExcelHelper(SimulationSession session, Element scriptContainer)
constructor.- Parameters:
session
- the running session.
-
ExcelHelper
public ExcelHelper(fUML.Semantics.Classes.Kernel.Object_ context)
constructor.- Parameters:
context
- the context of caller
-
-
Method Detail
-
findElement
@CheckForNull private Element findElement(java.lang.String keyword, java.lang.Class[] types)
-
getContext
@CheckForNull private fUML.Semantics.Classes.Kernel.Object_ getContext()
-
getLatestRowNum
public int getLatestRowNum(java.lang.String fileName, java.lang.String sheetName)
Get the latest row number of the sheet in the excel file.- Parameters:
fileName
- the excel file namesheetName
- the sheet name- Returns:
- the latest row number of the sheet in the excel file
-
readObjectFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectFromSpreadSheet(java.lang.String fileName, java.lang.Number rowIndex) throws java.lang.Exception
Read the excel file and create the fUML ValueList.- Parameters:
fileName
- the excel file namerowIndex
- the index of row- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
readObjectFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectFromSpreadSheet(java.lang.String fileName, java.lang.Number rowIndex, java.lang.Object mappingClass) throws java.lang.Exception
Read the excel file and create the fUML ValueList.- Parameters:
fileName
- the excel file namerowIndex
- the index of rowmappingClass
- the mapping class nameString
or mapping classElement
- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
readObjectFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectFromSpreadSheet(java.lang.String fileName, java.lang.String sheetName, java.lang.Number rowIndex) throws java.lang.Exception
Read the excel file and create the fUML ValueList.- Parameters:
fileName
- the excel file namesheetName
- the sheet namerowIndex
- the index of row- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
readObjectFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectFromSpreadSheet(java.lang.String fileName, java.lang.String sheetName, java.lang.Number rowIndex, java.lang.Object mappingClass) throws java.lang.Exception
Read the excel file and create the fUML ValueList.- Parameters:
fileName
- the excel file namesheetName
- the sheet namerowIndex
- the index of rowmappingClass
- the mapping class nameString
or mapping classElement
- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
readObjectsFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.Number startRow, java.lang.Number endRow) throws java.lang.Exception
Read the excel file and create the fUML ValueList.- Parameters:
fileName
- the excel file namestartRow
- the start row numberendRow
- the end row number- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
readObjectsFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.Number startRow, java.lang.Number endRow, java.lang.Object mappingClass) throws java.lang.Exception
Read the excel file and create the fUML ValueList.- Parameters:
fileName
- the excel file namestartRow
- the start row numberendRow
- the end row numbermappingClass
- the mapping class nameString
or mapping classElement
- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
readObjectsFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.String sheetName, java.lang.Number startRow, java.lang.Number endRow) throws java.lang.Exception
Read the excel file and create the fUML ValueList.- Parameters:
fileName
- the excel file namesheetName
- the sheet namestartRow
- the start row numberendRow
- the end row number- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
readObjectsFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.Object mappingClass) throws java.lang.Exception
Read the excel file and create the fUML ValueList for all rows in excel.- Parameters:
fileName
- the excel file namemappingClass
- the mapping class nameString
or mapping classElement
- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
readObjectsFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.String name) throws java.lang.Exception
Read the excel file and create the fUML ValueList for all rows in excel.- Parameters:
fileName
- the excel file namename
- the name of Mapping Class or sheet name.- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
readObjectsFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.String sheetName, java.lang.Object mappingClass) throws java.lang.Exception
Read the excel file and create the fUML ValueList for all rows in excel.- Parameters:
fileName
- the excel file namesheetName
- the sheet namemappingClass
- the mapping class nameString
or mapping classElement
- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
readObjectsFromSpreadSheet
public fUML.Semantics.Classes.Kernel.ValueList readObjectsFromSpreadSheet(java.lang.String fileName, java.lang.String sheetName, java.lang.Number startRow, java.lang.Number endRow, java.lang.Object mappingClass) throws java.lang.Exception
Read the excel file and create the fUML ValueList.- Parameters:
fileName
- the excel file namesheetName
- the sheet namestartRow
- the start row numberendRow
- the end row numbermappingClass
- the mapping class nameString
or mapping classElement
- Returns:
- the fUML ValueList of the data in the excel file
- Throws:
java.lang.Exception
- could be thrown if problem occurs when reading excel data
-
setCellValue
public void setCellValue(java.lang.Object object, java.lang.String fileName, java.lang.String sheetName, java.lang.Number atRow, java.lang.Number atCol)
Set fUML runtime value to specific row and column in the excel file.- Parameters:
object
- the fUML runtime value (ValueList/Value)fileName
- the excel file namesheetName
- the sheet nameatRow
- the row index numberatCol
- the column index number
-
getCellValue
@CheckForNull public java.lang.Object getCellValue(java.lang.String fileName, java.lang.String sheetName, java.lang.Number atRow, java.lang.Number atCol)
get value by specific row and column in the excel file.- Parameters:
fileName
- the excel file namesheetName
- the sheet nameatRow
- the row index numberatCol
- the column index number- Returns:
- the value of cell
-
updatefUMLValueFromSpreadSheet
public void updatefUMLValueFromSpreadSheet(fUML.Semantics.Classes.Kernel.StructuredValue value, java.lang.String fileName, java.lang.Number rowIndex) throws java.lang.Exception
update the value of SpreadSheet to fUML runtime object.- Parameters:
value
- the runtime objectfileName
- the spreadSheet file pathrowIndex
- the row index- Throws:
java.lang.Exception
-
updatefUMLValueFromSpreadSheet
public void updatefUMLValueFromSpreadSheet(fUML.Semantics.Classes.Kernel.StructuredValue value, java.lang.String fileName, java.lang.String sheetName, java.lang.Number rowIndex) throws java.lang.Exception
update the value of SpreadSheet to fUML runtime object.- Parameters:
value
- the runtime objectfileName
- the spreadSheet file pathsheetName
- the sheet namerowIndex
- the row index- Throws:
java.lang.Exception
-
updatefUMLValueFromSpreadSheet
public void updatefUMLValueFromSpreadSheet(fUML.Semantics.Classes.Kernel.StructuredValue value, java.lang.String fileName, java.lang.Number rowIndex, java.lang.Object mappingClass) throws java.lang.Exception
update the value of SpreadSheet to fUML runtime object.- Parameters:
value
- the runtime objectfileName
- the spreadSheet file pathrowIndex
- the row indexmappingClass
- the mapping class nameString
or mapping classElement
- Throws:
java.lang.Exception
-
updatefUMLValueFromSpreadSheet
public void updatefUMLValueFromSpreadSheet(fUML.Semantics.Classes.Kernel.StructuredValue value, java.lang.String fileName, java.lang.String sheetName, java.lang.Number rowIndex, @CheckForNull java.lang.Object mappingClass) throws java.lang.Exception
update the value of SpreadSheet to fUML runtime object.- Parameters:
value
- the runtime objectfileName
- the spreadSheet file pathsheetName
- the sheet namerowIndex
- the row indexmappingClass
- the mapping class nameString
or mapping classElement
- Throws:
java.lang.Exception
-
writeObjectsToSpreadSheet
public void writeObjectsToSpreadSheet(java.lang.Object object, java.lang.String fileName, java.lang.Number atRow, boolean isReplace, java.lang.Object mappingClass) throws java.lang.Exception
Write the fUML runtime value to the excel file.- Parameters:
object
- the fUML runtime value (ValueList/Value)fileName
- the excel file nameatRow
- the row number to write the dataisReplace
- if true, it will replace the existing data if false, it will insert the data at atRowmappingClass
- the mapping class nameString
or mapping classElement
- Throws:
java.lang.Exception
-
writeObjectsToSpreadSheet
public void writeObjectsToSpreadSheet(java.lang.Object object, java.lang.String fileName, java.lang.String sheetName, java.lang.Number atRow, boolean isReplace) throws java.lang.Exception
Write the fUML runtime value to the excel file.- Parameters:
object
- the fUML runtime value (ValueList/Value)fileName
- the excel file namesheetName
- the sheet nameatRow
- the row number to write the dataisReplace
- if true, it will replace the existing data if false, it will insert the data at atRow- Throws:
java.lang.Exception
-
writeObjectsToSpreadSheet
public void writeObjectsToSpreadSheet(java.lang.Object object, java.lang.String fileName, java.lang.Number atRow, boolean isReplace) throws java.lang.Exception
Write the fUML runtime value to the excel file.- Parameters:
object
- the fUML runtime value (ValueList/Value)fileName
- the excel file nameatRow
- the row number to write the dataisReplace
- if true, it will replace the existing data if false, it will insert the data at atRow- Throws:
java.lang.Exception
-
writeObjectsToSpreadSheet
public void writeObjectsToSpreadSheet(java.lang.Object object, java.lang.String fileName, java.lang.String sheetName, java.lang.Number atRow, boolean isReplace, @CheckForNull java.lang.Object mappingClass) throws java.lang.Exception
Write the fUML runtime value to the excel file.- Parameters:
object
- the fUML runtime value (ValueList/Value)fileName
- the excel file namesheetName
- the sheet nameatRow
- the row number to write the dataisReplace
- if true, it will replace the existing data if false, it will insert the data at atRowmappingClass
- the mapping class nameString
or mapping classElement
- Throws:
java.lang.Exception
-
getSavingValue
private fUML.Semantics.Classes.Kernel.ValueList getSavingValue(java.lang.Object object)
Check and create the valueList for saving to excel file.- Parameters:
object
- the value for saving- Returns:
- ValueList for save
-
isSupportMapping
private static boolean isSupportMapping(@CheckForNull Element element)
-
isMappingElement
private static boolean isMappingElement(@CheckForNull Element element)
-
isClassMapping
private static boolean isClassMapping(Element ele)
-
getElement
@CheckForNull private Element getElement()
-
getScriptContainer
@CheckForNull private Element getScriptContainer()
-
-