Document document = null;
try {
document = entityResourceHandler.getDocument();
} catch (GenericConfigException e) {
throw new GenericEntityConfException("Error getting document from resource handler", e);
}
if (document == null) {
throw new GenericEntityConfException("Could not get document for " + entityResourceHandler.toString());
}
// utilTimer.timerString("Before getDocumentElement in " + entityResourceHandler.toString());
Element docElement = document.getDocumentElement();
if (docElement == null) {
entityCache = null;
return null;
}
docElement.normalize();
Node curChild = docElement.getFirstChild();
ModelInfo def = new ModelInfo();
def.populateFromElements(docElement);
int i = 0;
if (curChild != null) {
utilTimer.timerString("Before start of entity loop in " + entityResourceHandler.toString());
do {
boolean isEntity = "entity".equals(curChild.getNodeName());
boolean isViewEntity = "view-entity".equals(curChild.getNodeName());
boolean isExtendEntity = "extend-entity".equals(curChild.getNodeName());
if ((isEntity || isViewEntity) && curChild.getNodeType() == Node.ELEMENT_NODE) {
i++;
ModelEntity modelEntity = buildEntity(entityResourceHandler, (Element) curChild, i, def);
// put the view entity in a list to get ready for the second pass to populate fields...
if (isViewEntity) tempViewEntityList.add((ModelViewEntity) modelEntity);
} else if (isExtendEntity && curChild.getNodeType() == Node.ELEMENT_NODE) {
tempExtendEntityElementList.add((Element) curChild);
}
} while ((curChild = curChild.getNextSibling()) != null);
} else {
Debug.logWarning("No child nodes found.", module);
}
utilTimer.timerString("Finished " + entityResourceHandler.toString() + " - Total Entities: " + i + " FINISHED");
}
// all entity elements in, now go through extend-entity elements and add their stuff
for (Element extendEntityElement: tempExtendEntityElementList) {
String entityName = UtilXml.checkEmpty(extendEntityElement.getAttribute("entity-name"));
ModelEntity modelEntity = (ModelEntity) entityCache.get(entityName);
if (modelEntity == null) throw new GenericEntityConfException("Entity to extend does not exist: " + entityName);
modelEntity.addExtendEntity(this, extendEntityElement);
}
// do a pass on all of the view entities now that all of the entities have
// loaded and populate the fields
for (ModelViewEntity curViewEntity: tempViewEntityList) {
curViewEntity.populateFields(this);
for (ModelViewEntity.ModelMemberEntity mve: curViewEntity.getAllModelMemberEntities()) {
ModelEntity me = (ModelEntity) entityCache.get(mve.getEntityName());
if (me == null) throw new GenericEntityConfException("View " + curViewEntity.getEntityName() + " references non-existant entity: " + mve.getEntityName());
me.addViewEntity(curViewEntity);
}
}
// auto-create relationships