Package ghidra.app.util.opinion
Class Loaded<T extends DomainObject>
java.lang.Object
ghidra.app.util.opinion.Loaded<T>
- Type Parameters:
T- The type ofDomainObjectthat was loaded
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
LoadedOpen
A loaded
DomainObject produced by a Loader. In addition to storing the loaded
DomainObject, it also stores the Loader's desired name and project folder path
for the loaded DomainObject, should it get saved to a project.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidSafely applies the given operation to the loadedDomainObjectwithout the need to worry about resource managementbooleanSafely tests the given predicate on the loadedDomainObjectwithout the need to worry about resource managementvoidclose()Closes thisLoadedDomainObjectand releases the reference on the object consuming it.Deprecated, for removal: This API element is subject to removal in a future version.getDomainObject(Object consumer) Gets the loadedDomainObject.Class<? extends DomainObject> Gets the loadedDomainObject's typegetName()Gets the name of the loadedDomainObject.Gets theProjectthis will get saved to during asave(TaskMonitor)operationGets the project folder path this will get saved to during asave(TaskMonitor)operation.voidDeprecated, for removal: This API element is subject to removal in a future version.Useclose()insteadsave(TaskMonitor monitor) Saves the loadedDomainObjectto the givenProjectat this object's project folder path, using this object's name.voidsetProjectFolderPath(String projectRootPath) Sets the project folder path this will get saved to during asave(TaskMonitor)operation.toString()
-
Field Details
-
domainObject
-
name
-
fsrl
-
project
-
projectRootPath
-
mirrorFsLayout
protected boolean mirrorFsLayout -
loadedConsumer
-
domainFile
-
-
Constructor Details
-
Loaded
public Loaded(T domainObject, String name, FSRL fsrl, Project project, String projectRootPath, boolean mirrorFsLayout, Object consumer) - Parameters:
domainObject- The loadedDomainObjectname- The name of the loadedDomainObject. Path information that appears at the beginning the name will be appended to theprojectRootPathduring aoperation.fsrl- TheFSRLof the loadedDomainObjectproject- If notnull, the project this will get saved to during asave(TaskMonitor)operationprojectRootPath- The project folder path that allLoadedDomainObjects will besavedrelative to. Ifnull, "/" will be used.mirrorFsLayout- True if the filesystem layout should be mirrored whensaving; otherwise, falseconsumer- A reference to the object "consuming" the returnedLoadedDomainObject, used to ensure the underlyingDomainObjectis only closed when every consumer is done with it (seeclose()). NOTE: Wrapping aDomainObjectin aLoadedtransfers responsibility of releasing the givenDomainObjectto thisLoaded'sclose()method.
-
Loaded
- Parameters:
domainObject- The loadedDomainObjectsettings- TheLoader.ImporterSettings.
-
-
Method Details
-
getDomainObject
Gets the loadedDomainObject.NOTE: The given It is the responsibility of the caller to properly
releaseit when done. ThisDomainObject.release(Object)does not replace the requirement toclose()theLoadedobject when done.- Parameters:
consumer- A new reference to the object "consuming" the returnedDomainObject, used to ensure the underlyingDomainObjectis only released when every consumer is done with it (seeDomainObject.release(Object)). NOTE: This method adds the given consumer to the returnedDomainObject, requiring an explicitDomainObject.release(Object)to be called on the return value (thisLoadedmust also still beclosed).- Returns:
- The loaded
DomainObject
-
getDomainObject
Deprecated, for removal: This API element is subject to removal in a future version.This class's internalDomainObjectis now cleaned up with theclose()method. If theDomainObjectneeds to be retrieved from this class, instead usegetDomainObject(Object)and independently clean up the new reference with a separate call toDomainObject.release(Object).Gets the loadedDomainObjectwith unsafe resource management. Temporarily exists to provide backwards compatibility.- Returns:
- The loaded
DomainObject
-
getDomainObjectType
Gets the loadedDomainObject's type- Returns:
- the loaded
DomainObject's type
-
apply
Safely applies the given operation to the loadedDomainObjectwithout the need to worry about resource management- Parameters:
operation- The operation to apply to the loadedDomainObject
-
check
Safely tests the given predicate on the loadedDomainObjectwithout the need to worry about resource management- Parameters:
predicate- The predicate to test- Returns:
- The result of the test
-
getName
Gets the name of the loadedDomainObject. If asave(TaskMonitor)occurs, this will attempted to be used for the resultingDomainFile's name.- Returns:
- the name of the loaded
DomainObject
-
getProject
Gets theProjectthis will get saved to during asave(TaskMonitor)operation- Returns:
- The
Projectthis will get saved to during asave(TaskMonitor)operation (could be null)
-
getProjectFolderPath
Gets the project folder path this will get saved to during asave(TaskMonitor)operation.NOTE: The returned path will always end with a "/".
- Returns:
- the project folder path
-
setProjectFolderPath
Sets the project folder path this will get saved to during asave(TaskMonitor)operation.- Parameters:
projectRootPath- The project folder path that allLoadedDomainObjects will be saved relative to. Ifnull, "/" will be used.
-
save
public DomainFile save(TaskMonitor monitor) throws CancelledException, ClosedException, IOException, InvalidNameException Saves the loadedDomainObjectto the givenProjectat this object's project folder path, using this object's name.If a
DomainFilealready exists with the same desired name and project folder path, the desired name will get a counter value appended to it to avoid a naming conflict. Therefore, it should not be assumed that the returnedDomainFilewill have the same name as a call togetName().- Parameters:
monitor- A cancelable task monitor- Returns:
- The
DomainFilewhere the save happened - Throws:
CancelledException- if the operation was cancelledClosedException- if the loadedDomainObjectwas already closedIOException- If there was an IO-related error, a project wasn't specified, an invalid name was specified, or it was already successfully saved and still existsInvalidNameException- if saving with an invalid name
-
getSavedDomainFile
- Returns:
- The loaded
DomainObject's associated savedDomainFile, or null if was not saved - Throws:
FileNotFoundException- If the loadedDomainObjectwas saved but the associatedDomainFileno longer exists- See Also:
-
release
Deprecated, for removal: This API element is subject to removal in a future version.Useclose()insteadUnsafely notifies the loadedDomainObjectthat the specified consumer is no longer using it. Temporarily exists to provide backwards compatibility.- Parameters:
consumer- the consumer
-
close
public void close()Closes thisLoadedDomainObjectand releases the reference on the object consuming it.NOTE: Any
DomainObjects obtained viagetDomainObject(Object)must still be explicitlyreleasedafter calling this method, since they were obtained with their own consumers.- Specified by:
closein interfaceAutoCloseable
-
toString
-
DomainObjectis now cleaned up with theclose()method.