Extension SDK 10.1.2

oracle.ide.model
Class TextNode

java.lang.Object
  extended byoracle.ide.model.DefaultDisplayable
      extended byoracle.ide.model.DefaultElement
          extended byoracle.ide.model.DefaultDocument
              extended byoracle.ide.model.DefaultNode
                  extended byoracle.ide.model.TextNode
All Implemented Interfaces:
Category, Data, Dirtyable, Displayable, Document, Element, LazyLoadable, Locatable, Node, Subject, TextDocument, WeakDataHolder
Direct Known Subclasses:
DeployableTextNode

public class TextNode
extends DefaultNode
implements TextDocument, WeakDataHolder

The TextNode class extends DefaultNodeand should be used for all objects that can be opened as a text file inside a code editor.

See Also:
TextDocument

Field Summary
 
Fields inherited from interface oracle.ide.addin.Subject
OBJECT_MODIFIED
 
Fields inherited from interface oracle.ide.model.Category
UNDEFINED
 
Constructor Summary
TextNode()
           
TextNode(java.net.URL url)
           
 
Method Summary
 TextBuffer acquireTextBuffer()
          Requests the data from the Document in the format of a TextBuffer instance so that it can be used by the code editor.
 void close()
          Empties the current TextBuffer and calls setOpen(false).
protected  java.io.Reader createReader(java.net.URL url)
           
protected  void dataExpired()
          Cleanup any meta data based on the underlying TextBuffer.
 void dataExpired(WeakDataReference reference)
          Respond to our TextBuffer being garbage collected.
 java.io.InputStream getInputStream()
          Deprecated.  
 java.io.InputStream getInputStream(boolean warn)
          Deprecated.  
protected  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 reopen()).
 java.io.Reader getReader()
           
protected  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()
          Directly gets the TextBuffer.
protected  TextBuffer getTextBufferDirectly(boolean force)
          Directly gets the TextBuffer.
 boolean hasEmptyTextBuffer()
           
 boolean isDirty()
          First checks if the superclass has its dirty flag set; if so, returns true.
 boolean isExpired()
          Determine whether or not our TextBuffer has been garbage collected.
 boolean isReadOnly()
          Part of Document interface.
 void markDirty(boolean dirty)
          Two things happen: The superclass markDirty(dirty) method is called.
 void open()
          Document method.
 void releaseTextBuffer()
          Informs the document that the previously acquired TextBuffer instance is no longer needed.
 void removeTextBufferListener(TextBufferListener listener)
          Informs the TextBuffer that the given listener no longer needs to track it.
 void reopen()
          This method reloads the contents of the Document from the current URL into a TextBuffer.
 void save(boolean shallow)
          Saves the contents of the current TextBuffer to the location specified by the current URL.
protected  void setDefaultLineTerminator(TextBuffer textBuffer)
          Sets up the default line terminator to use for the text buffer.
protected  void setTextBufferDirectly(TextBuffer textBuffer)
          Direclty sets the TextBuffer.
protected  void updateReadOnlyFlag(boolean readOnly)
          In general, this method should only be used by the TextNode class itself or any subclasses that need to override TextNode behavior. This method modifies the read-only flag of the underlying TextBuffer.
 
Methods inherited from class oracle.ide.model.DefaultNode
equalsImpl, getCategory, setURL
 
Methods inherited from class oracle.ide.model.DefaultDocument
attach, copyToImpl, createSubject, detach, ensureOpen, equalsImpl, getLongLabel, getShortLabel, getSubject, getTimestamp, getTimestampDirectly, getToolTipText, getURL, isNew, isOpen, notifyObservers, refreshTimestamp, setOpen, setTimestampDirectly, setURLDirectly
 
Methods inherited from class oracle.ide.model.DefaultElement
getAttributes, getChildren, getData, mayHaveChildren
 
Methods inherited from class oracle.ide.model.DefaultDisplayable
getIcon, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface oracle.ide.model.Document
getTimestamp, isNew
 
Methods inherited from interface oracle.ide.model.Locatable
getURL, setURL
 
Methods inherited from interface oracle.ide.model.Element
getAttributes, getChildren, mayHaveChildren
 
Methods inherited from interface oracle.ide.model.Data
getData
 
Methods inherited from interface oracle.ide.model.Displayable
getIcon, getLongLabel, getShortLabel, getToolTipText, toString
 
Methods inherited from interface oracle.ide.addin.Subject
attach, detach, notifyObservers
 
Methods inherited from interface oracle.ide.model.LazyLoadable
isOpen
 

Constructor Detail

TextNode

public TextNode()

TextNode

public TextNode(java.net.URL url)
Method Detail

isDirty

public boolean isDirty()
First checks if the superclass has its dirty flag set; if so, returns true. Otherwise, the determination of the dirty state is delegated to the underlying TextBuffer implementation. If the current TextBuffer is null, false is returned.

Specified by:
isDirty in interface Dirtyable
Overrides:
isDirty in class DefaultDocument

markDirty

public void markDirty(boolean dirty)
Two things happen:
  1. The superclass markDirty(dirty) method is called.
  2. If the dirty parameter is false, the modified state of the underlying TextBuffer is cleared.

Specified by:
markDirty in interface Dirtyable
Overrides:
markDirty in class DefaultDocument

reopen

public void reopen()
This method reloads the contents of the Document from the current URL into a TextBuffer.


open

public void open()
Document method. This implementation first checks if the document is already open. If it is not open, then the task of opening the document is delegated to reopen().

Specified by:
open in interface Document
Overrides:
open in class DefaultDocument
See Also:
Document.open()

close

