Class StandAloneDataTypeManager

java.lang.Object
ghidra.program.database.data.DataTypeManagerDB
ghidra.program.model.data.StandAloneDataTypeManager
All Implemented Interfaces:
DataTypeManager, Closeable, AutoCloseable
Direct Known Subclasses:
BuiltInDataTypeManager, FileDataTypeManager, ProjectDataTypeManager

public class StandAloneDataTypeManager extends DataTypeManagerDB implements Closeable
Basic implementation of the DataTypeManger interface
  • Field Details

    • name

      protected String name
  • Constructor Details

    • StandAloneDataTypeManager

      public StandAloneDataTypeManager(String rootName) throws RuntimeIOException
      Constructor for new temporary data-type manager using the default DataOrganization. Note that this manager does not support the save or saveAs operation.
      Parameters:
      rootName - Name of the root category.
      Throws:
      RuntimeIOException - if database error occurs during creation
    • StandAloneDataTypeManager

      public StandAloneDataTypeManager(String rootName, DataOrganization dataOrganzation) throws RuntimeIOException
      Constructor for new temporary data-type manager using a specified DataOrganization. Note that this manager does not support the save or saveAs operation.
      Parameters:
      rootName - Name of the root category.
      dataOrganzation - applicable data organization
      Throws:
      RuntimeIOException - if database error occurs during creation
    • StandAloneDataTypeManager

      protected StandAloneDataTypeManager(ResourceFile packedDbfile, OpenMode openMode, TaskMonitor monitor) throws IOException, CancelledException
      Constructor for a data-type manager backed by a packed database file. When opening for UPDATE an automatic upgrade will be performed if required.

      NOTE: logWarning() should be invoked immediately after instantiating a StandAloneDataTypeManager for an existing database after getName() and getPath() can be invoked safely. In addition, it may be appropriate to use check for warnings prior to use.

      Parameters:
      packedDbfile - packed datatype archive file (i.e., *.gdt resource).
      openMode - open mode CREATE, READ_ONLY or UPDATE
      monitor - the progress monitor
      Throws:
      IOException - a low-level IO error. This exception may also be thrown when a version error occurs (cause is VersionException).
      CancelledException - if task cancelled
    • StandAloneDataTypeManager

      protected StandAloneDataTypeManager(DBHandle handle, OpenMode openMode, ErrorHandler errHandler, Lock lock, TaskMonitor monitor) throws CancelledException, VersionException, IOException
      Constructor for a data-type manager using a specified DBHandle.
      NOTE: logWarning() should be invoked immediately after instantiating a StandAloneDataTypeManager for an existing database after getName() and getPath() can be invoked safely. In addition, it may be appropriate to use check for warnings prior to use.
      Parameters:
      handle - open database handle
      openMode - open mode CREATE, READ_ONLY or UPDATE
      errHandler - the database I/O error handler
      lock - the program synchronization lock
      monitor - the progress monitor
      Throws:
      CancelledException - if task cancelled
      VersionException - if the database does not match the expected version.
      IOException - if a database I/O error occurs.
  • Method Details

    • setImmutable

      protected void setImmutable()
      Set instance as immutable by disabling use of transactions. Attempts to start a transaction will result in a TerminatedTransactionException.
    • getWarning

      Get the StandAloneDataTypeManager.ArchiveWarning which may have occured immediately following instatiation of this StandAloneDataTypeManager. StandAloneDataTypeManager.ArchiveWarning.NONE will be returned if not warning condition.
      Returns:
      warning type.
    • getWarningDetail

      public Exception getWarningDetail()
      Returns:
      warning detail exception or null
    • getWarningMessage

      public String getWarningMessage(boolean includeDetails)
      Get a suitable warning message. See getWarning() for type and its severity level StandAloneDataTypeManager.ArchiveWarning.level().
      Parameters:
      includeDetails - if false simple message returned, otherwise more details are included.
      Returns:
      warning message or null if getWarning() is StandAloneDataTypeManager.ArchiveWarning.NONE.
    • logWarning

      protected void logWarning()
      Due to the supression of error and warning conditions during instantiation this method should be invoked at the end of instatiation when getName() and getPath() are ready to be invoked safely. Logging will be performed via Msg.
    • initializeOtherAdapters

      protected void initializeOtherAdapters(OpenMode openMode, TaskMonitor monitor) throws CancelledException, IOException, VersionException
      Description copied from class: DataTypeManagerDB
      Initialize other DB adapters after base implementation adapters has been initialized.
      Overrides:
      initializeOtherAdapters in class DataTypeManagerDB
      Parameters:
      openMode - the DB open mode
      monitor - the progress monitor
      Throws:
      CancelledException - if the user cancels an upgrade
      IOException - if a database IO error occurs.
      VersionException - if the database does not match the expected version.
    • handleDataOrganizationChange

      protected void handleDataOrganizationChange(OpenMode openMode, TaskMonitor monitor) throws LanguageVersionException, CancelledException, IOException
      Overrides:
      handleDataOrganizationChange in class DataTypeManagerDB
      Throws:
      LanguageVersionException
      CancelledException
      IOException
    • getProgramArchitectureSummary

      public String getProgramArchitectureSummary()
      Get the program architecture information which has been associated with this datatype manager. If DataTypeManagerDB.getProgramArchitecture() returns null this method may still return information if the program architecture was set on an archive and either isProgramArchitectureMissing() or isProgramArchitectureUpgradeRequired() returns true.
      Specified by:
      getProgramArchitectureSummary in interface DataTypeManager
      Overrides:
      getProgramArchitectureSummary in class DataTypeManagerDB
      Returns:
      program architecture summary if it has been set
    • isProgramArchitectureUpgradeRequired

      public boolean isProgramArchitectureUpgradeRequired()
      Indicates that an program architecture upgrade is required in order to constitute associated data. If true, the associated archive must be open for update to allow the upgrade to complete, or a new program architecture may be set/cleared if such an operation is supported.
      Returns:
      true if a program architecture upgrade is required, else false
    • isProgramArchitectureMissing

      public boolean isProgramArchitectureMissing()
      Indicates that a failure occured establishing the program architecture for the associated archive.
      Returns:
      true if a failure occured establishing the program architecture
    • clearProgramArchitecture

      public void clearProgramArchitecture(TaskMonitor monitor) throws CancelledException, IOException, LockException
      Clear the program architecture setting and all architecture-specific data from this archive. Archive will revert to using the default DataOrganization. Archive must be open for update for this method to be used.
      Parameters:
      monitor - task monitor
      Throws:
      CancelledException - if task cancelled. If thrown, this data type manager is no longer stable and should be closed without saving.
      IOException - if IO error occurs
      LockException - failure if exclusive access is required
      javax.help.UnsupportedOperationException - if architecture change is not permitted by implementation (e.g., BuiltInDataTypeManager).
    • setProgramArchitecture

      public void setProgramArchitecture(Language language, CompilerSpecID compilerSpecId, StandAloneDataTypeManager.LanguageUpdateOption updateOption, TaskMonitor monitor) throws CompilerSpecNotFoundException, LanguageNotFoundException, IOException, CancelledException, LockException, javax.help.UnsupportedOperationException, IncompatibleLanguageException
      Establish the program architecture for this datatype manager. The current setting can be determined from DataTypeManagerDB.getProgramArchitecture(). Archive must be open for update for this method to be used.
      Parameters:
      language - language
      compilerSpecId - compiler specification ID defined by the language.
      updateOption - indicates how variable storage data should be transitioned. If isProgramArchitectureMissing() is true and StandAloneDataTypeManager.LanguageUpdateOption.TRANSLATE specified, the translator will be based on whatever language version can be found. In this situation it may be best to force a StandAloneDataTypeManager.LanguageUpdateOption.CLEAR.
      monitor - task monitor (cancel not permitted to avoid corrupt state)
      Throws:
      CompilerSpecNotFoundException - if invalid compilerSpecId specified for language
      LanguageNotFoundException - if current language is not found (if required for data transition)
      IOException - if IO error occurs
      CancelledException - if task cancelled. If thrown, this data type manager is no longer stable and should be closed without saving.
      LockException - failure if exclusive access is required
      javax.help.UnsupportedOperationException - if architecture change is not permitted
      IncompatibleLanguageException - if translation requested but not possible due to incompatible language architectures
    • setProgramArchitecture

      protected void setProgramArchitecture(ProgramArchitecture programArchitecture, VariableStorageManager variableStorageMgr, boolean store, TaskMonitor monitor) throws IOException, CancelledException
      Set the architecture-specific details associated with a new datatype manager. This method is intended to be used during instantiation of derived implementations.
      Overrides:
      setProgramArchitecture in class DataTypeManagerDB
      Parameters:
      programArchitecture - program architecture details (required)
      variableStorageMgr - variable storage manager. Must be null.
      store - if true database update will occur and datatypes will be updated if any change to the data organization is detected (a stored copy may be used to detect this condition). This should never be passed as true if opened read-only. If true and no variable storage is specified it will be created.
      monitor - task monitor
      Throws:
      IOException - if IO error occurs
      CancelledException - if task cancelled
      javax.help.UnsupportedOperationException - if language was previously set
    • isArchitectureChangeAllowed

      protected boolean isArchitectureChangeAllowed()
      Determine if a program architecture change is permitted
      Returns:
      true if change allowed else false if disallowed
    • getName

      public String getName()
      Description copied from interface: DataTypeManager
      Returns this data type manager's name
      Specified by:
      getName in interface DataTypeManager
      Returns:
      the name
    • setName

      public void setName(String name) throws InvalidNameException
      Description copied from interface: DataTypeManager
      Sets this data type manager's name
      Specified by:
      setName in interface DataTypeManager
      Parameters:
      name - the new name
      Throws:
      InvalidNameException - if the given name is invalid (such as when null or empty)
    • initTransactionState

      protected void initTransactionState()
    • openTransaction

      public Transaction openTransaction(String description) throws IllegalStateException
      Description copied from interface: DataTypeManager
      Open new transaction. This should generally be done with a try-with-resources block:
       try (Transaction tx = dtm.openTransaction(description)) {
              // ... Do something
       }
       
      Specified by:
      openTransaction in interface DataTypeManager
      Parameters:
      description - a short description of the changes to be made.
      Returns:
      transaction object
      Throws:
      IllegalStateException - if this DataTypeManager has already been closed.
    • startTransaction

      public int startTransaction(String description)
      Description copied from interface: DataTypeManager
      Starts a transaction for making changes in this data type manager.
      Specified by:
      startTransaction in interface DataTypeManager
      Parameters:
      description - a short description of the changes to be made.
      Returns:
      the transaction ID
    • getTransactionCount

      protected int getTransactionCount()
      Get the number of active datatype manager transactions
      Returns:
      number of active datatype manager transactions
    • endTransaction

      public boolean endTransaction(int transactionID, boolean commit)
      Description copied from interface: DataTypeManager
      Ends the current transaction.

      NOTE: If multiple transactions are outstanding the full transaction will not be ended until all transactions have been ended. If any of the transactions indicate a false for commit the transaction will ultimately be rolled-back when the final transaction is ended.

      NOTE: Use of rollback (commit=false should be avoided unless absolutely neccessary since it will incur overhead to revert changes and may rollback multiple concurrent transactions if they exist.

      NOTE: If this manager is part of a larger DomainObject its transactions may become entangled with other transactions at a higher level. In such cases, use of the DomainObject transaction interface is preferred. The return value from this method cannot be relied on in such cases.

      Specified by:
      endTransaction in interface DataTypeManager
      Parameters:
      transactionID - id of the transaction to end
      commit - true if changes are committed, false if changes in transaction should be rolled back.
      Returns:
      true if this invocation was the final transaction and all changes were comitted.
    • undo

      public void undo()
    • redo

      public void redo()
    • clearUndo

      protected void clearUndo()
      Clear undo/redo stack.
      NOTE: It is important that this always be invoked following any save operation that compacts the checkpoints within the database BufferMgr.
    • canRedo

      public boolean canRedo()
      Determine if there is a transaction previously undone (see undo()) that can be redone (see redo()).
      Returns:
      true if there is a transaction previously undone that can be redone, else false
    • canUndo

      public boolean canUndo()
      Determine if there is a previous transaction that can be reverted/undone (see undo()).
      Returns:
      true if there is a previous transaction that can be reverted/undone, else false.
    • getRedoName

      public String getRedoName()
      Get the transaction name that is available for redo() (see canRedo()).
      Returns:
      transaction name that is available for redo() or empty String.
    • getUndoName

      public String getUndoName()
      Get the transaction name that is available for undo() (see canUndo()).
      Returns:
      transaction name that is available for undo() or empty String.
    • getAllUndoNames

      public List<String> getAllUndoNames()
      Get all transaction names that are available within the undo() stack.
      Returns:
      all transaction names that are available within the undo() stack.
    • getAllRedoNames

      public List<String> getAllRedoNames()
      Get all transaction names that are available within the redo() stack.
      Returns:
      all transaction names that are available within the redo() stack.
    • flushEvents

      public void flushEvents()
      Description copied from interface: DataTypeManager
      Force all pending notification events to be flushed
      Specified by:
      flushEvents in interface DataTypeManager
    • replaceDataTypesUsed

      protected void replaceDataTypesUsed(Map<Long,Long> dataTypeReplacementMap)
      Description copied from class: DataTypeManagerDB
      Allow extensions to perform any neccessary fixups to address all datatype replacements.
      Specified by:
      replaceDataTypesUsed in class DataTypeManagerDB
      Parameters:
      dataTypeReplacementMap - map of datatype replacements (oldID maps to replacementID).
    • deleteDataTypesUsed

      protected void deleteDataTypesUsed(Set<Long> deletedIds)
      Description copied from class: DataTypeManagerDB
      Allow extensions to perform any neccessary fixups for all datatype removals listed.
      Specified by:
      deleteDataTypesUsed in class DataTypeManagerDB
      Parameters:
      deletedIds - list of IDs for all datatypes which are getting removed.
    • close

      public void close()
      Description copied from interface: DataTypeManager
      Closes this dataType manager
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface DataTypeManager
      Overrides:
      close in class DataTypeManagerDB
    • finalize

      public void finalize()
      Overrides:
      finalize in class Object
    • getDomainFileID

      protected String getDomainFileID()
      Specified by:
      getDomainFileID in class DataTypeManagerDB
    • getPath

      public String getPath()
      Get the path name associated with the storage of this stand alone datatype manager.
      Specified by:
      getPath in class DataTypeManagerDB
      Returns:
      path name or null if not applicable
    • getType

      public ArchiveType getType()
      Description copied from interface: DataTypeManager
      Returns this manager's archive type
      Specified by:
      getType in interface DataTypeManager
      Returns:
      the type