if (Util.nullSafeEquals(newClassName, embeddable.getClassName())) {
return;
}
if (newClassName == null) {
throw new ValidationException("Embeddable name is required.");
}
else if (embeddable.getDataMap().getEmbeddable(newClassName) == null) {
// if newClassName dupliucates in other DataMaps
DataDomain domain = mediator.getCurrentDataDomain();
if (domain != null) {
for (DataMap nextMap : domain.getDataMaps()) {
if (nextMap == embeddable.getDataMap()) {
continue;
}
Embeddable conflictingEmbeddable = nextMap.getEmbeddable(newClassName);
if (conflictingEmbeddable != null) {
throw new ValidationException(
"Duplicate Embeddable name in another DataMap: "
+ newClassName
+ ".");
}
}
}
// completely new name, set new name for embeddable
EmbeddableEvent e = new EmbeddableEvent(this, embeddable, embeddable
.getClassName());
String oldName = embeddable.getClassName();
embeddable.setClassName(newClassName);
mediator.fireEmbeddableEvent(e, mediator.getCurrentDataMap());
Iterator it = mediator.getCurrentDataDomain().getDataMaps().iterator();
while (it.hasNext()) {
DataMap dataMap = (DataMap) it.next();
Iterator<ObjEntity> ent = dataMap.getObjEntities().iterator();
while (ent.hasNext()) {
Collection<ObjAttribute> attr = ent.next().getAttributes();
Iterator<ObjAttribute> attrIt = attr.iterator();
while (attrIt.hasNext()) {
ObjAttribute atribute = attrIt.next();
if (atribute.getType()==null || atribute.getType().equals(oldName)) {
atribute.setType(newClassName);
AttributeEvent ev = new AttributeEvent(this, atribute, atribute
.getEntity());
mediator.fireObjAttributeEvent(ev);
}
}
}
}
}
else {
// there is an embeddable with the same name
throw new ValidationException("There is another embeddable with name '"
+ newClassName
+ "'.");
}
}