use of CCDD.CcddClassesDataTable.TableInformation in project CCDD by nasa.
the class CcddScriptDataAccessHandler method getTableDataByColumnName.
/**
********************************************************************************************
* Get the data from the table in the specified column for the row in the matching column name
* that contains the matching name. Macro expansion is controlled by the input flag
*
* @param tableType
* table type (case insensitive). All structure table types are combined and are
* referenced by the type name "Structure", and all command table types are combined
* and are referenced by the type name "Command"
*
* @param tablePath
* full table path
*
* @param matchColumnName
* name of the column containing that matching name (case insensitive)
*
* @param matchName
* text to match in the matching column - this determines the row. The first row in
* the matching column that matches the matching name determines the row used to
* retrieve the data value
*
* @param dataColumnName
* name of the column from which to retrieve the data value (case insensitive)
*
* @param expandMacros
* true to replace any macros with their corresponding value; false to return the
* data with any macro names in place
*
* @return Contents of the table defined by the table type, table path, matching column name,
* matching name, and data column name specified; returns null if an instance of the
* table type, the matching column, the data column, or the matching name doesn't exist
********************************************************************************************
*/
private String getTableDataByColumnName(String tableType, String tablePath, String matchColumnName, String matchName, String dataColumnName, boolean expandMacros) {
String tableData = null;
// Get the reference to the table information class for the requested table type
TableInformation tableInfo = getTableInformation(tableType);
// Check that the table type exists
if (tableInfo != null) {
// Step through the table data
for (int row = 0; row < tableInfo.getData().length; row++) {
// Get the type definition based on the table's specific type name
TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(getTypeNameByRow(tableType, row));
// Get the index for the matching and data columns
int matchColumnIndex = typeDefn.getColumnIndexByUserName(matchColumnName);
int dataColumnIndex = typeDefn.getColumnIndexByUserName(dataColumnName);
// Check that the column names exist in the table
if (matchColumnIndex != -1 && dataColumnIndex != -1) {
// matches that in the matching name column
if (tableInfo.getData()[row][tableInfo.getData()[row].length - PATH_COLUMN_DELTA].equals(tablePath) && tableInfo.getData()[row][matchColumnIndex].equals(matchName)) {
// Store the contents of the table at the specified row and column and stop
// searching
tableData = tableInfo.getData()[row][dataColumnIndex];
// Check if any macros should be expanded
if (expandMacros) {
// Expand any macros in the data
tableData = macroHandler.getMacroExpansion(tableData);
}
// Check if the data field contains a message ID
if (typeDefn.getInputTypes()[dataColumnIndex].equals(InputDataType.MESSAGE_ID)) {
// Remove the auto-assignment protection flag, if present
tableData = CcddMessageIDHandler.removeProtectionFlag(tableData);
}
break;
}
}
}
}
return tableData;
}
use of CCDD.CcddClassesDataTable.TableInformation in project CCDD by nasa.
the class CcddScriptDataAccessHandler method getCommandArgMinimum.
/**
********************************************************************************************
* Get the argument minimum value (as a string) for the command argument specified at the
* specified row in the command data. Macro expansion is controlled by the input flag
*
* @param argumentNumber
* command argument index. The first argument is 0
*
* @param row
* table data row index
*
* @param expandMacros
* true to replace any macros with their corresponding value; false to return the
* data with any macro names in place
*
* @return Argument minimum value (as a string) for the command argument specified at the
* specified row in the command data; null if the argument number or row index is
* invalid
********************************************************************************************
*/
private String getCommandArgMinimum(int argumentNumber, int row, boolean expandMacros) {
String argMinimum = null;
// Get the table type definition for the command table referenced in the specified row
TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(getCommandTypeNameByRow(row));
// Check if the table type exists and represents a command
if (typeDefn != null && typeDefn.isCommand()) {
// Get the list of command arguments associated with this command table type
List<AssociatedColumns> commandArguments = typeDefn.getAssociatedCommandArgumentColumns(false);
// Check if the argument number is valid and that the argument minimum value exists
if (argumentNumber < commandArguments.size() && commandArguments.get(argumentNumber).getMinimum() != -1) {
// Get the reference to the table information
TableInformation tableInfo = getTableInformation(TYPE_COMMAND);
// Get the argument minimum value
argMinimum = tableInfo.getData()[row][commandArguments.get(argumentNumber).getMinimum()];
// Check if any macros should be expanded
if (expandMacros) {
// Expand any macros
argMinimum = macroHandler.getMacroExpansion(argMinimum);
}
}
}
return argMinimum;
}
use of CCDD.CcddClassesDataTable.TableInformation in project CCDD by nasa.
the class CcddScriptDataAccessHandler method getCommandArgName.
/**
********************************************************************************************
* Get the argument name for the command argument specified at the specified row in the command
* data. Macro expansion is controlled by the input flag
*
* @param argumentNumber
* command argument index. The first argument is 0
*
* @param row
* table data row index
*
* @param expandMacros
* true to replace any macros with their corresponding value; false to return the
* data with any macro names in place
*
* @return Argument name for the command argument specified at the specified row in the command
* data; null if the argument number or row index is invalid
********************************************************************************************
*/
private String getCommandArgName(int argumentNumber, int row, boolean expandMacros) {
String argName = null;
// Get the table type definition for the command table referenced in the specified row
TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(getCommandTypeNameByRow(row));
// Check if the table type exists and represents a command
if (typeDefn != null && typeDefn.isCommand()) {
// Get the list of command arguments associated with this command table type
List<AssociatedColumns> commandArguments = typeDefn.getAssociatedCommandArgumentColumns(false);
// Check if the argument number is valid and that the argument name exists
if (argumentNumber < commandArguments.size() && commandArguments.get(argumentNumber).getName() != -1) {
// Get the reference to the table information
TableInformation tableInfo = getTableInformation(TYPE_COMMAND);
// Get the argument name
argName = tableInfo.getData()[row][commandArguments.get(argumentNumber).getName()];
// Check if any macros should be expanded
if (expandMacros) {
// Expand any macros
argName = macroHandler.getMacroExpansion(argName);
}
}
}
return argName;
}
use of CCDD.CcddClassesDataTable.TableInformation in project CCDD by nasa.
the class CcddDbVerificationHandler method verifyDataTables.
/**
********************************************************************************************
* Check that the tables' data are consistent with their type definitions. If any
* inconsistencies are detected then get user approval to alter the table(s)
********************************************************************************************
*/
private void verifyDataTables() {
// Build the table tree
CcddTableTreeHandler tableTree = new CcddTableTreeHandler(ccddMain, TableTreeType.PROTOTYPE_TABLES, ccddMain.getMainFrame());
// Initialize the storage for each table's information and committed data
tableStorage = new ArrayList<TableStorage>();
// Initialize the progress bar within-step value counters
int count = 0;
int startProgress = progBar.getValue();
// Get the total number of rows in the table tree
int total = tableTree.getNodeCount(tableTree.getRootNode());
// Step through the root node's children
for (Enumeration<?> element = tableTree.getRootNode().preorderEnumeration(); element.hasMoreElements(); ) {
count++;
// Check if the user canceled verification
if (canceled) {
break;
}
// Get the referenced node and the path to the node
ToolTipTreeNode tableNode = (ToolTipTreeNode) element.nextElement();
TreePath path = new TreePath(tableNode.getPath());
// Check if the path references a table
if (path.getPathCount() > tableTree.getHeaderNodeLevel()) {
// Get the information from the database for the specified table
TableInformation tableInfo = dbTable.loadTableData(tableTree.getFullVariablePath(path.getPath()), false, false, false, ccddMain.getMainFrame());
// Check if the table loaded successfully and that the table has data
if (!tableInfo.isErrorFlag() && tableInfo.getData().length > 0) {
// Add the table information and data to the list. This stores a copy of the
// data (as it appears in the database) so that any changes made can be
// detected
tableStorage.add(new TableStorage(tableInfo, tableInfo.getData()));
// Get the table's type definition
typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
// Get the variable name, data type, and array size column indices for this
// table type
variableNameIndex = typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE);
dataTypeIndex = typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT);
arraySizeIndex = typeDefn.getColumnIndexByInputType(InputDataType.ARRAY_INDEX);
// Initialize the array check parameters: array data type, name, number of
// members, array dimension sizes, and current index position
String dataType = "";
String arrayName = "";
membersRemaining = 0;
totalArraySize = new int[0];
currentArrayIndex = new int[0];
// Initialize the array definition and last missing array member row indices
definitionRow = 0;
int lastMissingRow = 0;
// Step through each row in the table
for (int row = 0; row < tableInfo.getData().length && !canceled; row++) {
// Step through each column in the table
for (int column = 0; column < tableInfo.getData()[row].length && !canceled; column++) {
// Check if the cell value doesn't match the cell's input type
checkInputType(tableInfo, row, column);
}
// Check if the user canceled verification
if (canceled) {
continue;
}
// Check if this is a structure table
if (typeDefn.isStructure()) {
// Check if the array size isn't blank
if (tableInfo.getData()[row][arraySizeIndex] != null && !tableInfo.getData()[row][arraySizeIndex].isEmpty()) {
// definition is expected
if (membersRemaining == 0) {
// Get the variable name for this row
arrayName = tableInfo.getData()[row][variableNameIndex];
// Store the index of the array definition row
definitionRow = row;
// Store the row number for use if other members are found to
// be missing after all other rows have been checked
lastMissingRow = row;
// Check that no extra array member exists
if (!checkExcessArrayMember(tableInfo, row, arrayName)) {
// Get the number of array members remaining and data type
// for this row and initialize the array index
totalArraySize = ArrayVariable.getArrayIndexFromSize(macroHandler.getMacroExpansion(tableInfo.getData()[row][arraySizeIndex]));
// Get the total number of members for this array
membersRemaining = ArrayVariable.getNumMembersFromArrayDimension(totalArraySize);
// Initialize the current array index values
currentArrayIndex = new int[totalArraySize.length];
// Get the data type
dataType = tableInfo.getData()[row][dataTypeIndex];
// Check if the expected array definition is missing
if (checkForArrayDefinition(tableInfo, row, arrayName)) {
// Remove the array index from the array variable name
// and back up a row so that the array members can be
// checked
arrayName = ArrayVariable.removeArrayIndex(arrayName);
row--;
}
}
} else // This is not the first pass through this array; i.e., an array
// member is expected
{
// have the same variable name
if (checkArrayNamesMatch(tableInfo, row, arrayName)) {
// Back up a row so that it can be checked as a separate
// variable
row--;
} else // The array names match
{
// Check if the array definition and all of its members
// have the same array size
checkArraySizesMatch(tableInfo, row, arrayName, tableInfo.getData()[row][arraySizeIndex]);
// Check if the array definition and all of its members
// have the same data type
checkDataTypesMatch(tableInfo, row, arrayName, dataType);
// Store the row number for use if other members are found
// to be missing after all other rows have been checked
lastMissingRow = row;
}
// Update the array member counters
membersRemaining--;
// Update the current array index value(s)
goToNextArrayMember();
}
} else // Check if there are remaining array members that don't exist
{
// Check if an array member is expected but not present
checkForMissingArrayMember(tableInfo, row, arrayName);
}
}
}
// Check if this is a structure table
if (typeDefn.isStructure()) {
// Perform for each remaining missing array member
while (membersRemaining != 0) {
// Check if there are remaining array members that don't exist
checkForMissingArrayMember(tableInfo, lastMissingRow + 1, arrayName);
}
}
// Check if the flag to make changes is not already set
if (!isChanges) {
// Check if a row is missing based on the row indices
checkForRowIndexMismatch(tableInfo);
}
// Check if columns marked as unique contain duplicate values
checkForDuplicates(tableInfo);
}
}
// Update the within-step progress value
progBar.setValue(startProgress + (numDivisionPerStep * count / total));
}
}
use of CCDD.CcddClassesDataTable.TableInformation in project CCDD by nasa.
the class CcddCSVHandler method exportToFile.
/**
********************************************************************************************
* Export the project in CSV format to the specified file
*
* @param exportFile
* reference to the user-specified output file
*
* @param tableNames
* array of table names to export
*
* @param replaceMacros
* true to replace any embedded macros with their corresponding values
*
* @param includeReservedMsgIDs
* true to include the contents of the reserved message ID table in the export file
*
* @param includeVariablePaths
* true to include the variable path for each variable in a structure table, both in
* application format and using the user-defined separator characters
*
* @param variableHandler
* variable handler class reference; null if includeVariablePaths is false
*
* @param separators
* string array containing the variable path separator character(s), show/hide data
* types flag ('true' or 'false'), and data type/variable name separator
* character(s); null if includeVariablePaths is false
*
* @param extraInfo
* unused
*
* @return true if an error occurred preventing exporting the project to the file
********************************************************************************************
*/
@Override
public boolean exportToFile(FileEnvVar exportFile, String[] tableNames, boolean replaceMacros, boolean includeReservedMsgIDs, boolean includeVariablePaths, CcddVariableSizeAndConversionHandler variableHandler, String[] separators, Object... extraInfo) {
boolean errorFlag = false;
boolean addLineFeed = false;
FileWriter fw = null;
BufferedWriter bw = null;
PrintWriter pw = null;
try {
List<String> referencedTableTypes = new ArrayList<String>();
List<String> referencedDataTypes = new ArrayList<String>();
List<String> referencedMacros = new ArrayList<String>();
List<String[]> variablePaths = new ArrayList<String[]>();
// Output the table data to the selected file. Multiple writers are needed in case
// tables are appended to an existing file
fw = new FileWriter(exportFile, true);
bw = new BufferedWriter(fw);
pw = new PrintWriter(bw);
// Step through each table
for (String tblName : tableNames) {
// Get the information from the database for the specified table
TableInformation tableInfo = ccddMain.getDbTableCommandHandler().loadTableData(tblName, true, false, true, parent);
// Check if the table's data successfully loaded
if (!tableInfo.isErrorFlag()) {
// Output the file creation information (for the first pass only)
pw.printf((!addLineFeed ? "# Created " + new Date().toString() + " : project = " + dbControl.getDatabaseName() + " : host = " + dbControl.getServer() + " : user = " + dbControl.getUser() + "\n" : "") + "\n");
// Get the table type definition based on the type name
TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
// Check if this table type is not already output
if (!referencedTableTypes.contains(tableInfo.getType())) {
// Add the table type to the list of those referenced
referencedTableTypes.add(tableInfo.getType());
}
// Get the visible column names based on the table's type
String[] columnNames = typeDefn.getColumnNamesVisible();
// Check if the flag is set that indicates macros should be replaced
if (replaceMacros) {
// Replace all macro names with their corresponding values
tableInfo.setData(macroHandler.replaceAllMacros(tableInfo.getData()));
}
String systemName = fieldHandler.getFieldValue(tblName, InputDataType.SYSTEM_PATH);
// Check if the system name exists
if (systemName != null && !systemName.isEmpty()) {
// Store the system name
systemName = ",\"" + systemName + "\"";
}
// Output the table path (if applicable) and name, table type, and system name
// (if provided)
pw.printf(CSVTags.NAME_TYPE.getTag() + "\n%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(tableInfo.getTablePath(), tableInfo.getType(), systemName));
// Check if the table has a description
if (!tableInfo.getDescription().isEmpty()) {
// Output the table description tag and description
pw.printf(CSVTags.DESCRIPTION.getTag() + "\n%s\n", CcddUtilities.addEmbeddedQuotes(tableInfo.getDescription()));
}
// Output the column data tag and column names
pw.printf(CSVTags.COLUMN_NAMES.getTag() + "\n%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(columnNames));
// Step through each row in the table
for (int row = 0; row < tableInfo.getData().length; row++) {
// Output the table row data, skipping the hidden columns
pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(Arrays.copyOfRange(tableInfo.getData()[row], NUM_HIDDEN_COLUMNS, tableInfo.getData()[row].length)));
// Step through each column in the row, skipping the hidden columns
for (int column = NUM_HIDDEN_COLUMNS; column < columnNames.length; column++) {
List<Integer> dataTypeColumns = new ArrayList<Integer>();
// Get the column indices for all columns that can contain a primitive
// data type
dataTypeColumns.addAll(typeDefn.getColumnIndicesByInputType(InputDataType.PRIM_AND_STRUCT));
dataTypeColumns.addAll(typeDefn.getColumnIndicesByInputType(InputDataType.PRIMITIVE));
// Step through each data type column
for (int dataTypeColumn : dataTypeColumns) {
// Get the value in the data type column
String dataTypeName = tableInfo.getData()[row][dataTypeColumn].toString();
// list
if (dataTypeHandler.isPrimitive(dataTypeName) && !referencedDataTypes.contains(dataTypeName)) {
// Add the data type name to the list of references data types
referencedDataTypes.add(dataTypeName);
}
}
// Get the names of the macros referenced in the cell and add them to
// the list
referencedMacros.addAll(macroHandler.getReferencedMacros(tableInfo.getData()[row][column].toString()));
// represents a structure
if (includeVariablePaths && typeDefn.isStructure()) {
// Get the variable path
String variablePath = tableInfo.getTablePath() + "," + tableInfo.getData()[row][typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT)] + "." + tableInfo.getData()[row][typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE)];
// Add the path, in both application and user-defined formats, to
// the list to be output
variablePaths.add(new String[] { variablePath, variableHandler.getFullVariableName(variablePath, separators[0], Boolean.parseBoolean(separators[1]), separators[2]) });
}
}
}
// Get the table's data field information
List<FieldInformation> fieldInformation = tableInfo.getFieldHandler().getFieldInformation();
// Check if the table contains any data fields
if (!fieldInformation.isEmpty()) {
// Output the data field marker
pw.printf(CSVTags.DATA_FIELD.getTag() + "\n");
// Step through each data field
for (FieldInformation fieldInfo : fieldInformation) {
// Output the field information
pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(fieldInfo.getFieldName(), fieldInfo.getDescription(), Integer.toString(fieldInfo.getSize()), fieldInfo.getInputType().getInputName(), Boolean.toString(fieldInfo.isRequired()), fieldInfo.getApplicabilityType().getApplicabilityName(), fieldInfo.getValue()));
}
}
addLineFeed = true;
}
}
// Check if any table types are referenced
if (!referencedTableTypes.isEmpty()) {
// Step through each referenced table type
for (String tableType : referencedTableTypes) {
// Get the table type definition based on the type name
TypeDefinition tableTypeDefn = tableTypeHandler.getTypeDefinition(tableType);
// Output the table type tag, and the type name and description
pw.printf("\n" + CSVTags.TABLE_TYPE.getTag() + "\n%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(tableTypeDefn.getName(), tableTypeDefn.getDescription()));
// key and row index columns
for (int column = NUM_HIDDEN_COLUMNS; column < tableTypeDefn.getColumnCountDatabase(); column++) {
// Output the column definition
pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(tableTypeDefn.getColumnNamesUser()[column], tableTypeDefn.getColumnToolTips()[column], tableTypeDefn.getInputTypes()[column].getInputName(), tableTypeDefn.isRowValueUnique()[column].toString(), tableTypeDefn.isRequired()[column].toString(), tableTypeDefn.isStructureAllowed()[column].toString(), tableTypeDefn.isPointerAllowed()[column].toString()));
}
// Build the data field information for this table type
fieldHandler.buildFieldInformation(CcddFieldHandler.getFieldTypeName(tableType));
List<FieldInformation> fieldInformation = fieldHandler.getFieldInformation();
// Check if the table type contains any data fields
if (!fieldInformation.isEmpty()) {
// Output the data field marker
pw.printf(CSVTags.TABLE_TYPE_DATA_FIELD.getTag() + "\n");
// Step through each data field
for (FieldInformation fieldInfo : fieldInformation) {
// Output the field information
pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(fieldInfo.getFieldName(), fieldInfo.getDescription(), Integer.toString(fieldInfo.getSize()), fieldInfo.getInputType().getInputName(), Boolean.toString(fieldInfo.isRequired()), fieldInfo.getApplicabilityType().getApplicabilityName(), fieldInfo.getValue()));
}
}
}
}
// Check if any primitive data types are referenced
if (!referencedDataTypes.isEmpty()) {
// Output the data type marker
pw.printf("\n" + CSVTags.DATA_TYPE.getTag() + "\n");
// Step through each data type
for (String[] dataType : dataTypeHandler.getDataTypeData()) {
// Check if the data type is referenced in the table
if (referencedDataTypes.contains(CcddDataTypeHandler.getDataTypeName(dataType))) {
// Output the data type definition
pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(dataType[DataTypesColumn.USER_NAME.ordinal()], dataType[DataTypesColumn.C_NAME.ordinal()], dataType[DataTypesColumn.SIZE.ordinal()], dataType[DataTypesColumn.BASE_TYPE.ordinal()]));
}
}
}
// Check if any macros are referenced
if (!referencedMacros.isEmpty()) {
// Output the macro marker
pw.printf("\n" + CSVTags.MACRO.getTag() + "\n");
// Step through each macro
for (String[] macro : macroHandler.getMacroData()) {
// Check if the macro is referenced in the table
if (referencedMacros.contains(macro[MacrosColumn.MACRO_NAME.ordinal()])) {
// Output the macro definition
pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(macro[MacrosColumn.MACRO_NAME.ordinal()], macro[MacrosColumn.VALUE.ordinal()]));
}
}
}
// reserved message IDs defined
if (includeReservedMsgIDs && !rsvMsgIDHandler.getReservedMsgIDData().isEmpty()) {
// Output the reserved message ID marker
pw.printf("\n" + CSVTags.RESERVED_MSG_IDS.getTag() + "\n");
// Step through each reserved message ID
for (String[] reservedMsgID : rsvMsgIDHandler.getReservedMsgIDData()) {
// Output the reserved message ID definition
pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(reservedMsgID[ReservedMsgIDsColumn.MSG_ID.ordinal()], reservedMsgID[ReservedMsgIDsColumn.DESCRIPTION.ordinal()]));
}
}
// Check if variable paths are to be output and that any exist
if (includeVariablePaths && !variablePaths.isEmpty()) {
// Output the variable path marker
pw.printf("\n" + CSVTags.VARIABLE_PATHS.getTag() + "\n");
// Step through each variable path
for (String[] variablePath : variablePaths) {
// Output the variable path in application and user-defined formats
pw.printf("%s\n", CcddUtilities.addEmbeddedQuotesAndCommas(variablePath[0], variablePath[1]));
}
}
} catch (IOException ioe) {
// Inform the user that the data file cannot be written to
new CcddDialogHandler().showMessageDialog(parent, "<html><b>Cannot write to export file '</b>" + exportFile.getAbsolutePath() + "<b>'", "File Error", JOptionPane.ERROR_MESSAGE, DialogOption.OK_OPTION);
errorFlag = true;
} catch (Exception e) {
// Display a dialog providing details on the unanticipated error
CcddUtilities.displayException(e, parent);
errorFlag = true;
} finally {
// Check if the PrintWriter was opened
if (pw != null) {
// Close the file
pw.close();
}
try {
// Check if the BufferedWriter was opened
if (bw != null) {
// Close the file
bw.close();
}
// Check if the FileWriter was opened
if (fw != null) {
// Close the file
fw.close();
}
} catch (IOException ioe) {
// Inform the user that the data file cannot be closed
new CcddDialogHandler().showMessageDialog(parent, "<html><b>Cannot close export file '</b>" + exportFile.getAbsolutePath() + "<b>'", "File Warning", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
}
}
return errorFlag;
}
Aggregations