use of org.ccsds.schema.sois.seds.NamespaceType in project CCDD by nasa.
the class CcddEDSHandler method importFromFile.
/**
********************************************************************************************
* Import the the table definitions from an EDS XML formatted file
*
* @param importFile
* reference to the user-specified XML input file
*
* @param importType
* ImportType.IMPORT_ALL to import the table type, data type, and macro definitions,
* and the data from all the table definitions; ImportType.FIRST_DATA_ONLY to load
* only the data for the first table defined
*
* @throws CCDDException
* If a data is missing, extraneous, or in error in the import file
*
* @throws IOException
* If an import file I/O error occurs
*
* @throws Exception
* For any unanticipated errors
********************************************************************************************
*/
@Override
public void importFromFile(FileEnvVar importFile, ImportType importType) throws CCDDException, IOException, Exception {
try {
// Import the XML from the specified file
JAXBElement<?> jaxbElement = (JAXBElement<?>) unmarshaller.unmarshal(importFile);
// Get the data sheet reference
dataSheet = (DataSheetType) jaxbElement.getValue();
tableDefinitions = new ArrayList<TableDefinition>();
structureTypeDefn = null;
commandTypeDefn = null;
// Get the telemetry and command header argument column names for the application ID
// and the command function code. These are stored as project-level data fields
ccsdsAppID = fieldHandler.getFieldValue(CcddFieldHandler.getFieldProjectName(), InputDataType.XML_APP_ID);
ccsdsFuncCode = fieldHandler.getFieldValue(CcddFieldHandler.getFieldProjectName(), InputDataType.XML_FUNC_CODE);
// Step through each name space in the data sheet
for (NamespaceType namespace : dataSheet.getNamespace()) {
// Step through the interfaces
for (InterfaceDeclarationType intfcDecType : namespace.getDeclaredInterfaceSet().getInterface()) {
// Check if this interface contains a generic type set
if (intfcDecType.getGenericTypeSet() != null && !intfcDecType.getGenericTypeSet().getGenericType().isEmpty()) {
// Step through each generic type data
for (GenericTypeType genType : intfcDecType.getGenericTypeSet().getGenericType()) {
// column name indicator
if (genType.getName().equals(ArgumentColumnName.APP_ID.getAncillaryName())) {
// Store the item value as the application ID argument column name.
// Note that this overrides the value extracted from the project
// data field
ccsdsAppID = genType.getBaseType();
} else // argument column name indicator
if (genType.getName().equals(ArgumentColumnName.FUNC_CODE.getAncillaryName())) {
// Store the item value as the command function code argument
// column name. Note that this overrides the value extracted from
// the project data field
ccsdsFuncCode = genType.getBaseType();
}
// project or the import file
if (ccsdsAppID == null) {
// Use the default application ID argument column name
ccsdsAppID = ArgumentColumnName.APP_ID.getDefaultArgColName();
}
// the project or the import file
if (ccsdsFuncCode == null) {
// Use the default command function code argument column name
ccsdsFuncCode = ArgumentColumnName.FUNC_CODE.getDefaultArgColName();
}
}
}
}
}
// Create the table type definitions for any new structure and command tables
createTableTypeDefinitions(importType);
// Check if at least one structure or command table needs to be built
if (structureTypeDefn != null || commandTypeDefn != null) {
// Step through each space system
for (NamespaceType namespace : dataSheet.getNamespace()) {
// Recursively step through the EDS-formatted data and extract the telemetry
// and command information
unbuildSpaceSystems(namespace, importType);
// Check if only the data from the first table is to be read
if (importType == ImportType.FIRST_DATA_ONLY) {
// Stop reading table definitions
break;
}
}
}
} catch (JAXBException je) {
// Inform the user that the database import failed
new CcddDialogHandler().showMessageDialog(parent, "<html><b>Cannot import EDS XML from file<br>'</b>" + importFile.getAbsolutePath() + "<b>'; cause '" + je.getMessage() + "'", "File Error", JOptionPane.ERROR_MESSAGE, DialogOption.OK_OPTION);
}
}
use of org.ccsds.schema.sois.seds.NamespaceType in project CCDD by nasa.
the class CcddEDSHandler method createTableTypeDefinitions.
/**
********************************************************************************************
* Scan the import file in order to determine if any structure or command tables exist. If so,
* create the structure and/or command table type definition that's used to build the new
* tables
*
* @param importFileName
* import file name
********************************************************************************************
*/
private void createTableTypeDefinitions(ImportType importType) {
isTelemetry = false;
isCommand = false;
maxNumArguments = 1;
// Step through each space system
for (NamespaceType namespace : dataSheet.getNamespace()) {
// Recursively step through the EDS-formatted data and extract the telemetry and
// command information
findMetaData(namespace, importType);
}
// Check if a structure table is defined in the import file
if (isTelemetry) {
String typeName = "EDS Structure";
int sequence = 2;
// Continue to check while a table type with this name exists
while (tableTypeHandler.getTypeDefinition(typeName) != null) {
// Alter the name so that there isn't a duplicate
typeName = "EDS Structure " + sequence;
sequence++;
}
// Create the EDS structure table type using the default structure columns
structureTypeDefn = tableTypeHandler.createTypeDefinition(typeName, DefaultColumn.getDefaultColumnDefinitions(TYPE_STRUCTURE), "EDS import structure table type");
// Get the current number of columns defined for the structure table type. The new
// columns are appended to the existing ones
int columnIndex = structureTypeDefn.getColumnCountDatabase();
// Add the minimum and maximum value columns
structureTypeDefn.addColumn(columnIndex, structureTypeDefn.getColumnNameDatabase(COL_MINIMUM, InputDataType.MINIMUM), COL_MINIMUM, "Minimum value", InputDataType.MINIMUM, false, false, false, true);
structureTypeDefn.addColumn(columnIndex + 1, structureTypeDefn.getColumnNameDatabase(COL_MAXIMUM, InputDataType.MAXIMUM), COL_MAXIMUM, "Maximum value", InputDataType.MAXIMUM, false, false, false, true);
// Get structure table column indices
variableNameIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.VARIABLE));
dataTypeIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT));
arraySizeIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.ARRAY_INDEX));
bitLengthIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.BIT_LENGTH));
enumerationIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.ENUMERATION));
minimumIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.MINIMUM));
maximumIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.MAXIMUM));
descriptionIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.DESCRIPTION));
unitsIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.UNITS));
// Get the number of columns defined in the structure table type
numStructureColumns = structureTypeDefn.getColumnCountVisible();
}
// Check if a command table is defined in the import file
if (isCommand) {
String typeName = "EDS Command";
int sequence = 2;
// Continue to check while a table type with this name exists
while (tableTypeHandler.getTypeDefinition(typeName) != null) {
// Alter the name so that there isn't a duplicate
typeName = "EDS Command " + sequence;
sequence++;
}
// Create the EDS command table type using the default command columns
commandTypeDefn = tableTypeHandler.createTypeDefinition(typeName, DefaultColumn.getDefaultColumnDefinitions(TYPE_COMMAND), "EDS import command table type");
// Step through each additional command argument column set
for (int argIndex = 2; argIndex < maxNumArguments; argIndex++) {
// Add the default columns for this command argument
commandTypeDefn.addCommandArgumentColumns(argIndex);
}
// Get the list containing the associated column indices for each argument grouping
commandArguments = commandTypeDefn.getAssociatedCommandArgumentColumns(true);
// Get the command table column indices
commandNameIndex = CcddTableTypeHandler.getVisibleColumnIndex(commandTypeDefn.getColumnIndexByInputType(InputDataType.COMMAND_NAME));
commandCodeIndex = CcddTableTypeHandler.getVisibleColumnIndex(commandTypeDefn.getColumnIndexByInputType(InputDataType.COMMAND_CODE));
cmdDescriptionIndex = CcddTableTypeHandler.getVisibleColumnIndex(commandTypeDefn.getColumnIndexByInputType(InputDataType.DESCRIPTION));
// Get the number of columns defined in the command table type
numCommandColumns = commandTypeDefn.getColumnCountVisible();
}
}
use of org.ccsds.schema.sois.seds.NamespaceType in project CCDD by nasa.
the class CcddEDSHandler method addNamespace.
/**
********************************************************************************************
* Create a new name space as a child within the specified name space. If the specified name
* space is null then this is the root data sheet
*
* @param systemPath
* system name; null or blank if no system
*
* @param namespaceName
* name for the new name space
*
* @param description
* data sheet description
*
* @return Reference to the new name space
********************************************************************************************
*/
private NamespaceType addNamespace(String systemPath, String namespaceName, String description) {
// Create the new name space and set the name attribute
NamespaceType childSpace = factory.createNamespaceType();
// Set the name space name
childSpace.setName((systemPath != null ? systemPath + "/" : "") + namespaceName);
// Check if a description is provided
if (description != null && !description.isEmpty()) {
// Set the description attribute
childSpace.setLongDescription(description);
}
// Create an interface set for the name space
childSpace.setDeclaredInterfaceSet(factory.createInterfaceDeclarationSetType());
// Add the new names space
dataSheet.getNamespace().add(childSpace);
return childSpace;
}
use of org.ccsds.schema.sois.seds.NamespaceType in project CCDD by nasa.
the class CcddEDSHandler method searchNamespacesForName.
/**
********************************************************************************************
* Search for the name space with the same name as the search name
*
* @param systemPath
* system name; null or blank if no system
*
* @param namespaceName
* name of the name space to search for within the name space hierarchy
*
* @return Reference to the name space with the same name as the search name; null if no name
* space name matches the search name
********************************************************************************************
*/
private NamespaceType searchNamespacesForName(String systemPath, String namespaceName) {
NamespaceType foundNamespace = null;
// Prepend the system path, if present
namespaceName = (systemPath != null ? systemPath + "/" : "") + namespaceName;
// Step through each name space
for (NamespaceType namespace : dataSheet.getNamespace()) {
// Check if the current name space's name matches the search name
if (namespace.getName().equals(namespaceName)) {
// Store the reference to the matching name space
foundNamespace = namespace;
break;
}
}
return foundNamespace;
}
use of org.ccsds.schema.sois.seds.NamespaceType in project CCDD by nasa.
the class CcddEDSHandler method buildNamespaces.
/**
********************************************************************************************
* Build the name spaces for the list of tables specified
*
* @param tableNames
* array of table names
*
* @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
********************************************************************************************
*/
private void buildNamespaces(String[] tableNames, boolean includeVariablePaths, CcddVariableSizeAndConversionHandler variableHandler, String[] separators) {
// Build the data field information for all fields
fieldHandler.buildFieldInformation(null);
// Get the names of the tables representing the CCSDS telemetry and command headers
tlmHeaderTable = fieldHandler.getFieldValue(CcddFieldHandler.getFieldProjectName(), InputDataType.XML_TLM_HDR);
cmdHeaderTable = fieldHandler.getFieldValue(CcddFieldHandler.getFieldProjectName(), InputDataType.XML_CMD_HDR);
// Get the command header argument names for the application ID and the command function
// code. These are stored as project-level data fields
String ccsdsAppID = fieldHandler.getFieldValue(CcddFieldHandler.getFieldProjectName(), InputDataType.XML_APP_ID);
String ccsdsFuncCode = fieldHandler.getFieldValue(CcddFieldHandler.getFieldProjectName(), InputDataType.XML_FUNC_CODE);
// Step through each table name
for (String tableName : tableNames) {
// Check if this is a child (instance) table
if (!TableInformation.isPrototype(tableName)) {
// Get the prototype of the instance table. Only prototypes of the tables are
// used to create the space systems
tableName = TableInformation.getPrototypeName(tableName);
// Get the name of the system to which this table belongs from the table's
// system path data field (if present)
String systemPath = cleanSystemPath(fieldHandler.getFieldValue(tableName, InputDataType.SYSTEM_PATH));
// created
if (searchNamespacesForName(systemPath, tableName) != null) {
// Skip this table since it's space system has already been created
continue;
}
}
// Get the information from the database for the specified table
TableInformation tableInfo = dbTable.loadTableData(tableName, true, false, true, parent);
// Check if the table's data successfully loaded
if (!tableInfo.isErrorFlag()) {
// Get the table type and from the type get the type definition. The type
// definition can be a global parameter since if the table represents a structure,
// then all of its children are also structures, and if the table represents
// commands or other table type then it is processed within this nest level
typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
// Check if the table type represents a structure or command
if (typeDefn != null && (typeDefn.isStructure() || typeDefn.isCommand())) {
// Replace all macro names with their corresponding values
tableInfo.setData(macroHandler.replaceAllMacros(tableInfo.getData()));
// Get the application ID data field value, if present
String applicationID = fieldHandler.getFieldValue(tableName, InputDataType.MESSAGE_ID);
// Get the name of the system to which this table belongs from the table's
// system path data field (if present)
String systemPath = cleanSystemPath(fieldHandler.getFieldValue(tableName, InputDataType.SYSTEM_PATH));
// Add the name space
NamespaceType namespace = addNamespace(systemPath, tableName, tableInfo.getDescription());
// Check if this is a structure table
if (typeDefn.isStructure()) {
// Get the default column indices
int varColumn = typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE);
int typeColumn = typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT);
int sizeColumn = typeDefn.getColumnIndexByInputType(InputDataType.ARRAY_INDEX);
int bitColumn = typeDefn.getColumnIndexByInputType(InputDataType.BIT_LENGTH);
int enumColumn = typeDefn.getColumnIndexByInputType(InputDataType.ENUMERATION);
int descColumn = typeDefn.getColumnIndexByInputType(InputDataType.DESCRIPTION);
int unitsColumn = typeDefn.getColumnIndexByInputType(InputDataType.UNITS);
int minColumn = typeDefn.getColumnIndexByInputType(InputDataType.MINIMUM);
int maxColumn = typeDefn.getColumnIndexByInputType(InputDataType.MAXIMUM);
// Set the flag to indicate if this is the telemetry header table
boolean isTlmHeaderTable = tableName.equals(tlmHeaderTable);
// Check if this is the telemetry header table
if (isTlmHeaderTable) {
// Store the telemetry header's path
tlmHeaderPath = systemPath;
}
// Export the parameter container for this structure
addParameterContainer(namespace, tableInfo, varColumn, typeColumn, sizeColumn, minColumn, maxColumn, isTlmHeaderTable, applicationID, ccsdsAppID);
// Step through each row in the structure table
for (String[] rowData : tableInfo.getData()) {
// used to define the array)
if (!ArrayVariable.isArrayMember(rowData[varColumn])) {
// Add the variable to the data sheet
addParameter(namespace, rowData[varColumn], rowData[typeColumn], rowData[sizeColumn], rowData[bitColumn], (enumColumn != -1 && !rowData[enumColumn].isEmpty() ? rowData[enumColumn] : null), (unitsColumn != -1 && !rowData[unitsColumn].isEmpty() ? rowData[unitsColumn] : null), (descColumn != -1 && !rowData[descColumn].isEmpty() ? rowData[descColumn] : null), (dataTypeHandler.isString(rowData[typeColumn]) && !rowData[sizeColumn].isEmpty() ? Integer.valueOf(rowData[sizeColumn].replaceAll("^.*(\\d+)$", "$1")) : 1));
}
}
} else // This is a command table
{
// Check if this is the command header table
if (tableName.equals(cmdHeaderTable)) {
// Store the command header's path
cmdHeaderPath = systemPath;
}
// Add the command(s) from this table to the data sheet
addNamespaceCommands(namespace, tableInfo, tableName.equals(cmdHeaderTable), applicationID, ccsdsAppID, ccsdsFuncCode);
}
}
}
}
// Step through each table name
for (String tableName : tableNames) {
// Get the prototype for the child
tableName = TableInformation.getPrototypeName(tableName);
// Get the name of the system to which this table belongs from the table's
// system path data field (if present)
String systemPath = cleanSystemPath(fieldHandler.getFieldValue(tableName, InputDataType.SYSTEM_PATH));
// Get the name space for this table
NamespaceType namespace = searchNamespacesForName(systemPath, tableName);
// Check if the table's name space exists
if (namespace != null) {
// Step through the each parameter type
for (RootDataType type : namespace.getDataTypeSet().getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
// base type it's a reference to a child structure
if (type instanceof ContainerDataType && ((ContainerDataType) type).getBaseType() != null) {
// Get the base type, which has the name space path for the child structure
String typeName = ((ContainerDataType) type).getBaseType();
// Get the beginning of the last portion of the path, which is the
// structure data type
int index = ((ContainerDataType) type).getBaseType().lastIndexOf("/");
// Check if the structure data type exists
if (index != -1) {
// Remove the structure data type, leaving only the name space path to
// the child structure's definition
typeName = typeName.substring(0, index);
}
// Get the name space for the child structure's definition
NamespaceType nmspc = searchNamespacesForName(null, typeName);
// Check if the name space exists
if (nmspc != null) {
DataTypeSetType dataTypeSet = nmspc.getDataTypeSet();
// Check if the child's data type set exists
if (dataTypeSet != null && !dataTypeSet.getArrayDataTypeOrBinaryDataTypeOrBooleanDataType().isEmpty()) {
// Step through each data type
for (RootDataType rootData : dataTypeSet.getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
// Check if this is the container with the structure's members
if (rootData instanceof ContainerDataType && rootData.getName().equals(type.getName())) {
// Set the parent structure table's list of members of the
// child structure using the child structure definition's
// list, and stop searching
((ContainerDataType) type).setEntryList(((ContainerDataType) rootData).getEntryList());
break;
}
}
}
}
}
}
}
}
}
Aggregations