} else if (!(item instanceof IdentifiableDiagramElement)) {
// we're only going to allow references on non-identifiable
// diagram elements
converter.marshal(item, writer, this);
} else {
Path currentPath = pathTracker.getPath();
Object existingReferenceKey = references.lookupId(item);
if (existingReferenceKey != null) {
writer.addAttribute(getMapper().aliasForAttribute("reference"), createReference(currentPath,
existingReferenceKey));
} else if (implicitElements.lookupId(item) != null) {
throw new ReferencedImplicitElementException(item, currentPath);
} else {
String newReferenceKey = null;
boolean fire = false;
if (item instanceof IdentifiableDiagramElement) {
newReferenceKey = ensureUniqueness((IdentifiableDiagramElement) item);
} else {
newReferenceKey = makeUnique("" + nextIntId++);
fire = true;
}
if (lastPath == null || !currentPath.isAncestor(lastPath)) {
if (fire) {
fireValidReference(newReferenceKey);
}
lastPath = currentPath;
if (usedIDs.contains(newReferenceKey)) {