org.apache.batik.dom.svg

Class AbstractSVGList

public abstract class AbstractSVGList extends Object

This class is a base implementation for a live list representation of SVG attributes.

This class provides support for an SVG list representation of an attribute. It implements basic list functionality that is common to all of the SVG*List interfaces.

For a specific attribute, it requires an {@link #getValueAsString() attribute value}, a {@link #doParse(String,ListHandler) parser}, and a method to {@link #createSVGItem(Object) create items}.

Whenever the attribute changes outside of the control of the list, this list must be {@link #invalidate invalidated}.

Nested Class Summary
protected classAbstractSVGList.ListBuilder
A class for receiving notification of parsed list items.
Field Summary
protected ListitemList
The list of items.
protected booleanvalid
Whether this list is valid.
Method Summary
protected SVGItemappendItemImpl(Object newItem)
Inserts a new item at the end of the list.
protected abstract voidcheckItemType(Object newItem)
Asserts that the given object is an appropriate SVG object for this list.
voidclear()
Removes all items from the list.
protected voidclear(List list)
Clears the list and sets the parent of the former list items to null.
protected abstract DOMExceptioncreateDOMException(short type, String key, Object[] args)
Create a DOM Exception.
protected abstract SVGItemcreateSVGItem(Object newItem)
Creates an {@link SVGItem} object that has the same values as those in the specified SVG object.
protected abstract voiddoParse(String value, ListHandler builder)
Parses the given attribute value and informs the specified {@link ListHandler} of the parsed list items.
protected SVGItemgetItemImpl(int index)
Returns the item from the list at the specified index.
protected abstract StringgetItemSeparator()
Returns the separator string to use when constructing a string representation of the entire list.
intgetNumberOfItems()
Returns the number of items in the list.
protected abstract StringgetValueAsString()
Returns the value of the DOM attribute containing the list.
protected SVGIteminitializeImpl(Object newItem)
Removes all items from the list and adds the specified item to the list.
protected SVGIteminsertItemBeforeImpl(Object newItem, int index)
Inserts a new item into the list at the specified position.
voidinvalidate()
Invalidates this list.
voiditemChanged()
Method to be called by a member {@link SVGItem} object when its value changes.
protected SVGItemremoveIfNeeded(Object newItem)
Removes the specified object from its parent list if it is an item, or creates a new item if the specified object is not an item.
protected voidremoveItem(SVGItem item)
Removes an item from the list.
protected SVGItemremoveItemImpl(int index)
Removes an existing item from the list.
protected SVGItemreplaceItemImpl(Object newItem, int index)
Replaces an existing item in the list with a new item.
protected voidresetAttribute()
Resets the value of the associated attribute.
protected voidresetAttribute(SVGItem item)
Appends the string representation of the given {@link SVGItem} to the DOM attribute.
protected voidrevalidate()
Initializes the list, if needed.
protected abstract voidsetAttributeValue(String value)
Sets the DOM attribute value containing the number list.
protected voidsetValueAsString(List value)
Sets the DOM attribute value to be the string representation of the given list.

Field Detail

itemList

protected List itemList
The list of items.

valid

protected boolean valid
Whether this list is valid.

Method Detail

appendItemImpl

protected SVGItem appendItemImpl(Object newItem)
Inserts a new item at the end of the list. If newItem is already in a list, it is removed from its previous list before it is inserted into this list.

Parameters: newItem The item which is to be inserted into the list. The first item is number 0.

Returns: The inserted item.

Throws: DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified. SVGException SVG_WRONG_TYPE_ERR: Raised if parameter newItem is the wrong type of object for the given list.

checkItemType

protected abstract void checkItemType(Object newItem)
Asserts that the given object is an appropriate SVG object for this list.

clear

public void clear()
Removes all items from the list.

Throws: DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified.

clear

protected void clear(List list)
Clears the list and sets the parent of the former list items to null.

createDOMException

protected abstract DOMException createDOMException(short type, String key, Object[] args)
Create a DOM Exception.

createSVGItem

protected abstract SVGItem createSVGItem(Object newItem)
Creates an {@link SVGItem} object that has the same values as those in the specified SVG object.

Parameters: newItem the SVG object

Returns: the newly created {@link SVGItem} object

doParse

protected abstract void doParse(String value, ListHandler builder)
Parses the given attribute value and informs the specified {@link ListHandler} of the parsed list items.

Parameters: value the attribute value to be parsed builder the object to be informed of the parsed list items

getItemImpl

protected SVGItem getItemImpl(int index)
Returns the item from the list at the specified index.

Parameters: index The index of the item from the list which is to be returned. The first item is number 0.

Returns: The selected item.

Throws: DOMException INDEX_SIZE_ERR: Raised if the index number is negative or greater than or equal to numberOfItems.

getItemSeparator

protected abstract String getItemSeparator()
Returns the separator string to use when constructing a string representation of the entire list.

getNumberOfItems

public int getNumberOfItems()
Returns the number of items in the list.

getValueAsString

protected abstract String getValueAsString()
Returns the value of the DOM attribute containing the list.

initializeImpl

protected SVGItem initializeImpl(Object newItem)
Removes all items from the list and adds the specified item to the list.

Parameters: newItem the item which should become the only member of the list.

Returns: the item being inserted into the list.

Throws: DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified. SVGException SVG_WRONG_TYPE_ERR: Raised if parameter newItem is the wrong type of object for the given list.

insertItemBeforeImpl

protected SVGItem insertItemBeforeImpl(Object newItem, int index)
Inserts a new item into the list at the specified position.

The first item is number 0. If newItem is already in a list, it is removed from its previous list before it is inserted into this list.

Parameters: newItem The item which is to be inserted into the list. index The index of the item before which the new item is to be inserted. The first item is number 0. If the index is equal to 0, then the new item is inserted at the front of the list. If the index is greater than or equal to numberOfItems, then the new item is appended to the end of the list.

Returns: The inserted item.

Throws: DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified. SVGException SVG_WRONG_TYPE_ERR: Raised if parameter newItem is the wrong type of object for the given list.

invalidate

public void invalidate()
Invalidates this list.

itemChanged

public void itemChanged()
Method to be called by a member {@link SVGItem} object when its value changes. This causes the DOM attribute to be reset.

removeIfNeeded

protected SVGItem removeIfNeeded(Object newItem)
Removes the specified object from its parent list if it is an item, or creates a new item if the specified object is not an item.

Parameters: newItem an instance of {@link SVGItem} to remove from its parent list, or an SVG object for which a new {@link SVGItem} should be created

Returns: item the {@link SVGItem} just removed from its parent list, or the newly created {@link SVGItem}

removeItem

protected void removeItem(SVGItem item)
Removes an item from the list. This operation takes place when an item was already in one list and is being added to another one.

removeItemImpl

protected SVGItem removeItemImpl(int index)
Removes an existing item from the list.

Parameters: index The index of the item which is to be removed. The first item is number 0.

Returns: The removed item.

Throws: DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified. DOMException INDEX_SIZE_ERR: Raised if the index number is negative or greater than or equal to numberOfItems.

replaceItemImpl

protected SVGItem replaceItemImpl(Object newItem, int index)
Replaces an existing item in the list with a new item.

If newItem is already in a list, it is removed from its previous list before it is inserted into this list.

Parameters: newItem The item which is to be inserted into the list. index The index of the item which is to be replaced. The first item is number 0.

Returns: The inserted item.

Throws: DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the list cannot be modified. DOMException INDEX_SIZE_ERR: Raised if the index number is negative or greater than or equal to numberOfItems. SVGException SVG_WRONG_TYPE_ERR: Raised if parameter newItem is the wrong type of object for the given list.

resetAttribute

protected void resetAttribute()
Resets the value of the associated attribute.

resetAttribute

protected void resetAttribute(SVGItem item)
Appends the string representation of the given {@link SVGItem} to the DOM attribute. This is called in response to an append to the list.

revalidate

protected void revalidate()
Initializes the list, if needed.

setAttributeValue

protected abstract void setAttributeValue(String value)
Sets the DOM attribute value containing the number list.

Parameters: value the String representation of the list, or null if the list contains no items

setValueAsString

protected void setValueAsString(List value)
Sets the DOM attribute value to be the string representation of the given list.
Copyright B) 2007 Apache Software Foundation. All Rights Reserved.