ReferenceNodeHandler refHandler)
{
Collection<ImmutableNode> subNodes =
new LinkedList<ImmutableNode>(refHandler.getChildren(node));
Iterator<ImmutableNode> children = subNodes.iterator();
ImmutableNode sibling1;
ImmutableNode nd = null;
while (children.hasNext())
{
// find the next new node
do
{
sibling1 = nd;
nd = children.next();
} while (refHandler.getReference(nd) != null
&& children.hasNext());
if (refHandler.getReference(nd) == null)
{
// find all following new nodes
List<ImmutableNode> newNodes =
new LinkedList<ImmutableNode>();
newNodes.add(nd);
while (children.hasNext())
{
nd = children.next();
if (refHandler.getReference(nd) == null)
{
newNodes.add(nd);
}
else
{
break;
}
}
// Insert all new nodes
ImmutableNode sibling2 =
(refHandler.getReference(nd) == null) ? null : nd;
for (ImmutableNode insertNode : newNodes)
{
if (refHandler.getReference(insertNode) == null)
{