public abstract class AbstractDocument extends Object implements Document, MutableMetadataProvider
Document
interface. Not thread-safe!Document.BasicState, Document.State
Modifier and Type | Field and Description |
---|---|
protected com.levigo.jadice.document.DocumentInterceptorSupport |
interceptorSupport |
protected com.levigo.jadice.document.DocumentListenerSupport |
listenerSupport |
protected static Logger |
LOGGER |
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 and Description |
---|
AbstractDocument()
Construct a new document.
|
AbstractDocument(String name)
Construct a new document with the given name.
|
Modifier and Type | Method and Description |
---|---|
void |
addDocumentInterceptor(DocumentInterceptor interceptor)
Register a
DocumentInterceptor to this document instance. |
void |
addDocumentListener(DocumentListener listener)
Register a
DocumentListener to this document instance. |
void |
addPage(Page page)
Adds a page to the document.
|
protected void |
cleanUpResources()
Performes the actual clean-up required for disposing of
Document s. |
boolean |
close()
Closes a
Document . |
void |
dispose()
Disposes of a
Document performing necessary clean-up tasks. |
protected void |
exceptionIfDisposed() |
Metadata |
getMetadata()
Return the exposed meta-data or
null if no meta-data is available. |
MutableMetadataNode |
getMutableMetadataRoot()
Return the mutable root node of the meta-data tree belonging to this metadata provider.
|
String |
getName()
Gets the document's name.
|
Page |
getPage(int pageIndex)
Convenience method: return the page at the given page index.
|
Page |
getPage(int pageNumber,
boolean create)
Return the page at the given page index.
|
int |
getPageCount()
Convenience method: determine the number of pages in this document.
|
int |
getPageIndex(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 of
Permissions . |
Map<String,Object> |
getProperties()
Return a map of user properties.
|
Document.State |
getState() |
boolean |
isDisposed()
Return whether or not this
Document has been disposed of. |
void |
removeDocumentInterceptor(DocumentInterceptor interceptor)
Unregister a
DocumentInterceptor from this document. |
void |
removeDocumentListener(DocumentListener listener)
Unregister a
DocumentListener from this document. |
void |
setName(String name)
Sets the document's name.
|
boolean |
setState(Document.State state)
Sets the current state of the
Document . |
String |
toString()
The description of the document
|
protected static final Logger LOGGER
protected final com.levigo.jadice.document.DocumentListenerSupport listenerSupport
protected final com.levigo.jadice.document.DocumentInterceptorSupport interceptorSupport
public AbstractDocument()
public AbstractDocument(String name)
name
- the name of the documentpublic void addDocumentListener(DocumentListener listener)
Document
DocumentListener
to this document instance.addDocumentListener
in interface Document
listener
- the listener to registerpublic final void addPage(Page page)
page
- the page to addIllegalStateException
- if called on a Document
which has been disposed of.public final boolean close()
Document
Document
. This includes performing a state transition to
Document.BasicState.CLOSED
and cleaning up resources. Both will only happen if all registered
DocumentInterceptor
s agree with the state change. In usual cases, this method should be
preferred to calling Document.dispose()
.close
in interface Document
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 {@link BasicState#CLOSED}.
public void dispose()
Document
Disposes of a Document
performing necessary clean-up tasks. Disposed Document
s
will have Document.BasicState.CLOSED
as their Document.State
. This method is not expected to
ask registered DocumentInterceptor
s for their consent about the state transition.
DocumentListener
s 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. A Document
which 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 Document
to
be disposed of is not registered with any other (GUI or non-GUI) component which might call
methods later on.
protected void cleanUpResources()
Document
s.public boolean isDisposed()
Document
Document
has been disposed of. Disposed Document
s will
refuse further changes on themselves. Method calls on them may result in Exceptions being thrown.isDisposed
in interface Document
true
if this Document
has been disposed of and all of its resources
have been cleaned up. false
if this Document
has not yet been
disposed of and is therefore fully usable.Document.dispose()
public String getName()
Document
public Page getPage(int pageIndex)
Document
Document.getPages()
.get(pageNumber)
. As an added convenience, callers need not lock
the page list in order to be thread-safe.public int getPageIndex(Page page)
Document
Document.getPages()
.indexOf(page)
. As an added convenience, callers need not lock
the page list in order to be thread-safe.getPageIndex
in interface Document
page
- to search forpublic Page getPage(int pageNumber, boolean create)
Document
public int getPageCount()
Document
Document.getPages()
.size()
. As an added convenience, callers need not lock the page
list in order to be thread-safe.getPageCount
in interface Document
public abstract EventList<Page> getPages()
Document
EventList
. As
a convenience, a non-thread-safe page list may be wrapped using
GlazedLists.threadSafeList(EventList)
to obtain a thread-safe one.public final Document.State getState()
public void removeDocumentListener(DocumentListener listener)
Document
DocumentListener
from this document.removeDocumentListener
in interface Document
listener
- the listener to removepublic void setName(String name)
Document
public boolean setState(Document.State state)
Document
Sets the current state of the Document
.
The document Document.State
is 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.
setState
in interface Document
state
- the new statetrue
) or rejected (
false
).Document.State
,
Document.BasicState
,
DocumentInterceptor
public String toString()
public Map<String,Object> getProperties()
PropertiesProvider
getProperties
in interface PropertiesProvider
PropertiesProvider.getProperties()
public void addDocumentInterceptor(DocumentInterceptor interceptor)
Document
DocumentInterceptor
to this document instance.addDocumentInterceptor
in interface Document
interceptor
- the interceptor to registerpublic void removeDocumentInterceptor(DocumentInterceptor interceptor)
Document
DocumentInterceptor
from this document.removeDocumentInterceptor
in interface Document
interceptor
- the interceptor to removepublic Permissions<Document> getPermissions()
PermissionsProvider
Permissions
. Must never return null
.getPermissions
in interface PermissionsProvider<Document>
Permissions
object.public Metadata getMetadata()
MetadataProvider
null
if no meta-data is available. An object being
a MetadataProvider is not required to provide a non-null
meta-data.getMetadata
in interface MetadataProvider
null
public MutableMetadataNode getMutableMetadataRoot()
MutableMetadataProvider
getMutableMetadataRoot
in interface MutableMetadataProvider
protected void exceptionIfDisposed()
Copyright © 2024 levigo holding gmbh. All rights reserved.