public void initializePartialEntities(EOModelGroup modelGroup) {
NSMutableDictionary<EOEntity, EOEntity> baseForPartial = new NSMutableDictionary<EOEntity, EOEntity>();
Enumeration modelsEnum = modelGroup.models().objectEnumerator();
while (modelsEnum.hasMoreElements()) {
EOModel model = (EOModel) modelsEnum.nextElement();
Enumeration entitiesEnum = model.entities().objectEnumerator();
while (entitiesEnum.hasMoreElements()) {
EOEntity partialExtensionEntity = (EOEntity) entitiesEnum.nextElement();
NSDictionary userInfo = partialExtensionEntity.userInfo();
NSDictionary entityModelerDictionary = (NSDictionary) userInfo.objectForKey("_EntityModeler");
if (entityModelerDictionary != null) {
String partialEntityName = (String) entityModelerDictionary.objectForKey("partialEntity");
if (partialEntityName != null) {
EOEntity partialEntity = modelGroup.entityNamed(partialEntityName);
if (partialEntity == null) {
throw new IllegalArgumentException("The entity '" + partialExtensionEntity.name() + "' claimed to be a partialEntity for the entity '" + partialEntityName + "', but there is no entity of that name.");
}
Enumeration partialAttributes = partialExtensionEntity.attributes().objectEnumerator();
while (partialAttributes.hasMoreElements()) {
EOAttribute partialAttribute = (EOAttribute) partialAttributes.nextElement();
if (partialEntity.attributeNamed(partialAttribute.name()) == null) {
NSMutableDictionary<String, Object> attributePropertyList = new NSMutableDictionary<String, Object>();
partialAttribute.encodeIntoPropertyList(attributePropertyList);
String factoryMethodArgumentType = (String) attributePropertyList.objectForKey("factoryMethodArgumentType");
// OFFICIALLY THE DUMBEST DAMN THING I'VE EVER
// SEEN
if ("EOFactoryMethodArgumentIsString".equals(factoryMethodArgumentType)) {
attributePropertyList.setObjectForKey("EOFactoryMethodArgumentIsNSString", "factoryMethodArgumentType");
}
EOAttribute primaryAttribute = new EOAttribute(attributePropertyList, partialEntity);
primaryAttribute.awakeWithPropertyList(attributePropertyList);
partialEntity.addAttribute(primaryAttribute);
}
else {
ERXModelGroup.log.debug("Skipping partial attribute " + partialExtensionEntity.name() + "." + partialAttribute.name() + " because " + partialEntity.name() + " already has an attribute of the same name.");
}
}
Enumeration partialRelationships = partialExtensionEntity.relationships().objectEnumerator();
while (partialRelationships.hasMoreElements()) {
EORelationship partialRelationship = (EORelationship) partialRelationships.nextElement();
if (partialEntity.relationshipNamed(partialRelationship.name()) == null) {
NSMutableDictionary<String, Object> relationshipPropertyList = new NSMutableDictionary<String, Object>();
partialRelationship.encodeIntoPropertyList(relationshipPropertyList);
EORelationship primaryRelationship = new EORelationship(relationshipPropertyList, partialEntity);
primaryRelationship.awakeWithPropertyList(relationshipPropertyList);
partialEntity.addRelationship(primaryRelationship);
}
else {
ERXModelGroup.log.debug("Skipping partial relationship " + partialExtensionEntity.name() + "." + partialRelationship.name() + " because " + partialEntity.name() + " already has a relationship of the same name.");
}
}
NSMutableArray<Class<ERXPartial>> partialsForEntity = _partialsForEntity.objectForKey(partialEntity);
if (partialsForEntity == null) {
partialsForEntity = new NSMutableArray<Class<ERXPartial>>();
_partialsForEntity.setObjectForKey(partialsForEntity, partialEntity);
}
Class<ERXPartial> partialClass = (Class<ERXPartial>) _NSUtilities.classWithName(partialExtensionEntity.className());
ERXEntityClassDescription ecd = (ERXEntityClassDescription) partialEntity.classDescriptionForInstances();
ecd._addPartialClass(partialClass);
partialsForEntity.addObject(partialClass);
baseForPartial.setObjectForKey(partialEntity, partialExtensionEntity);
}
}
}
}
NSMutableSet<EOEntity> convertedEntities = new NSMutableSet<EOEntity>();
modelsEnum = modelGroup.models().objectEnumerator();
while (modelsEnum.hasMoreElements()) {
EOModel model = (EOModel) modelsEnum.nextElement();
Enumeration entitiesEnum = model.entities().objectEnumerator();
while (entitiesEnum.hasMoreElements()) {
EOEntity entity = (EOEntity) entitiesEnum.nextElement();
convertEntityPartialReferences(entity, baseForPartial, convertedEntities);
}
}