Package ghidra.framework.data

# Class DomainObjectAdapter

java.lang.Object
ghidra.framework.data.DomainObjectAdapter

All Implemented Interfaces:
  `DomainObject`

Direct Known Subclasses:
  `DomainObjectAdapterDB`

public abstract class DomainObjectAdapter extends Object implements DomainObject
An abstract class that provides default behavior for DomainObject(s), specifically it handles listeners and change status; the derived class must provide the getDescription() method.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected boolean`
  `changed`
  `protected Map<EventQueueID,ghidra.framework.data.DomainObjectChangeSupport>`
  `changeSupportMap`
  `protected static final String`
  `DEFAULT_NAME`
  `protected Lock`
  `lock`
  `protected Map<String,String>`
  `metadata`
  `protected String`
  `name`
  `protected boolean`
  `temporary`

  ### Fields inherited from interface ghidra.framework.model.DomainObject

  `DO_DOMAIN_FILE_CHANGED, DO_OBJECT_CLOSED, DO_OBJECT_ERROR, DO_OBJECT_RENAMED, DO_OBJECT_RESTORED, DO_OBJECT_SAVED, DO_PROPERTY_CHANGED, undoLock`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `DomainObjectAdapter(String name, int timeInterval, Object consumer)`
  Construct a new DomainObjectAdapter.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addCloseListener(DomainObjectClosedListener listener)`
  Adds a listener that will be notified when this DomainObject is closed.
  `boolean`
  `addConsumer(Object consumer)`
  Adds the given object as a consumer.
  `void`
  `addDomainFileListener(DomainObjectFileListener listener)`
  Adds a listener that will be notified when this DomainFile associated with this DomainObject changes, such as when a 'Save As' action occurs.
  `void`
  `addListener(DomainObjectListener l)`
  Adds a listener for this object.
  `void`
  `checkExclusiveAccess()`
  `protected void`
  `close()`
  `EventQueueID`
  `createPrivateEventQueue(DomainObjectListener listener, int maxDelay)`
  Creates a private event queue that can be flushed independently from the main event queue.
  `protected void`
  `fatalErrorOccurred(Exception e)`
  `void`
  `fireEvent(DomainObjectChangeRecord ev)`
  Fires the specified event.
  `void`
  `flushEvents()`
  Makes sure all pending domainEvents have been sent.
  `void`
  `flushPrivateEventQueue(EventQueueID id)`
  Flush events from the specified event queue.
  `protected FileSystem`
  `getAssociatedUserFilesystem()`
  Returns the hidden user-filesystem associated with this objects domain file, or null if unknown.
  `boolean`
  `getChangeStatus()`
  Return "changed" status
  `ArrayList<Object>`
  `getConsumerList()`
  Returns the list of consumers on this domainObject
  `static ContentHandler<?>`
  `getContentHandler(DomainObject dobj)`
  Get the `ContentHandler` associated with the specified domain object
  `static ContentHandler<?>`
  `getContentHandler(Class<? extends DomainObject> dobjClass)`
  Get the `ContentHandler` associated with the specified domain object class
  `static ContentHandler<?>`
  `getContentHandler(String contentType)`
  Get the `ContentHandler` associated with the specified content-type.
  `static Set<ContentHandler<?>>`
  `getContentHandlers()`
  Get all `ContentHandler`s
  `abstract String`
  `getDescription()`
  Returns a word or short phrase that best describes or categorizes the object in terms that a user will understand.
  `DomainFile`
  `getDomainFile()`
  Get the domain file for this domain object.
  `Lock`
  `getLock()`
  `Map<String,String>`
  `getMetadata()`
  Returns a map containing all the stored metadata associated with this domain object.
  `long`
  `getModificationNumber()`
  Returns a long value that gets incremented every time a change, undo, or redo takes place.
  `String`
  `getName()`
  Get the name of this domain object.
  `boolean`
  `hasExclusiveAccess()`
  Returns true if the user has exclusive access to the domain object.
  `void`
  `invalidate()`
  Invalidates any caching in a program and generate a `DomainObjectEvent.RESTORED` event.
  `boolean`
  `isChanged()`
  Returns whether the object has changed.
  `boolean`
  `isSendingEvents()`
  Returns true if this object is sending out events as it is changed.
  `boolean`
  `isTemporary()`
  Returns true if this object has been marked as Temporary.
  `boolean`
  `isUsedBy(Object consumer)`
  Returns true if the given consumer is using this object.
  `void`
  `release(Object consumer)`
  Notify the domain object that the specified consumer is no longer using it.
  `void`
  `removeCloseListener(DomainObjectClosedListener listener)`
  Removes the given close listener.
  `void`
  `removeDomainFileListener(DomainObjectFileListener listener)`
  Removes the given DomainObjectFileListener listener.
  `void`
  `removeListener(DomainObjectListener l)`
  Remove the listener for this object.
  `boolean`
  `removePrivateEventQueue(EventQueueID id)`
  Removes the specified private event queue
  `protected void`
  `setChanged(boolean state)`
  `protected void`
  `setDomainFile(DomainFile df)`
  Set the `DomainFile` associated with this instance.
  `void`
  `setEventsEnabled(boolean v)`
  If true, domain object change events are sent.
  `void`
  `setName(String newName)`
  Set the name for this domain object.
  `void`
  `setTemporary(boolean state)`
  Set the temporary state of this object.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface ghidra.framework.model.DomainObject

  `addSynchronizedDomainObject, addTransactionListener, canLock, canRedo, canSave, canUndo, clearUndo, endTransaction, forceLock, getAllRedoNames, getAllUndoNames, getCurrentTransactionInfo, getOptions, getOptionsNames, getRedoName, getSynchronizedDomainObjects, getUndoName, hasTerminatedTransaction, isChangeable, isClosed, isLocked, lock, openTransaction, redo, releaseSynchronizedDomainObject, removeTransactionListener, save, saveToPackedFile, startTransaction, startTransaction, undo, unlock, withTransaction, withTransaction`

