Search in sources :

Example 1 with GenericTypeType

use of org.ccsds.schema.sois.seds.GenericTypeType 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);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) TableDefinition(CCDD.CcddClassesDataTable.TableDefinition) InterfaceDeclarationType(org.ccsds.schema.sois.seds.InterfaceDeclarationType) JAXBElement(javax.xml.bind.JAXBElement) GenericTypeType(org.ccsds.schema.sois.seds.GenericTypeType) NamespaceType(org.ccsds.schema.sois.seds.NamespaceType)

Aggregations

TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 GenericTypeType (org.ccsds.schema.sois.seds.GenericTypeType)1 InterfaceDeclarationType (org.ccsds.schema.sois.seds.InterfaceDeclarationType)1 NamespaceType (org.ccsds.schema.sois.seds.NamespaceType)1