/Ghidra/Framework/Project/src/main/java/ghidra/framework/data/ContentHandler.java

https://github.com/NationalSecurityAgency/ghidra · Java · 215 lines · 42 code · 20 blank · 153 comment · 0 complexity · 5c2b3dff7433fdf41f67b6ec656c383c MD5 · raw file

  1. /* ###
  2. * IP: GHIDRA
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package ghidra.framework.data;
  17. import java.io.IOException;
  18. import javax.swing.Icon;
  19. import db.DBHandle;
  20. import ghidra.framework.model.ChangeSet;
  21. import ghidra.framework.model.DomainObject;
  22. import ghidra.framework.store.FileSystem;
  23. import ghidra.framework.store.FolderItem;
  24. import ghidra.util.InvalidNameException;
  25. import ghidra.util.classfinder.ExtensionPoint;
  26. import ghidra.util.exception.CancelledException;
  27. import ghidra.util.exception.VersionException;
  28. import ghidra.util.task.TaskMonitor;
  29. /**
  30. * NOTE: ALL ContentHandler CLASSES MUST END IN "ContentHandler". If not,
  31. * the ClassSearcher will not find them.
  32. *
  33. * <code>ContentHandler</code> defines an application interface for converting
  34. * between a specific domain object implementation and folder item storage.
  35. * This interface also defines a method which provides an appropriate icon
  36. * corresponding to the content.
  37. */
  38. public interface ContentHandler extends ExtensionPoint {
  39. public static final String UNKNOWN_CONTENT = "Unknown-File";
  40. public static final String MISSING_CONTENT = "Missing-File";
  41. /**
  42. * Creates a new folder item within a specified file-system.
  43. * If fs is versioned, the resulting item is marked as checked-out
  44. * within the versioned file-system. The specified domainObj
  45. * will become associated with the newly created database.
  46. * @param fs the file system in which to create the folder item
  47. * @param userfs file system which contains associated user data
  48. * @param path the path of the folder item
  49. * @param name the name of the new folder item
  50. * @param domainObject the domain object to store in the newly created folder item
  51. * @param monitor the monitor that allows the user to cancel
  52. * @return checkout ID for new item
  53. * @throws IOException if an i/o error occurs
  54. * @throws InvalidNameException if the specified name contains invalid characters
  55. * @throws CancelledException if the user cancels
  56. */
  57. long createFile(FileSystem fs, FileSystem userfs, String path, String name,
  58. DomainObject domainObject, TaskMonitor monitor)
  59. throws IOException, InvalidNameException, CancelledException;
  60. /**
  61. * Open a folder item for immutable use. If any changes are attempted on the
  62. * returned object, an IllegalStateException state exception may be thrown.
  63. * @param item stored folder item
  64. * @param consumer consumer of the returned object
  65. * @param version version of the stored folder item to be opened.
  66. * DomainFile.DEFAULT_VERSION (-1) should be specified when not opening a specific
  67. * file version.
  68. * @param minChangeVersion the minimum version which should be included in the
  69. * change set for the returned object. A value of -1 indicates the default change
  70. * set.
  71. * @param monitor the monitor that allows the user to cancel
  72. * @return immutable domain object
  73. * @throws IOException if a folder item access error occurs
  74. * @throws CancelledException if operation is cancelled by user
  75. * @throws VersionException if unable to handle file content due to version
  76. * difference which could not be handled.
  77. */
  78. DomainObjectAdapter getImmutableObject(FolderItem item, Object consumer, int version,
  79. int minChangeVersion, TaskMonitor monitor)
  80. throws IOException, CancelledException, VersionException;
  81. /**
  82. * Open a folder item for read-only use. While changes are permitted on the
  83. * returned object, the original folder item may not be overwritten / updated.
  84. * @param item stored folder item
  85. * @param version version of the stored folder item to be opened.
  86. * DomainFile.DEFAULT_VERSION should be specified when not opening a specific
  87. * file version.
  88. * @param okToUpgrade if true a version upgrade to the content will be done
  89. * if necessary.
  90. * @param consumer consumer of the returned object
  91. * @param monitor the monitor that allows the user to cancel
  92. * @return read-only domain object
  93. * @throws IOException if a folder item access error occurs
  94. * @throws CancelledException if operation is cancelled by user
  95. * @throws VersionException if unable to handle file content due to version
  96. * difference which could not be handled.
  97. */
  98. DomainObjectAdapter getReadOnlyObject(FolderItem item, int version, boolean okToUpgrade,
  99. Object consumer, TaskMonitor monitor)
  100. throws IOException, VersionException, CancelledException;
  101. /**
  102. * Open a folder item for update. Changes made to the returned object may be
  103. * saved to the original folder item.
  104. * @param item stored folder item
  105. * @param userfs file system which contains associated user data
  106. * @param checkoutId an appropriate checout ID required to update the specified
  107. * folder item.
  108. * @param okToUpgrade if true a version upgrade to the content will be done
  109. * if necessary.
  110. * @param okToRecover if true an attempt to recover any unsaved changes resulting from
  111. * a crash will be attempted.
  112. * @param consumer consumer of the returned object
  113. * @param monitor cancelable task monitor
  114. * @return updateable domain object
  115. * @throws IOException if a folder item access error occurs
  116. * @throws CancelledException if operation is cancelled by user
  117. * @throws VersionException if unable to handle file content due to version
  118. * difference which could not be handled.
  119. */
  120. DomainObjectAdapter getDomainObject(FolderItem item, FileSystem userfs, long checkoutId,
  121. boolean okToUpgrade, boolean okToRecover, Object consumer, TaskMonitor monitor)
  122. throws IOException, CancelledException, VersionException;
  123. /**
  124. * Returns the object change data which includes changes made to the specified
  125. * olderVersion through to the specified newerVersion.
  126. * @param versionedFolderItem versioned folder item
  127. * @param olderVersion the older version number
  128. * @param newerVersion the newer version number
  129. * @return the set of changes that were made
  130. * @throws VersionException if a database version change prevents reading of data.
  131. * @throws IOException if a folder item access error occurs or change set was
  132. * produced by newer version of software and can not be read
  133. */
  134. ChangeSet getChangeSet(FolderItem versionedFolderItem, int olderVersion, int newerVersion)
  135. throws VersionException, IOException;
  136. /**
  137. * Get an instance of a suitable merge manager to be used during the merge of a Versioned
  138. * object which has been modified by another user since it was last merged
  139. * or checked-out.
  140. * @param resultsObj object to which merge results should be written
  141. * @param sourceObj object which contains user's changes to be merged
  142. * @param originalObj object which corresponds to checked-out version state
  143. * @param latestObj object which corresponds to latest version with which
  144. * the sourceObj must be merged.
  145. * @return merge manager
  146. */
  147. DomainObjectMergeManager getMergeManager(DomainObject resultsObj, DomainObject sourceObj,
  148. DomainObject originalObj, DomainObject latestObj);
  149. /**
  150. * Returns true if the content type is always private
  151. * (i.e., can not be added to the versioned filesystem).
  152. */
  153. boolean isPrivateContentType();
  154. /**
  155. * Returns list of unique content-types supported.
  156. * A minimum of one content-type will be returned. If more than one
  157. * is returned, these are considered equivalent aliases.
  158. */
  159. String getContentType();
  160. /**
  161. * A string that is meant to be presented to the user.
  162. */
  163. String getContentTypeDisplayString();
  164. /**
  165. * Returns the Icon associated with this handlers content type.
  166. */
  167. Icon getIcon();
  168. /**
  169. * Returns the name of the default tool that should be used to open this content type
  170. */
  171. String getDefaultToolName();
  172. /**
  173. * Returns domain object implementation class supported.
  174. */
  175. Class<? extends DomainObject> getDomainObjectClass();
  176. /**
  177. * Create user data file associated with existing content.
  178. * This facilitates the lazy creation of the user data file.
  179. * @param associatedDomainObj associated domain object corresponding to this content handler
  180. * @param userDbh user data handle
  181. * @param userfs private user data filesystem
  182. * @param monitor task monitor
  183. * @throws IOException if an access error occurs
  184. * @throws CancelledException if operation is cancelled by user
  185. */
  186. void saveUserDataFile(DomainObject associatedDomainObj, DBHandle userDbh, FileSystem userfs,
  187. TaskMonitor monitor) throws CancelledException, IOException;
  188. /**
  189. * Remove user data file associated with an existing folder item.
  190. * @param item folder item
  191. * @param userFilesystem
  192. * @throws IOException if an access error occurs
  193. */
  194. void removeUserDataFile(FolderItem item, FileSystem userFilesystem) throws IOException;
  195. }