*/
private void postProcess(DiagramElement diag, DiagramElement parent) {
if (diag instanceof Diagram) {
int rank = 0;
for (Iterator<Connection> iterator = ((Diagram) diag).getAllLinks().iterator(); iterator.hasNext();) {
Connection l = (Connection) iterator.next();
if ((l.getFrom() != NO_REF) && (l.getTo() != NO_REF)) {
l.getFrom().getLinks().add(l);
l.getTo().getLinks().add(l);
if (l instanceof Link) {
((Link) l).setRank(rank++);
}
} else {
iterator.remove();
}
}
}
if (diag instanceof Contained) {
((Contained) diag).setContainer((Container) parent);
}
if (diag instanceof CompositionalDiagramElement) {
((CompositionalDiagramElement) diag).setParent(parent);
}
if (diag instanceof Link) {
Link il = (Link) diag;
if (il.getFrom() == null) {
il.setFrom((Connected) parent);
} else {
ensureLink(il.getFrom(), il);
}
if (il.getTo() == null) {
il.setTo((Connected) parent);
} else {
ensureLink(il.getTo(), il);
}
postProcess(il.getFromLabel(), il);
postProcess(il.getToLabel(), il);
}
if (diag instanceof Glyph) {
for (CompositionalDiagramElement c : ((Glyph) diag).getText()) {
postProcess(c, diag);
}
}
if (diag instanceof Container) {
Collection<Contained> content = ((Container) diag).getContents();
if (content != null) {
for (Contained c : content) {
postProcess(c, diag);
}
}
postProcess(((Container) diag).getLabel(), diag);
}
if (diag instanceof Connected) {
for (Iterator<Connection> lc = ((Connected) diag).getLinks().iterator(); lc.hasNext();) {
Connection c = (Connection) lc.next();
if ((c.getFrom() == NO_REF) || (c.getTo() == NO_REF)) {
lc.remove();
} else {
postProcess(c, diag);
}
}