|
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference 11g Release 1 (11.1.1.7.2) E13403-10 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface TextBuffer
The TextBuffer
interface describes a class which can be used for managing the raw text content of a document. It provides services to higher level document classes, such as shared/exclusive locking services, buffer modification through insert/removal, buffer change notification, and mark services.
This TextBuffer
interface acts as a unified data or buffer model between the editor and IDE packages - this allows us to build implementation layers above this Content layer to satisfy the requirements of each.
Terminology Notes:
The implementation refers to implementations of the TextBuffer
interface, such as an ArrayTextBuffer
. The client refers to clients which use a TextBuffer
, such as an editor document or parser.
LineMap Service:
The TextBuffer
provides line map services for clients to use for determining line boundaries. Method calls are available for mapping a given buffer offset to a line, and for obtaining the start and end offsets of a line. Please refer to the
interface for more details on using the LineMap
LineMap
.
OffsetMark Service:
OffsetMarks
are used to bookmark specific offsets in the text buffer. Method calls are available for adding or removing marks, and for getting or changing the offset location for specific marks. Please refer to the
interface for more details on using OffsetMark
OffsetMarks
.
UndoableEdit Notes:
UndoableEdits
are generated by the insert()
and remove()
methods to represent the changes made to the buffer. These can be used as building blocks to support an Undo mechanism in the client application. It is the responsibility of the client application to manage the UndoableEdits
and to apply them in the proper order. Buffer implementations may however use the change id to do some minimum enforcing of undo ordering.
If there are specific changes that should be represented by a single undo operation, the beginEdit()
and endEdit()
pairs can be used. For example, suppose the user adds a button through a UI designer, which corresponds to adding multiple lines of code in the buffer. The application should call beginEdit(), make the changes to the buffer, then call endEdit(), which will return a single compound UndoableEdit representing all the changes made. Note that calls to the beginEdit()
and endEdit()
pairs cannot overlap or be nested - that is it is illegal to call beginEdit()
if there is already a compound edit in progress.
Note that individual edits within a compound edit should take into account how their offsets and lengths affect each other. For example, let's suppose that the application needs to insert 10 bytes at offset 10, and 5 bytes at offset 20. It should apply them in reverse order:
If it applies them in forward order, the offset shifts must be taken into account:
Locking Notes:
This interface provides locking routines which must be used by clients to ensure data consistency and integrity. Clients must acquire a read lock before retrieving data from this buffer, or accessing information from the line map. As discussed in the ReadTextBuffer
interface, implementations are not required to perform range checking on data read requests, such as through getChar()
. Clients must either perform their own range checking, or must catch and handle the IndexOutOfBoundsException
.
Clients must acquire a write lock before modifying the text buffer through this interface. As a convenience to clients, implementations must implicitly lock the buffer in the insert()
and remove()
methods. Clients are still encouraged to make use of the writeLock()
and writeUnlock()
calls, especially when multiple modifications need to be made sequentially.
The tryReadLock()
and tryWriteLock()
are non-blocking versions of readLock()
and writeLock()
. These methods can be used for testing if a lock can be acquired without blocking.
Modification Notes:
This interface provides some basic support for determining whether a buffer has been modified or not. It does not however provide timestamp information, such as the timestamp for when a modification was made to the text buffer. A buffer is marked as unmodified when it is created, after read() is called, or after clearModified() is called. After an insert(), append(), remove(), or removeToEnd(), a buffer is considered to be modified.
Additionally, the (buffer) implementation is required to update the modification information when applying undos that are generated by the buffer. For example, suppose a buffer is initially unmodified, then an insert made resulting in an UndoableEdit
. If that UndoableEdit
is then applied, the buffer is required to ensure that the buffer's modified status is also reset back to unmodified as it was before the insert.
Change ID Notes:
This interface provides the getChangeId()
method for getting an incarnation number for representing a particular version of the buffer's contents. (Buffer) implementations must guarantee that incarnation numbers of the buffer before and after a mutation are different, though not necessarily in sequence. Implementations must also guarantee that undoing a mutation using an UndoableEdit
generated by the buffer will also restore the previous change id as well. For example, suppose the change id for the buffer is 10, then an insert was made resulting in an UndoableEdit
and new change id of 12. If that UndoableEdit
is then applied (undone), the change id of the buffer must be restored back to 10. If that UndoableEdit
is re-applied (redone), the chagne id of the buffer must be restored back to 12.
This can be used by clients to determine whether a buffer has been modified since a particular snapshot. For example, suppose a client uses a parser to build additional client-specific model information based on the text buffer's contents. The client can store the change id for the text buffer at the time the client-specific model information was built to determine, at some later point in the future, whether the text buffer has changed by comparing the stored change id vs. the current change id of the text buffer.
Since possible numbers for the change id come from a finite set (set of int's
), the change id numbers may repeat once the set of int's
have been exhausted. Until the change id's loop over (repeat), clients are guaranteed that different change id's represent different buffer contents. Load/Save Notes:
This interface provides basic routines for reading and writing the data to and from a persistent storage area, such as a file system, database, network drive, and so on. Additionally, implementations will perform normalization on end-of-line (EOL) terminators such that buffers will contain only LF (\n) characters in memory to simplify the task of dealing with line ends for clients.
The EOL terminator recorded in the buffer is defined as the predominant or majority EOL terminator encountered while reading the data in through the read( Reader )
method. For newly created TextBuffer instances where this method is not called, the platform default EOL terminator will be used. In either case the assigned EOL terminator type will be used when saving the file using the write( Writer )
method.
When the file is read or saved, the modification status of the text buffer will be cleared.
Read-Only Mode Notes:
This interface provides support for marking the buffer as read-only programmatically to restrict modifications to the buffer. This may be useful for example, if the persistent data storage area is read-only.
To retrieve or change the read-only mode of the text buffer, use the setReadOnly()
or isReadOnly()
method calls.
If the buffer is in read-only mode, any attempts to acquire a write lock will result in a ReadOnlyException
to be thrown. This includes calling the following methods: beginEdit()
, writeLock()
insert()
, append()
, remove()
, removeToEnd()
, and setEOLType()
. The only exception is read()
which will reset the text buffer's read only status back to WRITABLE.
If there is an edit in progress (i.e., someone is holding the write lock), any attempts to change the buffer to read-only will block until the edit is complete.
Although the ReadOnlyException
is defined as a RuntimeException
(and need not be caught explicitly), implementations are encouraged to catch the exception for thoroughness, in addition to calling isReadOnly() first before attempting any modifications to the buffer.
ReadTextBuffer
, LineMap
, OffsetMark
Field Summary | |
---|---|
static java.lang.String |
EOL_CR Private constant for a single CR for an EOL terminator. |
static java.lang.String |
EOL_CRLF Private constant for CR/LF pair for an EOL terminator. |
static java.lang.String |
EOL_LF Private constant for a single LF for an EOL terminator. |
static java.lang.String |
EOL_MACINTOSH Private constant for EOL terminators used by Macintosh platforms. |
static java.lang.String |
EOL_UNIX Private constant for EOL terminators used by UNIX platforms. |
static java.lang.String |
EOL_WINDOWS Private constant for EOL terminators used by DOS or Windows platforms. |
static boolean |
READ_ONLY Public constant for use with setReadOnly() to mark the buffer as read only. |
static boolean |
WRITABLE Public constant for use with setReadOnly() to allow regular modifications to the buffer. |
Fields inherited from interface oracle.javatools.buffer.ReadTextBuffer |
---|
LOCK_STATUS_NONE, LOCK_STATUS_READ, LOCK_STATUS_UNSUPPORTED, LOCK_STATUS_WRITE |
Method Summary | |
---|---|
OffsetMark |
addOffsetMark(int offset) Create a new OffsetMark at the given location. |
OffsetMark |
addOffsetMark(int offset, boolean bias) Create a new OffsetMark at the given location. |
void |
addTextBufferListener(TextBufferListener listener) Registers the given observer to begin receiving notifications when changes are made to the text buffer either by an insert or remove. |
boolean |
addWriteLockRequestListener(WriteLockRequestListener listener) Add a write lock request listener on this text buffer. |
javax.swing.undo.UndoableEdit |
append(char[] data) Appends the indicated data into the text buffer at the end of the buffer. |
void |
beginEdit() Used to instruct to the text buffer to start a compound edit such that all the changes made between this point and when the endEdit() is called should be combined into a single UndoableEdit record. |
void |
clearModified() Clears the modification status of the buffer so that it indicates that it has not been modified. |
javax.swing.undo.UndoableEdit |
endEdit() Used to indicate to the text buffer to end an in progress compound edit. |
int |
getChangeId() Fetches a change, or incarnation, number that represents the current version of the buffer contents. |
java.lang.String |
getEOLType() Fetches the EOL terminator type found in the document when its data was read with read( Reader ) . |
LineMap |
getLineMap() Fetches a line map for the text buffer. |
java.lang.String |
getPlatformEOLType() Fetches the default EOL terminator type associated with this platform as defined by the 'line.separator' property in the system properties. |
javax.swing.undo.UndoableEdit |
insert(int offset, char[] data) Inserts the indicated data into the text buffer at the given offset. |
javax.swing.undo.UndoableEdit |
insert(int offset, java.io.Reader reader) Inserts the data from a Reader instance into the text buffer at the given offset. |
boolean |
isModified() Fetches whether the buffer has been modified since its modification flag was last reset. |
boolean |
isReadOnly() Fetches whether this TextBuffer is in read-only mode or not. |
void |
read(java.io.Reader reader) Replaces the current contents of the text buffer with the data from a reader instance. |
javax.swing.undo.UndoableEdit |
remove(int offset, int count) Removes a range of data from the text buffer. |
void |
removeOffsetMark(OffsetMark offsetMark) Remove an existing OffsetMark from the text buffer. |
void |
removeTextBufferListener(TextBufferListener listener) Unregisters the given observer from the notification list so that it will no longer receive change updates. |
javax.swing.undo.UndoableEdit |
removeToEnd(int offset) Removes data from the text buffer starting at the given offset to the end of the buffer. |
void |
removeWriteLockRequestListener(WriteLockRequestListener listener) Remove a write lock request listener from this text buffer. |
void |
setEOLType(java.lang.String eolType) Changes the EOL terminator type associated with this document to the type specified. |
void |
setReadOnly(boolean readOnly) Sets the read-only mode of this TextBuffer to the requested mode. |
boolean |
tryWriteLock() Attempts to acquire a write lock on this text buffer in a non-blocking manner. |
void |
write(java.io.Writer writer) Writes the current contents of the text buffer to a writer, and closes the writer. |
void |
write(java.io.Writer writer, boolean clearModified) Writes the current contents of the text buffer to a writer, and closes the writer. |
void |
writeLock() Attempts to acquire a write lock on this text buffer for the purposes of writing to the text buffer - this is a blocking call. |
void |
writeLock(boolean checkIfReadOnly) Attempts to acquire a write lock on this text buffer for the purposes of writing to the text buffer - this is a blocking call. |
void |
writeUnlock() Releases a held write lock on this text buffer. |
Methods inherited from interface oracle.javatools.buffer.ReadTextBuffer |
---|
getChar, getChars, getLength, getLockStatus, getString, getText, readLock, readUnlock, tryReadLock |
Field Detail |
---|
static final boolean READ_ONLY
setReadOnly()
to mark the buffer as read only.
static final boolean WRITABLE
setReadOnly()
to allow regular modifications to the buffer.
static final java.lang.String EOL_CRLF
static final java.lang.String EOL_WINDOWS
static final java.lang.String EOL_LF
static final java.lang.String EOL_UNIX
static final java.lang.String EOL_CR
static final java.lang.String EOL_MACINTOSH
Method Detail |
---|
void beginEdit() throws ReadOnlyException
endEdit()
is called should be combined into a single UndoableEdit record. This guarantees to the client that the buffer will be locked for the duration between beginEdit()
and endEdit()
for data consistency. This also takes care of locking the buffer, and collecting the individual UndoableEdit
objects into a larger compound one.
Note that compound edits may not be nested - it is illegal to call beginEdit()
twice in a row without calling endEdit()
in between.
ReadOnlyException
- if the buffer is in read only modeendEdit()
javax.swing.undo.UndoableEdit endEdit()
UndoableEdit
representing all of the changes made between the calls to beginEdit()
and endEdit()
. If no modifications were made to the buffer since beginEdit()
was called, null will be returned.beginEdit()
javax.swing.undo.UndoableEdit insert(int offset, char[] data) throws java.lang.IndexOutOfBoundsException, ReadOnlyException
insertUpdate()
. This will return an UndoableEdit representing this insert change unless a compound edit is in progress in which case null is returned.offset
- the offset at which to insert the new datadata
- the text to insertjava.lang.IndexOutOfBoundsException
- if offset is invalidReadOnlyException
- if the buffer is in read only modebeginEdit()
, endEdit()
, addTextBufferListener(oracle.javatools.buffer.TextBufferListener)
, removeTextBufferListener(oracle.javatools.buffer.TextBufferListener)
javax.swing.undo.UndoableEdit append(char[] data) throws java.lang.IndexOutOfBoundsException, ReadOnlyException
insertUpdate()
notification. The UndoableEdit representing this append will be returned unless a compound edit is in progress.data
- the text to insertReadOnlyException
- if the buffer is in read only modejava.lang.IndexOutOfBoundsException
- this exception is not expected as there are no offsets being passed. It is just to be consistent since internally, append just cals insert.insert(int, char[])
, beginEdit()
, endEdit()
, addTextBufferListener(oracle.javatools.buffer.TextBufferListener)
, removeTextBufferListener(oracle.javatools.buffer.TextBufferListener)
javax.swing.undo.UndoableEdit remove(int offset, int count) throws java.lang.IndexOutOfBoundsException, ReadOnlyException
removeUpdate()
. This will return an UndoableEdit representing this removal change unless a compound edit is in progress in which case null is returned.offset
- the offset at which to remove datacount
- number of characters to removejava.lang.IndexOutOfBoundsException
- if offset or count is invalidReadOnlyException
- if the buffer is in read only modebeginEdit()
, endEdit()
javax.swing.undo.UndoableEdit removeToEnd(int offset) throws java.lang.IndexOutOfBoundsException, ReadOnlyException
removeUpdate
notification. The UndoableEdit representing this removal will be returned unless a compound edit is in progress.offset
- the offset at which to remove datajava.lang.IndexOutOfBoundsException
- if offset is invalidReadOnlyException
- if the buffer is in read only moderemove(int, int)
, beginEdit()
, endEdit()
LineMap getLineMap()
void addTextBufferListener(TextBufferListener listener)
listener
- the observer to registerReadTextBuffer.readLock()
void removeTextBufferListener(TextBufferListener listener)
listener
- the observer to unregistervoid setReadOnly(boolean readOnly)
TextBuffer
to the requested mode.readOnly
- the new mode to set, READ_ONLY to mark as read-only, WRITABLE to allow modificationsboolean isReadOnly()
TextBuffer
is in read-only mode or not.void writeLock() throws ReadOnlyException
Clients may acquire a writeLock explicitly if they have multiple changes to make in the text buffer, to ensure that the changes will not be interleaved with another client's changes.
Note that this version of the writeLock() method will throw a ReadOnlyException if this method is called on a read only text buffer.
ReadOnlyException
- if the buffer is in read only modeReadTextBuffer.readLock()
void writeLock(boolean checkIfReadOnly) throws ReadOnlyException
Clients may acquire a writeLock explicitly if they have multiple changes to make in the text buffer, to ensure that the changes will not be interleaved with another client's changes.
This version of the writeLock() method takes a boolean parameter that controls whether or not an exception is thrown if you attempt to acquire a write lock on a read only text buffer. Note that in most cases, clients should pass true (or use the writeLock() method that takes no arguments) so that they are immediately notified that write operations will fail.
ReadOnlyException
- if the buffer is in read only mode and checkIfReadOnly is trueReadTextBuffer.readLock()
boolean tryWriteLock() throws ReadOnlyException
tryWriteLock()
(i.e., where it returns true) must be matched by a call to writeUnlock()
.ReadOnlyException
- if the buffer is in read only modewriteLock()
, ReadTextBuffer.tryReadLock()
void writeUnlock()
boolean addWriteLockRequestListener(WriteLockRequestListener listener)
listener
- the listener to be adddedtrue
if there are already other threads waiting for the write lock, false
otherwisejava.lang.NullPointerException
- if the listener is null
void removeWriteLockRequestListener(WriteLockRequestListener listener)
listener
- the listener to be removedjava.lang.NullPointerException
- if the listener is null
OffsetMark addOffsetMark(int offset)
OffsetMark
at the given location. This OffsetMark
will bias to the right of the given location.offset
- the offset to stick toOffsetMark
for tracking the offsetOffsetMark
, removeOffsetMark(oracle.javatools.buffer.OffsetMark)
OffsetMark addOffsetMark(int offset, boolean bias)
OffsetMark
at the given location. The bias can be either OffsetMark.BIAS_RIGHT
or OffsetMark.BIAS_LEFT
.offset
- the offset to stick tobias
- the side of the offset to bias or stick toOffsetMark
for tracking the offsetOffsetMark
, removeOffsetMark(oracle.javatools.buffer.OffsetMark)
void removeOffsetMark(OffsetMark offsetMark)
OffsetMark
from the text buffer. Since OffsetMarks
persist until they are removed explicitly, clients must remove OffsetMarks
they created to ensure proper resource release.offsetMark
- the mark to removeOffsetMark
, addOffsetMark(int)
boolean isModified()
void clearModified()
int getChangeId()
int's
is exhausted (at which point they may repeat.)void read(java.io.Reader reader) throws java.io.IOException
Note that this call will reset the read-only status of the text buffer back to WRITABLE.
reader
- a Reader instance from which to read text datajava.io.IOException
- as thrown by the stream if an error occurs while reading datajavax.swing.undo.UndoableEdit insert(int offset, java.io.Reader reader) throws java.lang.IndexOutOfBoundsException, java.io.IOException, ReadOnlyException
insertUpdate()
. This will return an UndoableEdit representing this insert change unless a compound edit is in progress in which case null is returned.offset
- the offset at which to insert the new datareader
- a Reader instance from which to read text datajava.lang.IndexOutOfBoundsException
- if offset is invalidReadOnlyException
- if the buffer is in read only modejava.io.IOException
- as thrown by the stream if an error occurs while reading databeginEdit()
, endEdit()
, addTextBufferListener(oracle.javatools.buffer.TextBufferListener)
, removeTextBufferListener(oracle.javatools.buffer.TextBufferListener)
void write(java.io.Writer writer) throws java.io.IOException
The modified state of the buffer is cleared. Clearing the modified state, if not already cleared, will safely take a write lock, which means that if the caller of this method holds a read lock, that read lock will be released and reacquired during the execution of this method.
writer
- a Writer
to which to write buffer contents.java.io.IOException
- if the write throws IOException.void write(java.io.Writer writer, boolean clearModified) throws java.io.IOException
If the buffer state needs to be cleared, this method will safely take a write lock, which means that if the caller of this method holds a read lock, that read lock will be released and reacquired during the execution of this method.
writer
- a Writer
to which to write buffer contents.clearModified
- whether to clear the modified state of the buffer.java.io.IOException
- if the write throws IOException.java.lang.String getPlatformEOLType()
java.lang.String getEOLType()
read( Reader )
. The default EOL terminator is defined as the predominant (majority) terminator used in the document.void setEOLType(java.lang.String eolType) throws ReadOnlyException
eolType
- the EOL terminator type to useReadOnlyException
- if the buffer is in read only mode
|
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference 11g Release 1 (11.1.1.7.2) E13403-10 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |