Class AbstractDocument
- java.lang.Object
-
- com.levigo.jadice.document.AbstractDocument
-
- All Implemented Interfaces:
Document,Item,MetadataProvider,MutableMetadataProvider,PermissionsProvider<Document>,PropertiesProvider
- Direct Known Subclasses:
BasicDocument
public abstract class AbstractDocument extends Object implements Document, MutableMetadataProvider
A basic implementation of theDocumentinterface. Not thread-safe!
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.levigo.jadice.document.Document
Document.BasicState, Document.State
-
-
Field Summary
Fields Modifier and Type Field Description protected com.levigo.jadice.document.DocumentInterceptorSupportinterceptorSupportprotected com.levigo.jadice.document.DocumentListenerSupportlistenerSupportprotected static LoggerLOGGER-
Fields inherited from interface com.levigo.jadice.document.Document
BASE_RESOLUTION, PROPERTY_KEY_DISPLAY_NAME, PROPERTY_KEY_DOCUMENT_ID, PROPERTY_KEY_FILE_NAME, PROPERTY_NAME, PROPERTY_PREFIX_PAGE, PROPERTY_PREFIX_USER_PROPERTY, PROPERTY_STATE
-
-
Constructor Summary
Constructors Constructor Description AbstractDocument()Construct a new document.AbstractDocument(String name)Construct a new document with the given name.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddDocumentInterceptor(DocumentInterceptor interceptor)Register aDocumentInterceptorto this document instance.voidaddDocumentListener(DocumentListener listener)Register aDocumentListenerto this document instance.voidaddPage(Page page)Adds a page to the document.protected voidcleanUpResources()Performes the actual clean-up required for disposing ofDocuments.booleanclose()Closes aDocument.voiddispose()Disposes of aDocumentperforming necessary clean-up tasks.protected voidexceptionIfDisposed()MetadatagetMetadata()Return the exposed meta-data ornullif no meta-data is available.MutableMetadataNodegetMutableMetadataRoot()Return the mutable root node of the meta-data tree belonging to this metadata provider.StringgetName()Gets the document's name.PagegetPage(int pageIndex)Convenience method: return the page at the given page index.PagegetPage(int pageNumber, boolean create)Return the page at the given page index.intgetPageCount()Convenience method: determine the number of pages in this document.intgetPageIndex(Page page)Convenience method: determine the index of a page in this document.abstract EventList<Page>getPages()Returns a list of pages in the document.Permissions<Document>getPermissions()Provides an instance ofPermissions.Map<String,Object>getProperties()Return a map of user properties.Document.StategetState()booleanisDisposed()Return whether or not thisDocumenthas been disposed of.voidremoveDocumentInterceptor(DocumentInterceptor interceptor)Unregister aDocumentInterceptorfrom this document.voidremoveDocumentListener(DocumentListener listener)Unregister aDocumentListenerfrom this document.voidsetName(String name)Sets the document's name.booleansetState(Document.State state)Sets the current state of theDocument.StringtoString()The description of the document
-
-
-
Field Detail
-
LOGGER
protected static final Logger LOGGER
-
listenerSupport
protected final com.levigo.jadice.document.DocumentListenerSupport listenerSupport
-
interceptorSupport
protected final com.levigo.jadice.document.DocumentInterceptorSupport interceptorSupport
-
-
Constructor Detail
-
AbstractDocument
public AbstractDocument()
Construct a new document.
-
AbstractDocument
public AbstractDocument(String name)
Construct a new document with the given name.- Parameters:
name- the name of the document
-
-
Method Detail
-
addDocumentListener
public void addDocumentListener(DocumentListener listener)
Description copied from interface:DocumentRegister aDocumentListenerto this document instance.- Specified by:
addDocumentListenerin interfaceDocument- Parameters:
listener- the listener to register
-
addPage
public final void addPage(Page page)
Adds a page to the document.- Parameters:
page- the page to add- Throws:
IllegalStateException- if called on aDocumentwhich has been disposed of.
-
close
public final boolean close()
Description copied from interface:DocumentCloses aDocument. This includes performing a state transition toDocument.BasicState.CLOSEDand cleaning up resources. Both will only happen if all registeredDocumentInterceptors agree with the state change. In usual cases, this method should be preferred to callingDocument.dispose().- Specified by:
closein interfaceDocument- Returns:
- flag indicating whether the process passed successfully or not
- See Also:
for details about resource clean-up,will be asked to accept or deny the state change. Implementations could ask the user for acknowledgment.,gets the chance to perform save or clean-up actions when it receives the state change to new state .
-
dispose
public void dispose()
Description copied from interface:DocumentDisposes of a
Documentperforming necessary clean-up tasks. DisposedDocuments will haveDocument.BasicState.CLOSEDas theirDocument.State. This method is not expected to ask registeredDocumentInterceptors for their consent about the state transition.DocumentListeners may or may not be informed about the state change. In most cases,Document.close()should be used instead of this method.Since cleaning up releases any resources held by this
Document, it will no longer be practically useful afterwards. ADocumentwhich has been disposed of will refuse further changes on itself and may throw Exceptions if methods are called.Before calling dispose it is for this reason important to make sure that the
Documentto be disposed of is not registered with any other (GUI or non-GUI) component which might call methods later on.
-
cleanUpResources
protected void cleanUpResources()
Performes the actual clean-up required for disposing ofDocuments.
-
isDisposed
public boolean isDisposed()
Description copied from interface:DocumentReturn whether or not thisDocumenthas been disposed of. DisposedDocuments will refuse further changes on themselves. Method calls on them may result in Exceptions being thrown.- Specified by:
isDisposedin interfaceDocument- Returns:
trueif thisDocumenthas been disposed of and all of its resources have been cleaned up.falseif thisDocumenthas not yet been disposed of and is therefore fully usable.- See Also:
Document.dispose()
-
getName
public String getName()
Description copied from interface:DocumentGets the document's name.
-
getPage
public Page getPage(int pageIndex)
Description copied from interface:DocumentConvenience method: return the page at the given page index. Equivalent to. As an added convenience, callers need not lock the page list in order to be thread-safe.Document.getPages().get(pageNumber)
-
getPageIndex
public int getPageIndex(Page page)
Description copied from interface:DocumentConvenience method: determine the index of a page in this document. Equivalent to. As an added convenience, callers need not lock the page list in order to be thread-safe.Document.getPages().indexOf(page)- Specified by:
getPageIndexin interfaceDocument- Parameters:
page- to search for- Returns:
- int the page number of the given page in this document, or -1 if this document does not contain the page
-
getPage
public Page getPage(int pageNumber, boolean create)
Description copied from interface:DocumentReturn the page at the given page index. Create it, if there is no page at this index at this point. As an added convenience, callers need not lock the page list in order to be thread-safe.
-
getPageCount
public int getPageCount()
Description copied from interface:DocumentConvenience method: determine the number of pages in this document. Equivalent to. As an added convenience, callers need not lock the page list in order to be thread-safe.Document.getPages().size()- Specified by:
getPageCountin interfaceDocument- Returns:
- int the page number count
-
getPages
public abstract EventList<Page> getPages()
Description copied from interface:DocumentReturns a list of pages in the document. Please note that, unless stated otherwise by implementors, this list is not thread-safe. Care must therefore be taken to manipulate the page list with appropriate locking as detailed in the documentation ofEventList. As a convenience, a non-thread-safe page list may be wrapped usingGlazedLists.threadSafeList(EventList)to obtain a thread-safe one.
-
getState
public final Document.State getState()
-
removeDocumentListener
public void removeDocumentListener(DocumentListener listener)
Description copied from interface:DocumentUnregister aDocumentListenerfrom this document.- Specified by:
removeDocumentListenerin interfaceDocument- Parameters:
listener- the listener to remove
-
setName
public void setName(String name)
Description copied from interface:DocumentSets the document's name.
-
setState
public boolean setState(Document.State state)
Description copied from interface:DocumentSets the current state of the
Document.The document
Document.Stateis not only a simple information about a document instance, but also it provides the decision base of the enabled state for many document functionalities. If the document state is not set or is set to a wrong state, these functionalities may become disabled or fail to execute. Registered interceptors may disapprove state changes. Therefore the requested state is not necessarily the actual next state.- Specified by:
setStatein interfaceDocument- Parameters:
state- the new state- Returns:
- whether the state change was successful (
true) or rejected (false). - See Also:
Document.State,Document.BasicState,DocumentInterceptor
-
toString
public String toString()
The description of the document
-
getProperties
public Map<String,Object> getProperties()
Description copied from interface:PropertiesProviderReturn a map of user properties. What to store and which keys to use is largely up to the user of classes implementing this interface, since those classes will generally be oblivious to the map's contents. There are no guarantees regarding the thread-safety of the returned map, unless otherwise specified by implementors.- Specified by:
getPropertiesin interfacePropertiesProvider- Returns:
- a thread-safe map of user properties. If this document has been disposed of, the map will be empty.
- See Also:
PropertiesProvider.getProperties()
-
addDocumentInterceptor
public void addDocumentInterceptor(DocumentInterceptor interceptor)
Description copied from interface:DocumentRegister aDocumentInterceptorto this document instance.- Specified by:
addDocumentInterceptorin interfaceDocument- Parameters:
interceptor- the interceptor to register
-
removeDocumentInterceptor
public void removeDocumentInterceptor(DocumentInterceptor interceptor)
Description copied from interface:DocumentUnregister aDocumentInterceptorfrom this document.- Specified by:
removeDocumentInterceptorin interfaceDocument- Parameters:
interceptor- the interceptor to remove
-
getPermissions
public Permissions<Document> getPermissions()
Description copied from interface:PermissionsProviderProvides an instance ofPermissions. Must never returnnull.- Specified by:
getPermissionsin interfacePermissionsProvider<Document>- Returns:
- a
Permissionsobject.
-
getMetadata
public Metadata getMetadata()
Description copied from interface:MetadataProviderReturn the exposed meta-data ornullif no meta-data is available. An object being a MetadataProvider is not required to provide a non-nullmeta-data.- Specified by:
getMetadatain interfaceMetadataProvider- Returns:
- the metadata document or
null
-
getMutableMetadataRoot
public MutableMetadataNode getMutableMetadataRoot()
Description copied from interface:MutableMetadataProviderReturn the mutable root node of the meta-data tree belonging to this metadata provider.- Specified by:
getMutableMetadataRootin interfaceMutableMetadataProvider- Returns:
- the mutable root node
-
exceptionIfDisposed
protected void exceptionIfDisposed()
-
-