public void close()
Empties the current TextBuffer and calls setOpen(false). The contents of the TextBuffer are not saved.

Specified by:
close in interface Document
Overrides:
close in class DefaultDocument
See Also:
Document.close()

setDefaultLineTerminator

protected void setDefaultLineTerminator(TextBuffer textBuffer)
Sets up the default line terminator to use for the text buffer. Note that the TextNode will still use the regular behavior of maintaining the EOL for existing files.


save

public void save(boolean shallow)
          throws java.io.IOException
Saves the contents of the current TextBuffer to the location specified by the current URL.

Specified by:
save in interface Document
Overrides:
save in class DefaultDocument
Throws:
java.io.IOException
See Also:
Document.save(boolean)

isReadOnly

public boolean isReadOnly()
Part of Document interface. This implementation delegates to the URLFileSystem to determine whether or not this document is read-only.

We override this here in order to force the underlying buffer to be read only.

Specified by:
isReadOnly in interface Document
Overrides:
isReadOnly in class DefaultDocument
See Also:
Document.isReadOnly()

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Deprecated.  

NOTE: Use of TextNode.getInputStream() is highly discouraged because of the NLS issues raised by using byte streams for text and the associated poor performance caused by char-to-byte conversion. Use TextNode.getReader() instead whenever possible.

Returns an InputStream that's backed by the current TextBuffer.

Specified by:
getInputStream in interface Document
Overrides:
getInputStream in class DefaultDocument
Throws:
java.lang.IllegalStateException - if the current TextBuffer is null.
java.io.IOException - if an I/O error occurs when trying to open the InputStream.
See Also:
Document.getInputStream()

getInputStream

public java.io.InputStream getInputStream(boolean warn)
                                   throws java.io.IOException
Deprecated.  

NOTE: Use of TextNode.getInputStream() is highly discouraged because of the NLS issues raised by using byte streams for text and the associated poor performance caused by char-to-byte conversion. Use TextNode.getReader() instead whenever possible.

Returns an InputStream that's backed by the current TextBuffer.

Throws:
java.lang.IllegalStateException - if the current TextBuffer is null.
java.io.IOException

acquireTextBuffer

public TextBuffer acquireTextBuffer()
Requests the data from the Document in the format of a TextBuffer instance so that it can be used by the code editor. Note that the acquisition and release of TextBuffer instances are reference counted - this is to allow TextDocument implementations the freedom to drop the use of the TextBuffer instance when it is no longer needed and revert to a more "compressed" form of storage.

Specified by:
acquireTextBuffer in interface TextDocument
Returns:
the TextBuffer instance for accessing this Document in text form

releaseTextBuffer

public void releaseTextBuffer()
Informs the document that the previously acquired TextBuffer instance is no longer needed. This frees up the need for the Document to maintain the TextBuffer instance.

Specified by:
releaseTextBuffer in interface TextDocument

removeTextBufferListener

public void removeTextBufferListener(TextBufferListener listener)
Informs the TextBuffer that the given listener no longer needs to track it. This helps us avoid the situation where the TextBuffer might have been GC'd, and we want to avoid having to acquire the TextBuffer (and reloading it, potentially from network storage) in order to remove the TextBufferListener.

Parameters:
listener - the text buffer listener

dataExpired

public final void dataExpired(WeakDataReference reference)
Respond to our TextBuffer being garbage collected. We verify that the WeakDataReference received as argument matches the result of getTextBufferDirectly(false) before assuming that it is the _current_ TextBuffer that was GC'd, as opposed to one that we have since replaced on the fly.

Specified by:
dataExpired in interface WeakDataHolder
Parameters:
reference - WeakDataReference holding our TextBuffer

dataExpired

protected void dataExpired()
Cleanup any meta data based on the underlying TextBuffer. When called as a result of garbage collection, Subclasses can safely assume that the data collected was in fact the current TextBuffer and not a stale reference that has since been replaced on the fly.


isExpired

public boolean isExpired()
Determine whether or not our TextBuffer has been garbage collected.

Specified by:
isExpired in interface WeakDataHolder
Returns:
true when the TextNode is null while in an open state.

getReader

public java.io.Reader getReader()
                         throws java.io.IOException
Throws:
java.io.IOException

hasEmptyTextBuffer

public boolean hasEmptyTextBuffer()

getTextBufferDirectly

protected TextBuffer getTextBufferDirectly()
Directly gets the TextBuffer. This method is primarily intended for subclass customization of TextNode.


getTextBufferDirectly

protected TextBuffer getTextBufferDirectly(boolean force)
Directly gets the TextBuffer. This method is primarily intended for subclass customization of TextNode.


setTextBufferDirectly

protected void setTextBufferDirectly(TextBuffer textBuffer)
Direclty sets the TextBuffer. This method is primarily intended for subclass customization of TextNode.


updateReadOnlyFlag

protected void updateReadOnlyFlag(boolean readOnly)
In general, this method should only be used by the TextNode class itself or any subclasses that need to override TextNode behavior. This method modifies the read-only flag of the underlying TextBuffer.


getLoadEncoding

protected 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 reopen()). The base implementation returns the IDE default encoding, however subclasses (like XMLSourceNode) may override this with a different encoding determined from the URL data

Returns:
a Java supported encoding name for reading

getSaveEncoding

protected 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()). The base implementation returns the IDE default encoding, subclasses (like XMLSourceNode) may override this with a different encoding determined from the TextBuffer data

Returns:
a Java supported encoding name for writing

createReader

protected java.io.Reader createReader(java.net.URL url)
                               throws java.io.IOException
Throws:
java.io.IOException

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.