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 java.lang.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 booleanchangedprotected java.util.Map<EventQueueID,ghidra.framework.data.DomainObjectChangeSupport>changeSupportMapprotected static java.lang.StringDEFAULT_NAMEprotected Locklockprotected java.util.Map<java.lang.String,java.lang.String>metadataprotected java.lang.Stringnameprotected booleantemporary-
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 protectedDomainObjectAdapter(java.lang.String name, int timeInterval, int bufsize, java.lang.Object consumer)Construct a new DomainObjectAdapter.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddCloseListener(DomainObjectClosedListener listener)Adds a listener that will be notified when this DomainObject is closed.booleanaddConsumer(java.lang.Object consumer)Adds the given object as a consumer.voidaddListener(DomainObjectListener l)Adds a listener for this object.voidcheckExclusiveAccess()protected voidclose()EventQueueIDcreatePrivateEventQueue(DomainObjectListener listener, int maxDelay)Creates a private event queue that can be flushed independently from the main event queue.protected voidfatalErrorOccurred(java.lang.Exception e)voidfireEvent(DomainObjectChangeRecord ev)Fires the specified event.voidflushEvents()Makes sure all pending domainEvents have been sent.voidflushPrivateEventQueue(EventQueueID id)Flush events from the specified event queue.protected FileSystemgetAssociatedUserFilesystem()Returns the hidden user-filesystem associated with this objects domain file, or null if unknown.booleangetChangeStatus()Return "changed" statusjava.util.ArrayList<java.lang.Object>getConsumerList()Returns the list of consumers on this domainObjectstatic ContentHandlergetContentHandler(DomainObject dobj)Get the ContentHandler associated with the specified domain objectabstract java.lang.StringgetDescription()Returns a word or short phrase that best describes or categorizes the object in terms that a user will understand.DomainFilegetDomainFile()Get the domain file for this domain object.LockgetLock()java.util.Map<java.lang.String,java.lang.String>getMetadata()Returns a map containing all the stored metadata associated with this domain object.longgetModificationNumber()Returns a long value that gets incremented every time a change, undo, or redo takes place.java.lang.StringgetName()Get the name of this domain object.booleanhasExclusiveAccess()Returns true if the user has exclusive access to the domain object.booleanisChanged()Returns whether the object has changed.booleanisSendingEvents()Returns true if this object is sending out events as it is changed.booleanisTemporary()Returns true if this object has been marked as Temporary.booleanisUsedBy(java.lang.Object consumer)Returns true if the given tool is using this object.voidrelease(java.lang.Object consumer)Notify the domain object that the specified consumer is no longer using it.voidremoveCloseListener(DomainObjectClosedListener listener)Removes the given close listener.voidremoveListener(DomainObjectListener l)Remove the listener for this object.booleanremovePrivateEventQueue(EventQueueID id)Removes the specified private event queueprotected voidsetChanged(boolean state)static voidsetDefaultContentClass(java.lang.Class<?> doClass)Set default content typeprotected voidsetDomainFile(DomainFile df)voidsetEventsEnabled(boolean v)If true, domain object change events are sent.voidsetName(java.lang.String newName)Set the name for this domain object.voidsetTemporary(boolean state)Set the temporary state of this object.java.lang.StringtoString()-
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
canLock, canSave, forceLock, getOptions, getOptionsNames, isChangeable, isClosed, isLocked, lock, save, saveToPackedFile, unlock
-
-
-
-
Field Detail
-
DEFAULT_NAME
protected static final java.lang.String DEFAULT_NAME
- See Also:
- Constant Field Values
-
name
protected java.lang.String name
-
changeSupportMap
protected java.util.Map<EventQueueID,ghidra.framework.data.DomainObjectChangeSupport> changeSupportMap
-
metadata
protected java.util.Map<java.lang.String,java.lang.String> metadata
-
changed
protected boolean changed
-
temporary
protected boolean temporary
-
lock
protected Lock lock
-
-
Constructor Detail
-
DomainObjectAdapter
protected DomainObjectAdapter(java.lang.String name, int timeInterval, int bufsize, java.lang.Object consumer)Construct a new DomainObjectAdapter. If construction of this object fails, be sure to release with consumer.- Parameters:
name- name of the objecttimeInterval- 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.bufsize- initial size of event bufferconsumer- the object that created this domain object
-
-
Method Detail
-
release
public void release(java.lang.Object consumer)
Description copied from interface:DomainObjectNotify 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:
releasein interfaceDomainObject- Parameters:
consumer- the consumer (e.g., tool, plugin, etc) of the domain object previously established with the addConsumer method.- See Also:
DomainObject.release(java.lang.Object)
-
getLock
public Lock getLock()
-
getDomainFile
public DomainFile getDomainFile()
Description copied from interface:DomainObjectGet the domain file for this domain object.- Specified by:
getDomainFilein interfaceDomainObject- Returns:
- the associated domain file
- See Also:
DomainObject.getDomainFile()
-
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 java.lang.String getName()
Description copied from interface:DomainObjectGet the name of this domain object.- Specified by:
getNamein interfaceDomainObject- Returns:
- the name
- See Also:
DomainObject.getName()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-
setName
public void setName(java.lang.String newName)
Description copied from interface:DomainObjectSet the name for this domain object.- Specified by:
setNamein interfaceDomainObject- Parameters:
newName- object name- See Also:
DomainObject.setName(java.lang.String)
-
isChanged
public boolean isChanged()
Description copied from interface:DomainObjectReturns whether the object has changed.- Specified by:
isChangedin interfaceDomainObject- Returns:
- whether the object has changed.
- See Also:
DomainObject.isChanged()
-
setTemporary
public void setTemporary(boolean state)
Description copied from interface:DomainObjectSet 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:
setTemporaryin interfaceDomainObject- Parameters:
state- if true object is marked as temporary- See Also:
DomainObject.setTemporary(boolean)
-
isTemporary
public boolean isTemporary()
Description copied from interface:DomainObjectReturns true if this object has been marked as Temporary.- Specified by:
isTemporaryin interfaceDomainObject- Returns:
- true if this object has been marked as Temporary.
- See Also:
DomainObject.isTemporary()
-
setDomainFile
protected void setDomainFile(DomainFile df)
-
close
protected void close()
-
flushEvents
public void flushEvents()
Description copied from interface:DomainObjectMakes sure all pending domainEvents have been sent.- Specified by:
flushEventsin interfaceDomainObject- See Also:
DomainObject.flushEvents()
-
getChangeStatus
public boolean getChangeStatus()
Return "changed" status- Returns:
- true if this object has changed
-
addListener
public void addListener(DomainObjectListener l)
Description copied from interface:DomainObjectAdds a listener for this object.- Specified by:
addListenerin interfaceDomainObject- Parameters:
l- listener notified when any change occurs to this domain object- See Also:
DomainObject.addListener(ghidra.framework.model.DomainObjectListener)
-
removeListener
public void removeListener(DomainObjectListener l)
Description copied from interface:DomainObjectRemove the listener for this object.- Specified by:
removeListenerin interfaceDomainObject- Parameters:
l- listener- See Also:
DomainObject.removeListener(ghidra.framework.model.DomainObjectListener)
-
addCloseListener
public void addCloseListener(DomainObjectClosedListener listener)
Description copied from interface:DomainObjectAdds 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:
addCloseListenerin interfaceDomainObject- Parameters:
listener- the reference to add
-
removeCloseListener
public void removeCloseListener(DomainObjectClosedListener listener)
Description copied from interface:DomainObjectRemoves the given close listener.- Specified by:
removeCloseListenerin interfaceDomainObject- Parameters:
listener- the listener to remove.
-
createPrivateEventQueue
public EventQueueID createPrivateEventQueue(DomainObjectListener listener, int maxDelay)
Description copied from interface:DomainObjectCreates a private event queue that can be flushed independently from the main event queue.- Specified by:
createPrivateEventQueuein interfaceDomainObject- 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:DomainObjectRemoves the specified private event queue- Specified by:
removePrivateEventQueuein interfaceDomainObject- 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:DomainObjectFlush events from the specified event queue.- Specified by:
flushPrivateEventQueuein interfaceDomainObject- Parameters:
id- the id specifying the event queue to be flushed.
-
getDescription
public abstract java.lang.String getDescription()
Description copied from interface:DomainObjectReturns a word or short phrase that best describes or categorizes the object in terms that a user will understand.- Specified by:
getDescriptionin interfaceDomainObject- Returns:
- the description
- See Also:
DomainObject.getDescription()
-
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:DomainObjectIf 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:
setEventsEnabledin interfaceDomainObject- Parameters:
v- true means to enable events- See Also:
DomainObject.setEventsEnabled(boolean)
-
isSendingEvents
public boolean isSendingEvents()
Description copied from interface:DomainObjectReturns true if this object is sending out events as it is changed. The default is true. You can change this value by callingDomainObject.setEventsEnabled(boolean).- Specified by:
isSendingEventsin interfaceDomainObject- Returns:
- true if sending events
- See Also:
DomainObject.setEventsEnabled(boolean)
-
hasExclusiveAccess
public boolean hasExclusiveAccess()
Description copied from interface:DomainObjectReturns 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:
hasExclusiveAccessin interfaceDomainObject- Returns:
- true if has exclusive access
- See Also:
DomainObject.hasExclusiveAccess()
-
checkExclusiveAccess
public void checkExclusiveAccess() throws LockException- Throws:
LockException
-
setChanged
protected void setChanged(boolean state)
-
addConsumer
public boolean addConsumer(java.lang.Object consumer)
Description copied from interface:DomainObjectAdds 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:
addConsumerin interfaceDomainObject- Parameters:
consumer- domain object consumer- Returns:
- false if this domain object has already been closed
- See Also:
DomainObject.addConsumer(java.lang.Object)
-
isUsedBy
public boolean isUsedBy(java.lang.Object consumer)
Returns true if the given tool is using this object.- Specified by:
isUsedByin interfaceDomainObject- 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 java.util.ArrayList<java.lang.Object> getConsumerList()
Description copied from interface:DomainObjectReturns the list of consumers on this domainObject- Specified by:
getConsumerListin interfaceDomainObject- Returns:
- the list of consumers.
-
setDefaultContentClass
public static void setDefaultContentClass(java.lang.Class<?> doClass)
Set default content type- Parameters:
doClass- default domain object implementation
-
getContentHandler
public static ContentHandler getContentHandler(DomainObject dobj) throws java.io.IOException
Get the ContentHandler associated with the specified domain object- Parameters:
dobj- domain object- Returns:
- content handler
- Throws:
java.io.IOException
-
getMetadata
public java.util.Map<java.lang.String,java.lang.String> getMetadata()
Description copied from interface:DomainObjectReturns 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:
getMetadatain interfaceDomainObject- Returns:
- a map containing all the stored metadata associated with this domain object.
-
getModificationNumber
public long getModificationNumber()
Description copied from interface:DomainObjectReturns a long value that gets incremented every time a change, undo, or redo takes place. Useful for implementing a lazy caching system.- Specified by:
getModificationNumberin interfaceDomainObject- Returns:
- a long value that is incremented for every change to the program.
-
fatalErrorOccurred
protected void fatalErrorOccurred(java.lang.Exception e)
-
-