- ## Field Details

  - ### DEFAULT_NAME

    protected static final String DEFAULT_NAME
    See Also:
      - Constant Field Values

  - ### name

    protected String name

  - ### changeSupportMap

    protected Map<EventQueueID,ghidra.framework.data.DomainObjectChangeSupport> changeSupportMap

  - ### metadata

    protected Map<String,String> metadata

  - ### changed

    protected boolean changed

  - ### temporary

    protected boolean temporary

  - ### lock

    protected Lock lock

- ## Constructor Details

  - ### DomainObjectAdapter

    protected DomainObjectAdapter(String name, int timeInterval, Object consumer)
    Construct a new DomainObjectAdapter. If construction of this object fails, be sure to release with consumer.
    Parameters:
      `name` - name of the object
      `timeInterval` - the time (in milliseconds) to wait before the event queue is flushed. If a new event comes in before the time expires the timer is reset.
      `consumer` - the object that created this domain object

- ## Method Details

  - ### invalidate

    public void invalidate()
    Invalidates any caching in a program and generate a `DomainObjectEvent.RESTORED` event. NOTE: Over-using this method can adversely affect system performance.

  - ### release

    public void release(Object consumer)
    Description copied from interface: `DomainObject`
    Notify the domain object that the specified consumer is no longer using it. When the last consumer invokes this method, the domain object will be closed and will become invalid.
    Specified by:
      `release` in interface `DomainObject`
    Parameters:
      `consumer` - the consumer (e.g., tool, plugin, etc) of the domain object previously established with the addConsumer method.

  - ### getLock

    public Lock getLock()

  - ### getDomainFile

    public DomainFile getDomainFile()
    Description copied from interface: `DomainObject`
    Get the domain file for this domain object.
    Specified by:
      `getDomainFile` in interface `DomainObject`
    Returns:
      the associated domain file

  - ### getAssociatedUserFilesystem

    protected FileSystem getAssociatedUserFilesystem()
    Returns the hidden user-filesystem associated with this objects domain file, or null if unknown.
    Returns:
      user data file system

  - ### getName

    public String getName()
    Description copied from interface: `DomainObject`
    Get the name of this domain object.
    Specified by:
      `getName` in interface `DomainObject`
    Returns:
      the name

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### setName

    public void setName(String newName)
    Description copied from interface: `DomainObject`
    Set the name for this domain object.
    Specified by:
      `setName` in interface `DomainObject`
    Parameters:
      `newName` - object name

  - ### isChanged

    public boolean isChanged()
    Description copied from interface: `DomainObject`
    Returns whether the object has changed.
    Specified by:
      `isChanged` in interface `DomainObject`
    Returns:
      whether the object has changed.

  - ### setTemporary

    public void setTemporary(boolean state)
    Description copied from interface: `DomainObject`
    Set the temporary state of this object. If this object is temporary, the isChanged() method will always return false. The default temporary state is false.
    Specified by:
      `setTemporary` in interface `DomainObject`
    Parameters:
      `state` - if true object is marked as temporary

  - ### isTemporary

    public boolean isTemporary()
    Description copied from interface: `DomainObject`
    Returns true if this object has been marked as Temporary.
    Specified by:
      `isTemporary` in interface `DomainObject`
    Returns:
      true if this object has been marked as Temporary.

  - ### setDomainFile

    protected void setDomainFile(DomainFile df) throws DomainObjectException
    Set the `DomainFile` associated with this instance.
    Parameters:
      `df` - domain file
    Throws:
      `DomainObjectException` - if a severe failure occurs during the operation.

  - ### close

    protected void close()

  - ### flushEvents

    public void flushEvents()
    Description copied from interface: `DomainObject`
    Makes sure all pending domainEvents have been sent.
    Specified by:
      `flushEvents` in interface `DomainObject`

  - ### getChangeStatus

    public boolean getChangeStatus()
    Return "changed" status
    Returns:
      true if this object has changed

  - ### addListener

    public void addListener(DomainObjectListener l)
    Description copied from interface: `DomainObject`
    Adds a listener for this object.
    Specified by:
      `addListener` in interface `DomainObject`
    Parameters:
      `l` - listener notified when any change occurs to this domain object

  - ### removeListener

    public void removeListener(DomainObjectListener l)
    Description copied from interface: `DomainObject`
    Remove the listener for this object.
    Specified by:
      `removeListener` in interface `DomainObject`
    Parameters:
      `l` - listener

  - ### addCloseListener

    public void addCloseListener(DomainObjectClosedListener listener)
    Description copied from interface: `DomainObject`
    Adds a listener that will be notified when this DomainObject is closed. This is meant for clients to have a chance to cleanup, such as reference removal.
    Specified by:
      `addCloseListener` in interface `DomainObject`
    Parameters:
      `listener` - the reference to add

  - ### removeCloseListener

    public void removeCloseListener(DomainObjectClosedListener listener)
    Description copied from interface: `DomainObject`
    Removes the given close listener.
    Specified by:
      `removeCloseListener` in interface `DomainObject`
    Parameters:
      `listener` - the listener to remove.

  - ### addDomainFileListener

    public void addDomainFileListener(DomainObjectFileListener listener)
    Description copied from interface: `DomainObject`
    Adds a listener that will be notified when this DomainFile associated with this DomainObject changes, such as when a 'Save As' action occurs. Unlike DomainObject events, these notifications are not buffered and happen immediately when the DomainFile is changed.
    Specified by:
      `addDomainFileListener` in interface `DomainObject`
    Parameters:
      `listener` - the listener to be notified when the associated DomainFile changes

  - ### removeDomainFileListener

    public void removeDomainFileListener(DomainObjectFileListener listener)
    Description copied from interface: `DomainObject`
    Removes the given DomainObjectFileListener listener.
    Specified by:
      `removeDomainFileListener` in interface `DomainObject`
    Parameters:
      `listener` - the listener to remove.

  - ### createPrivateEventQueue

    public EventQueueID createPrivateEventQueue(DomainObjectListener listener, int maxDelay)
    Description copied from interface: `DomainObject`
    Creates a private event queue that can be flushed independently from the main event queue.
    Specified by:
      `createPrivateEventQueue` in interface `DomainObject`
    Parameters:
      `listener` - the listener to be notified of domain object events.
      `maxDelay` - the time interval (in milliseconds) used to buffer events.
    Returns:
      a unique identifier for this private queue.

  - ### removePrivateEventQueue

    public boolean removePrivateEventQueue(EventQueueID id)
    Description copied from interface: `DomainObject`
    Removes the specified private event queue
    Specified by:
      `removePrivateEventQueue` in interface `DomainObject`
    Parameters:
      `id` - the id of the queue to remove.
    Returns:
      true if the id represents a valid queue that was removed.

  - ### flushPrivateEventQueue

    public void flushPrivateEventQueue(EventQueueID id)
    Description copied from interface: `DomainObject`
    Flush events from the specified event queue.
    Specified by:
      `flushPrivateEventQueue` in interface `DomainObject`
    Parameters:
      `id` - the id specifying the event queue to be flushed.

  - ### getDescription

    public abstract String getDescription()
    Description copied from interface: `DomainObject`
    Returns a word or short phrase that best describes or categorizes the object in terms that a user will understand.
    Specified by:
      `getDescription` in interface `DomainObject`
    Returns:
      the description

  - ### fireEvent

    public void fireEvent(DomainObjectChangeRecord ev)
    Fires the specified event.
    Parameters:
      `ev` - event to fire

  - ### setEventsEnabled

    public void setEventsEnabled(boolean v)
    Description copied from interface: `DomainObject`
    If true, domain object change events are sent. If false, no events are sent.

    NOTE: disabling events could cause plugins to be out of sync!

    NOTE: when re-enabling events, an event will be sent to the system to signal that every listener should update.

    Specified by:
      `setEventsEnabled` in interface `DomainObject`
    Parameters:
      `v` - true means to enable events

  - ### isSendingEvents

    public boolean isSendingEvents()
    Description copied from interface: `DomainObject`
    Returns true if this object is sending out events as it is changed. The default is true. You can change this value by calling `DomainObject.setEventsEnabled(boolean)`.
    Specified by:
      `isSendingEvents` in interface `DomainObject`
    Returns:
      true if sending events
    See Also:
      - `DomainObject.setEventsEnabled(boolean)`

  - ### hasExclusiveAccess

    public boolean hasExclusiveAccess()
    Description copied from interface: `DomainObject`
    Returns true if the user has exclusive access to the domain object. Exclusive access means either the object is not shared or the user has an exclusive checkout on the object.
    Specified by:
      `hasExclusiveAccess` in interface `DomainObject`
    Returns:
      true if has exclusive access

  - ### checkExclusiveAccess

    public void checkExclusiveAccess() throws LockException
    Throws:
      `LockException`

  - ### setChanged

    protected void setChanged(boolean state)

  - ### addConsumer

    public boolean addConsumer(Object consumer)
    Description copied from interface: `DomainObject`
    Adds the given object as a consumer. The release method must be invoked with this same consumer instance when this domain object is no longer in-use.
    Specified by:
      `addConsumer` in interface `DomainObject`
    Parameters:
      `consumer` - domain object consumer
    Returns:
      false if this domain object has already been closed

  - ### isUsedBy

    public boolean isUsedBy(Object consumer)
    Returns true if the given consumer is using this object.
    Specified by:
      `isUsedBy` in interface `DomainObject`
    Parameters:
      `consumer` - the object to test to see if it is a consumer of this domain object.
    Returns:
      true if the given consumer is using (has open) this domain object;

  - ### getConsumerList

    public ArrayList<Object> getConsumerList()
    Description copied from interface: `DomainObject`
    Returns the list of consumers on this domainObject
    Specified by:
      `getConsumerList` in interface `DomainObject`
    Returns:
      the list of consumers.

  - ### getContentHandler

    public static ContentHandler<?> getContentHandler(String contentType) throws IOException
    Get the `ContentHandler` associated with the specified content-type.
    Parameters:
      `contentType` - domain object content type
    Returns:
      content handler
    Throws:
      `IOException` - if no content handler can be found

  - ### getContentHandler

    public static ContentHandler<?> getContentHandler(Class<? extends DomainObject> dobjClass) throws IOException
    Get the `ContentHandler` associated with the specified domain object class
    Parameters:
      `dobjClass` - domain object class
    Returns:
      content handler
    Throws:
      `IOException` - if no content handler can be found

  - ### getContentHandler

    public static ContentHandler<?> getContentHandler(DomainObject dobj) throws IOException
    Get the `ContentHandler` associated with the specified domain object
    Parameters:
      `dobj` - domain object
    Returns:
      content handler
    Throws:
      `IOException` - if no content handler can be found

  - ### getContentHandlers

    public static Set<ContentHandler<?>> getContentHandlers()
    Get all `ContentHandler`s
    Returns:
      collection of content handlers

  - ### getMetadata

    public Map<String,String> getMetadata()
    Description copied from interface: `DomainObject`
    Returns a map containing all the stored metadata associated with this domain object. The map contains key,value pairs and are ordered by their insertion order.
    Specified by:
      `getMetadata` in interface `DomainObject`
    Returns:
      a map containing all the stored metadata associated with this domain object.

  - ### getModificationNumber

    public long getModificationNumber()
    Description copied from interface: `DomainObject`
    Returns a long value that gets incremented every time a change, undo, or redo takes place. Useful for implementing a lazy caching system.
    Specified by:
      `getModificationNumber` in interface `DomainObject`
    Returns:
      a long value that is incremented for every change to the program.

  - ### fatalErrorOccurred

    protected void fatalErrorOccurred(Exception e)