|
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference 11g Release 1 (11.1.1.7.0) E13403-08 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object oracle.ide.model.Node oracle.ide.model.TextNode
public class TextNode
A base class for Node
s representing text files.
Locking
Node uses a ReadWriteLock
to protect most of its state; TextNode uses the same lock to protect its state, including its text
content.
Memory Management
{@link TextNode} must avoid avoid pinning large numbers of
{@link TextBuffer}s, holding large amounts of character data, in memory. The
chosen mechanism is to automatically close a node, releasing the text
buffer, as soon as all clients using it have dropped their references. Doing
this requires some trickery: TextNode never dispenses the real text buffer,
but instead dispenses a facade which it holds only with a weak reference,
and polls the reference queue to detect when the facade is garbage collected.
When this happens, the node is closed and node closed events are fired. When
the node is dirty, this mechanism is disabled.
Field Summary |
---|
Fields inherited from class oracle.ide.model.Node |
---|
LOG_READONLY |
Constructor Summary | |
---|---|
TextNode()
Creates a text node with an undefined URL. |
|
TextNode(java.net.URL url)
Creates a text node. |
Method Summary | |
---|---|
TextBuffer |
acquireTextBuffer()
Gets a TextBuffer with the content of this node, or null if the
content cannot be loaded. |
TextBuffer |
acquireTextBufferOrThrow()
Gets a TextBuffer with the content of this node. |
boolean |
addTextBufferListener(TextBufferListener listener)
Adds a text buffer listener to the text buffer of this node whether or not the node is open. |
protected void |
closeImpl()
Subclasses should override this method to customize the close() behavior. |
protected java.io.OutputStreamWriter |
createOutputStreamWriter(java.io.OutputStream outStream)
|
protected java.io.Reader |
createReader(java.net.URL url)
Fetch a Reader for reading the contents of this node from the given URL. |
java.io.InputStream |
getInputStream()
Deprecated. |
java.io.InputStream |
getInputStream(boolean warn)
Deprecated. |
java.lang.String |
getLoadEncoding()
Returns a Java supported encoding name to use to create the InputStreamReader for reading data from the URL into the TextBuffer (called from revert()). |
java.io.Reader |
getReader()
Fetch a Reader for accessing the buffer contents of this TextNode. |
java.lang.String |
getSaveEncoding()
Returns a Java supported encoding name to use to create the OutputStreamWriter for writing the TextBuffer to a file (called from save()). |
protected TextBuffer |
getTextBufferDirectly()
Gets the text buffer if the node is open, or null if not. |
boolean |
hasEmptyTextBuffer()
Gets whether the TextBuffer for this TextNode is empty. |
boolean |
isDirty()
First checks if the superclass has its dirty flag set; if so, returns true . |
boolean |
isReadOnly()
Returns true if the Node is read-only. |
void |
markDirty(boolean dirty)
Marks the data with the specified dirty state. |
protected void |
markDirtyImpl(boolean dirty)
Subclasses should override this method to customize the markDirty() behavior. |
protected void |
openImpl()
Subclasses should override this method to customize the open() behavior. |
protected void |
readUnlock()
Read unlocks the node for the current thread. |
void |
releaseTextBuffer()
Informs the document that the previously acquired TextBuffer instance is no longer needed. |
void |
removeTextBufferListener(TextBufferListener listener)
Removes a text buffer listener from the text buffer of this node. |
protected void |
reportOpenException(java.lang.Exception e)
This routine is given a chance to handle or report an Exception that occurred during open(). |
protected void |
revertImpl()
Subclasses should override this method to customize the revert() behavior. |
protected void |
saveImpl()
Subclasses should override this method to customize the save() behavior. |
protected void |
setDefaultLineTerminator(TextBuffer textBuffer)
Sets up the default line terminator to use for the text buffer. |
void |
setLoadEncoding(java.lang.String loadEncoding)
Sets a Java supported encoding name to use to create the InputStreamReader for reading data from the URL into the TextBuffer (called from revert()). |
void |
setSaveEncoding(java.lang.String saveEncoding)
Sets a Java supported encoding name to use to create the OutputStreamWriter for writing the TextBuffer to a file (called from save()). |
TextBuffer |
tryAcquireTextBuffer()
Non-blocking version of acquireTextBuffer() . |
protected void |
upgradeUnlock()
Write locks the node for the current thread. |
protected void |
urlReadOnlyChanged()
Reports that the read-only state of the URL of this node changed. |
protected void |
writeUnlock()
Read unlocks the node for the current thread. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TextNode()
public TextNode(java.net.URL url)
url
- The URL
of the file represented by this node. The URL
need not represent an existing file.Method Detail |
---|
protected void readUnlock()
The Node
implementation invokes readUnlock()
on the
node lock.
Overridden to clear facadeBuffer
when the node is not dirty and
the current thread releases its last lock.
readUnlock
in class Node
protected void writeUnlock()
The Node
implementation invokes writeUnlock()
on
the node lock.
Overridden to clear facadeBuffer
when the node is not dirty and
the current thread releases its last lock.
writeUnlock
in class Node
protected void upgradeUnlock()
writeLock();
try
{
// access and/or update protected state...
}
finally
{
writeUnlock();
}
Note that a number of Node
extensions points are called with a
read or write lock held, and are so documented.
Overridden to clear facadeBuffer
when the node is not dirty and
the current thread releases its last lock.
upgradeUnlock
in class Node
protected void urlReadOnlyChanged()
Node
Node
implementation is empty.
urlReadOnlyChanged
in class Node
public boolean isReadOnly()
true
if the Node is read-only.
TextNode
overrides to force the underlying buffer to be read only.
isReadOnly
in class Node
Node.isReadOnly()
public boolean isDirty()
true
. Otherwise, the determination of
the dirty state is delegated to the underlying TextBuffer
implementation. If the current TextBuffer
is
null
, false
is returned.
isDirty
in interface Dirtyable
isDirty
in class Node
true
if the data in the object has been modified.public void markDirty(boolean dirty)
Dirtyable
markDirty(...)
instead of
setDirty(...)
so that the JavaBeans
Introspector
will not
mistakenly identify "dirty" as a JavaBean property.
markDirty
in interface Dirtyable
markDirty
in class Node
dirty
- If true
, sets the object as being
dirty; if false
, sets the object as being up-to-date.protected void markDirtyImpl(boolean dirty)
Node.markDirty(boolean)
invokes this only if the dirty state is
changing, under write lock. The Node
implementation does nothing.
The TextNode
implementation clears the modified
property of the text buffer if the node is open and the dirty state is
cleared.
markDirtyImpl
in class Node
protected void openImpl() throws java.io.IOException
Node
Node.open()
invokes this only if the node is not open, under
write lock. The Node
implementation does nothing.
openImpl
in class Node
java.io.IOException
- if an I/O error occurred while openingprotected void closeImpl() throws java.io.IOException
Node
Node.close()
invokes this only if the node is open, under
write lock. The Node
implementation does nothing.
closeImpl
in class Node
java.io.IOException
- if an I/O error occurred while closingprotected void saveImpl() throws java.io.IOException
Node
Node.save()
invokes this only if the node is dirty, under
write lock. The Node
implementation does nothing.
saveImpl
in class Node
java.io.IOException
- if an I/O error occurred while savingprotected void revertImpl() throws java.io.IOException
Node
Node.revert()
invokes this only if the node is dirty, under
write lock. The Node
implementation invokes Node.closeImpl()
followed by Node.openImpl()
.
revertImpl
in class Node
java.io.IOException
- if an I/O error occurred while revertingprotected void setDefaultLineTerminator(TextBuffer textBuffer)
textBuffer
- the text buffer that backs up the contents
of this nodepublic final TextBuffer acquireTextBuffer()
TextBuffer
with the content of this node, or null if the
content cannot be loaded.
public final TextBuffer acquireTextBufferOrThrow() throws java.io.IOException
TextBuffer
with the content of this node.
java.io.IOException
- if the content cannot be loaded.public final TextBuffer tryAcquireTextBuffer()
acquireTextBuffer()
. Returns null
immediately if the buffer cannot be obtained without blocking.
public final void releaseTextBuffer()
protected TextBuffer getTextBufferDirectly()
public boolean addTextBufferListener(TextBufferListener listener)
Be aware that all text buffer listeners are cleared when the node is closed. Typically, a client using this method from outside of a NodeListener should already have added a NodeListener that will add this text buffer listener on node opened (possibly redundantly).
Also be aware that if the node is not open and never gets opened, the text buffer listeners will never be cleared. Typically, a client using this method when the node may be closed will protect itself against leaking the listener by explicitly removing this text buffer listener as soon as it is no longer needed.
listener
- The text buffer listener.
java.lang.IllegalArgumentException
- if the listener is null.public void removeTextBufferListener(TextBufferListener listener)
listener
- The text buffer listener.
java.lang.IllegalArgumentException
- if the listener is null.public java.io.Reader getReader() throws java.io.IOException
java.io.IOException
public boolean hasEmptyTextBuffer()
public java.lang.String getLoadEncoding()
public java.lang.String getSaveEncoding()
public void setLoadEncoding(java.lang.String loadEncoding)
getLoadEncoding()
with a different encoding
determined from the TextBuffer data
loadEncoding
- a Java supported encoding name for readingpublic void setSaveEncoding(java.lang.String saveEncoding)
getSaveEncoding()
with a different encoding determined from the TextBuffer data
saveEncoding
- a Java supported encoding name for writingprotected java.io.Reader createReader(java.net.URL url) throws java.io.IOException
url
- the URL to fetch a Reader for
java.io.IOException
protected java.io.OutputStreamWriter createOutputStreamWriter(java.io.OutputStream outStream) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public java.io.InputStream getInputStream() throws java.io.IOException
InputStream
that's backed by the current
TextBuffer
.
getInputStream
in class Node
InputStream
, or null
if the
document has no contents.
java.lang.IllegalStateException
- if the current
TextBuffer
is null
.
java.net.UnknownServiceException
- if the
URL
's protocol does not support input.
java.io.IOException
- if an I/O error occurs when trying to open
the InputStream
.public java.io.InputStream getInputStream(boolean warn) throws java.io.IOException
InputStream
that's backed by the current
TextBuffer
.
java.lang.IllegalStateException
- if the current
TextBuffer
is null
.
java.io.IOException
protected void reportOpenException(java.lang.Exception e)
reportOpenException
in class Node
|
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference 11g Release 1 (11.1.1.7.0) E13403-08 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |