An abstract base implementation for the Document interface.
This class provides some common functionality for all Elements,
most notably it implements a locking mechanism to make document modification
thread-safe.
Creates and returns a branch element with the specified
parent and attributes. Note that the new
Element is linked to the parent Element
through Element.getParentElement(), but it is not yet added
to the parent Element as child.
Parameters:
parent - the parent Element for the new branch element
attributes - the text attributes to be installed in the new element
Creates and returns a leaf element with the specified
parent and attributes. Note that the new
Element is linked to the parent Element
through Element.getParentElement(), but it is not yet added
to the parent Element as child.
Parameters:
parent - the parent Element for the new branch element
attributes - the text attributes to be installed in the new element
Returns the thread that currently modifies this Document
if there is one, otherwise null. This can be used to
distinguish between a method call that is part of an ongoing modification
or if it is a separate modification for which a new lock must be aquired.
Returns:
the thread that currently modifies this Document
if there is one, otherwise null
Returns the default root Element of this Document.
Usual Documents only have one root element and return this.
However, there may be Document implementations that
support multiple root elements, they have to return a default root element
here.
Returns all root elements of this Document. By default
this just returns the single root element returned by
getDefaultRootElement(). Document implementations
that support multiple roots must override this method and return all roots
here.
Inserts a String into this Document at the specified
position and assigning the specified attributes to it.
If a DocumentFilter is installed in this document, the
corresponding method of the filter object is called.
The method has no effect when text is null
or has a length of zero.
Called to indicate that text has been inserted into this
Document. The default implementation does nothing.
This method is executed within a write lock.
Parameters:
chng - the DefaultDocumentEvent describing the change
Removes a piece of content from this Document.
If a DocumentFilter is installed in this document, the
corresponding method of the filter object is called. The
DocumentFilter is called even if length
is zero. This is different from replace(int,int,String,AttributeSet).
Note: When length is zero or below the call is not
forwarded to the underlying AbstractDocument.Content instance
of this document and no exception is thrown.
Called before some content gets removed from this Document.
The default implementation does nothing but may be overridden by
subclasses to modify the Document structure in response
to a remove request. The method is executed within a write lock.
Parameters:
chng - the DefaultDocumentEvent describing the change
Called to render this Document visually. It obtains a read
lock, ensuring that no changes will be made to the document
during the rendering process. It then calls the Runnable.run()
method on runnable. This method must not attempt
to modifiy the Document, since a deadlock will occur if it
tries to obtain a write lock. When the Runnable.run() method
completes (either naturally or by throwing an exception), the read lock
is released. Note that there is nothing in this method related to
the actual rendering. It could be used to execute arbitrary code within
a read lock.
Replaces a piece of content in this Document with
another piece of content.
If a DocumentFilter is installed in this document, the
corresponding method of the filter object is called.
The method has no effect if length is zero (and
only zero) and, at the same time, text is
null or has zero length.
Parameters:
offset - the start offset of the fragment to be removed
length - the length of the fragment to be removed
text - the text to replace the content with
attributes - the text attributes to assign to the new content
Throws:
BadLocationException - if offset or
offset + length or invalid locations within this
document
Releases the write lock. This allows waiting readers or writers to
obtain the lock.
AbstractDocument.java --
Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.