sk.uniba.euromath.document.schema.impl.iterator
Class SchemaLevelNodeIterator

java.lang.Object
  extended by sk.uniba.euromath.document.schema.impl.iterator.SchemaLevelNodeIterator
All Implemented Interfaces:
Iterable<ContentInfo>, Iterator<ContentInfo>, ListIterator<ContentInfo>

public class SchemaLevelNodeIterator
extends Object
implements ListIterator<ContentInfo>, Iterable<ContentInfo>

Iterator over insert point infos (instances of ContentInfo class). Insert point is a point between two adjacent nodes, where a new element/elements can be inserted. Does not support modification operations.

Only Text(CDATASection) and Element are generating element's content. Thus, only InsertPoint s pointing to such nodes are returned. Returned string may span over multiple Text and/or CDATASection nodes. That is because text value is a string between two adjacent elements.

Every returned insertpoint must point to a validable node, or it can have value of [nodes.getLength(), 0].

Warning: given NodeList must NOT be changed during process of iteration.

Author:
Martin Vysny

Field Summary
protected  int act
          Iterator is now standing before this item - this insertpoint will be returned by the next() call.
protected  List<ContentInfo> items
          Contains set of ContentInfos, computed from given nodeset.
 boolean lastEmptyItem
          If true then last item is a pointer that points after the last node.
 Node parent
          The parent of the children over which the iteration occurs.
 
Constructor Summary
protected SchemaLevelNodeIterator(Collection<ContentInfo> contentInfos, Node parent)
          Constructs an iterator from given collection of ContentInfo objects.
 
Method Summary
 void add(ContentInfo o)
           
protected  int getActIP()
          Returns actual index to items array, that will be returned by next call to next().
 SchemaLevelNodeIterator getChildIterator(Element e)
          Returns a child iterator for given element.
 SchemaLevelNodeIterator getClone()
          Clones the iterator.
 sk.baka.ikslibs.ptr.DomPointer getEquivalent(sk.baka.ikslibs.ptr.DomPointer ptr)
          Returns an DOMPointer that is equal to some pointer in the list, and inserting an element/text at given ip is equivalent to inserting the node at returned pointer.
 boolean hasNext()
           
 boolean hasPrevious()
           
 Iterator<ContentInfo> iterator()
           
 ContentInfo next()
           
 int nextIndex()
           
 ContentInfo previous()
           
 int previousIndex()
           
 void remove()
           
 void set(ContentInfo o)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

items

protected final List<ContentInfo> items
Contains set of ContentInfos, computed from given nodeset. When text spans over multiple text/cdata nodes, then pointer points to first such node.


lastEmptyItem

public final boolean lastEmptyItem
If true then last item is a pointer that points after the last node.


act

protected int act
Iterator is now standing before this item - this insertpoint will be returned by the next() call.


parent

public final Node parent
The parent of the children over which the iteration occurs. Serves only for informational purposes - displayed by the validator on error only.

Constructor Detail

SchemaLevelNodeIterator

protected SchemaLevelNodeIterator(Collection<ContentInfo> contentInfos,
                                  Node parent)
Constructs an iterator from given collection of ContentInfo objects. They must be ordered in ascending order by the ptr part. There shall be no force insertpoints, the filter shall accept anything and lastEmptyItem is determined from the last item in the collection.

Parameters:
contentInfos - collection of ContentInfo ordered by the ptr part.
parent - the parent node
Throws:
IllegalArgumentException - if given collection is not ordered correctly.
Method Detail

add

public final void add(ContentInfo o)
Specified by:
add in interface ListIterator<ContentInfo>

hasNext

public final boolean hasNext()
Specified by:
hasNext in interface Iterator<ContentInfo>
Specified by:
hasNext in interface ListIterator<ContentInfo>

hasPrevious

public final boolean hasPrevious()
Specified by:
hasPrevious in interface ListIterator<ContentInfo>

next

public final ContentInfo next()
Specified by:
next in interface Iterator<ContentInfo>
Specified by:
next in interface ListIterator<ContentInfo>

nextIndex

public final int nextIndex()
Specified by:
nextIndex in interface ListIterator<ContentInfo>

previous

public final ContentInfo previous()
Specified by:
previous in interface ListIterator<ContentInfo>

previousIndex

public final int previousIndex()
Specified by:
previousIndex in interface ListIterator<ContentInfo>

remove

public final void remove()
Specified by:
remove in interface Iterator<ContentInfo>
Specified by:
remove in interface ListIterator<ContentInfo>

set

public final void set(ContentInfo o)
Specified by:
set in interface ListIterator<ContentInfo>

getActIP

protected final int getActIP()
Returns actual index to items array, that will be returned by next call to next().

Returns:
actual insert point.

getEquivalent

public final sk.baka.ikslibs.ptr.DomPointer getEquivalent(sk.baka.ikslibs.ptr.DomPointer ptr)
Returns an DOMPointer that is equal to some pointer in the list, and inserting an element/text at given ip is equivalent to inserting the node at returned pointer.

Parameters:
ptr - pointer to check.
Returns:
an equivalent insertpoint. It may not be equal to some pointer from the list if and only if the pointer is greater than the last item in the list and this item is not ContentInfo of type NONE. In such case, given pointer is returned.

getChildIterator

public SchemaLevelNodeIterator getChildIterator(Element e)
Returns a child iterator for given element. The element must be amongst contentinfos returned by this iterator. Default implementation inherits the filter and the lastEmptyItem value, however forceIPs are not given to the child. The algorithm iterating with this iterator should use this method when entering child elements. You should override getClone() method when overriding this method to ensure the correct class type.

Parameters:
e - the element whose children shall be enumerated.
Returns:
iterator that iterates the children of given element. It points before the first node of the element children.

getClone

public SchemaLevelNodeIterator getClone()
Clones the iterator. The clone behaves independently from the original iterator.

Returns:
the clone.

iterator

public Iterator<ContentInfo> iterator()
Specified by:
iterator in interface Iterable<ContentInfo>


Copyright © 2003-2006 null. All Rights Reserved.