/projects/nakedobjects-4.0.0/core/applib/src/main/java/org/nakedobjects/applib/DomainObjectContainer.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 365 lines · 37 code · 55 blank · 273 comment · 0 complexity · 1c3536656ed4540a0655dea6d7d744a4 MD5 · raw file

  1. package org.nakedobjects.applib;
  2. import java.util.List;
  3. import org.nakedobjects.applib.query.Query;
  4. import org.nakedobjects.applib.security.UserMemento;
  5. /**
  6. * Represents a container that the domain objects work within. It provides access to the persistence mechanism
  7. * and user interface.
  8. */
  9. public interface DomainObjectContainer {
  10. //////////////////////////////////////////////////////////////////
  11. // resolve, objectChanged
  12. //////////////////////////////////////////////////////////////////
  13. /**
  14. * Ensure that the specified object is completely loaded into memory.
  15. *
  16. * <p>
  17. * This forces the lazy loading mechanism to load the object if it is not already loaded.
  18. */
  19. void resolve(Object domainObject);
  20. /**
  21. * Ensure that the specified object is completely loaded into memory, though only if the supplied field
  22. * reference is <tt>null</tt>.
  23. *
  24. * <p>
  25. * This forces the lazy loading mechanism to load the object if it is not already loaded.
  26. */
  27. void resolve(Object domainObject, Object field);
  28. /**
  29. * Flags that the specified object's state has changed and its changes need to be saved.
  30. */
  31. void objectChanged(Object domainObject);
  32. //////////////////////////////////////////////////////////////////
  33. // flush, commit
  34. //////////////////////////////////////////////////////////////////
  35. /**
  36. * Flush all changes to the object store.
  37. *
  38. * <p>
  39. * Typically only for use by tests.
  40. *
  41. * @return <tt>true</tt>
  42. */
  43. boolean flush();
  44. /**
  45. * Commit all changes to the object store.
  46. *
  47. * <p>
  48. * Typically only for use by tests.
  49. */
  50. void commit();
  51. //////////////////////////////////////////////////////////////////
  52. // new{Transient/Persistent}Instance
  53. //////////////////////////////////////////////////////////////////
  54. /**
  55. * Create a new instance of the specified class, but do not persist it.
  56. *
  57. * @see #newPersistentInstance(Class)
  58. */
  59. <T> T newTransientInstance(Class<T> ofType);
  60. /**
  61. * Returns a new instance of the specified class that will have been persisted.
  62. */
  63. <T> T newPersistentInstance(final Class<T> ofType) ;
  64. /**
  65. * Returns a new instance of the specified class that has the sane persisted state as the specified object.
  66. */
  67. <T> T newInstance(final Class<T> ofType, final Object object);
  68. //////////////////////////////////////////////////////////////////
  69. // isValid, validate
  70. //////////////////////////////////////////////////////////////////
  71. /**
  72. * Whether the object is in a valid state, that is that none of the validation of
  73. * properties, collections and object-level is vetoing.
  74. *
  75. * @see #validate(Object)
  76. */
  77. boolean isValid(Object domainObject);
  78. /**
  79. * The reason, if any why the object is in a invalid state
  80. *
  81. * <p>
  82. * Checks the validation of all of the properties, collections and object-level.
  83. *
  84. * @see #isValid(Object)
  85. */
  86. String validate(Object domainObject);
  87. //////////////////////////////////////////////////////////////////
  88. // isPersistent, persist, remove
  89. //////////////////////////////////////////////////////////////////
  90. /**
  91. * Determines if the specified object is persistent (that it is stored permanently outside of the virtual
  92. * machine).
  93. */
  94. boolean isPersistent(Object domainObject);
  95. /**
  96. * Make the specified transient object persistent.
  97. *
  98. * <p>
  99. * Throws an exception if object is already persistent.
  100. *
  101. * @see #isPersistent(Object)
  102. * @see #persistIfNotAlready(Object)
  103. */
  104. void persist(Object transientDomainObject);
  105. /**
  106. * Make the specified object persistent if not already.
  107. *
  108. * <p>
  109. * Does nothing otherwise.
  110. *
  111. * @see #isPersistent(Object)
  112. * @see #persist(Object)
  113. */
  114. void persistIfNotAlready(Object domainObject);
  115. /**
  116. * Removes (deletes) the persisted object.
  117. *
  118. * @param persistentDomainObject
  119. */
  120. void remove(Object persistentDomainObject);
  121. //////////////////////////////////////////////////////////////////
  122. // info, warn, error
  123. //////////////////////////////////////////////////////////////////
  124. /**
  125. * Make the specified message available to the user. Note this will probably be displayed in transitory
  126. * fashion, so is only suitable for useful but optional information.
  127. *
  128. * @see #warnUser(String)
  129. * @see #raiseError(String)
  130. */
  131. void informUser(String message);
  132. /**
  133. * Warn the user about a situation with the specified message. The container should guarantee to display
  134. * this warning to the user.
  135. *
  136. * @see #raiseError(String)
  137. * @see #informUser(String)
  138. */
  139. void warnUser(String message);
  140. /**
  141. * Notify the user of an application error with the specified message. Note this will probably be
  142. * displayed in an alarming fashion, so is only suitable for errors
  143. *
  144. * @see #warnUser(String)
  145. * @see #informUser(String)
  146. */
  147. void raiseError(String message);
  148. //////////////////////////////////////////////////////////////////
  149. // security
  150. //////////////////////////////////////////////////////////////////
  151. /**
  152. * Get the details about the current user.
  153. */
  154. UserMemento getUser();
  155. //////////////////////////////////////////////////////////////////
  156. // allInstances, allMatches, firstMatch, uniqueMatch
  157. //////////////////////////////////////////////////////////////////
  158. /**
  159. * Returns all the instances of the specified type (including subtypes).
  160. *
  161. * <p>
  162. * If there are no instances the list will be empty. This method creates a
  163. * new {@link List} object each time it is called so the caller is free to
  164. * use or modify the returned {@link List}, but the changes will not be
  165. * reflected back to the repository.
  166. *
  167. * <p>
  168. * This method should only be called where the number of instances is known to
  169. * be relatively low.
  170. */
  171. public <T> List<T> allInstances(Class<T> ofType);
  172. /**
  173. * Returns all the instances of the specified type (including subtypes) that
  174. * the filter object accepts.
  175. *
  176. * <p>
  177. * If there are no instances the list will be empty. This method creates a
  178. * new {@link List} object each time it is called so the caller is free to
  179. * use or modify the returned {@link List}, but the changes will not be
  180. * reflected back to the repository.
  181. *
  182. * <p>
  183. * This method is useful during exploration/prototyping, but you may want to use
  184. * {@link #allMatches(Query)} for production code.
  185. */
  186. public <T> List<T> allMatches(final Class<T> ofType, final Filter<T> filter);
  187. /**
  188. * Returns all the instances of the specified type (including subtypes) that
  189. * have the given title.
  190. *
  191. * <p>
  192. * If there are no instances the list will be empty. This method creates a
  193. * new {@link List} object each time it is called so the caller is free to
  194. * use or modify the returned {@link List}, but the changes will not be
  195. * reflected back to the repository.
  196. *
  197. * <p>
  198. * This method is useful during exploration/prototyping, but you may want to use
  199. * {@link #allMatches(Query)} for production code.
  200. */
  201. public <T> List<T> allMatches(Class<T> ofType, String title);
  202. /**
  203. * Returns all the instances of the specified type (including subtypes) that
  204. * match the given object: where any property that is set will be tested and
  205. * properties that are not set will be ignored.
  206. *
  207. * <p>
  208. * If there are no instances the list will be empty. This method creates a
  209. * new {@link List} object each time it is called so the caller is free to
  210. * use or modify the returned {@link List}, but the changes will not be
  211. * reflected back to the repository.
  212. *
  213. * <p>
  214. * This method is useful during exploration/prototyping, but you may want to use
  215. * {@link #allMatches(Query)} for production code.
  216. */
  217. <T> List<T> allMatches(Class<T> ofType, T pattern);
  218. /**
  219. * Returns all the instances that match the given {@link Query}.
  220. *
  221. * <p>
  222. * If there are no instances the list will be empty. This method creates a
  223. * new {@link List} object each time it is called so the caller is free to
  224. * use or modify the returned {@link List}, but the changes will not be
  225. * reflected back to the repository.
  226. */
  227. <T> List<T> allMatches(Query<T> query);
  228. /**
  229. * Returns the first instance of the specified type (including subtypes)
  230. * that matches the supplied {@link Filter}, or <tt>null</tt> if none.
  231. *
  232. * <p>
  233. * This method is useful during exploration/prototyping, but you may want to use
  234. * {@link #firstMatch(Query)} for production code.
  235. */
  236. public <T> T firstMatch(final Class<T> ofType, final Filter<T> filter);
  237. /**
  238. * Returns the first instance of the specified type (including subtypes)
  239. * that matches the supplied title, or <tt>null</tt> if none.
  240. *
  241. * <p>
  242. * This method is useful during exploration/prototyping, but you may want to use
  243. * {@link #firstMatch(Query)} for production code.
  244. */
  245. <T> T firstMatch(Class<T> ofType, String title);
  246. /**
  247. * Returns the first instance of the specified type (including subtypes)
  248. * that matches the supplied object as a pattern, or <tt>null</tt> if none.
  249. *
  250. * <p>
  251. * This method is useful during exploration/prototyping, but you may want to use
  252. * {@link #firstMatch(Query)} for production code.
  253. */
  254. <T> T firstMatch(Class<T> ofType, T pattern);
  255. /**
  256. * Returns the first instance that matches the supplied query,
  257. * or <tt>null</tt> if none.
  258. */
  259. <T> T firstMatch(Query<T> query);
  260. /**
  261. * Find the only instance of the specified type (including subtypes) that
  262. * has the specified title.
  263. *
  264. * <p>
  265. * If no instance is found then <tt>null</tt> will be return, while if there
  266. * is more that one instances a run-time exception will be thrown.
  267. *
  268. * <p>
  269. * This method is useful during exploration/prototyping, but you may want to use
  270. * {@link #uniqueMatch(Query)} for production code.
  271. */
  272. public <T> T uniqueMatch(final Class<T> ofType, final Filter<T> filter);
  273. /**
  274. * Find the only instance of the specified type (including subtypes) that
  275. * has the specified title.
  276. *
  277. * <p>
  278. * If no instance is found then <tt>null</tt> will be returned, while if
  279. * there is more that one instances a run-time exception will be thrown.
  280. *
  281. * <p>
  282. * This method is useful during exploration/prototyping, but you may want to use
  283. * {@link #uniqueMatch(Query)} for production code.
  284. */
  285. <T> T uniqueMatch(Class<T> ofType, String title);
  286. /**
  287. * Find the only instance of the patterned object type (including subtypes)
  288. * that matches the set fields in the pattern object: where any property
  289. * that is set will be tested and properties that are not set will be
  290. * ignored.
  291. *
  292. * <p>
  293. * If no instance is found then null will be return, while if there is more
  294. * that one instances a run-time exception will be thrown.
  295. *
  296. * <p>
  297. * This method is useful during exploration/prototyping, but you may want to use
  298. * {@link #uniqueMatch(Query)} for production code.
  299. */
  300. <T> T uniqueMatch(Class<T> ofType, T pattern);
  301. /**
  302. * Find the only instance that matches the provided query.
  303. *
  304. * <p>
  305. * If no instance is found then null will be return, while if there is more
  306. * that one instances a run-time exception will be thrown.
  307. */
  308. <T> T uniqueMatch(Query<T> query);
  309. }
  310. // Copyright (c) Naked Objects Group Ltd.