* @param modelDescriptorResource Resource that identifies the model descriptor file
* @return The new model or null (error messages go to the message container)
*/
private Model readModelByPath(Resource modelDescriptorResource)
{
Model model = readModelDescriptor(modelDescriptorResource);
if (model == null)
return null;
// Determine the model URL from the descriptor URL
// TODO Cleanup 4: This is very rough, there should be some better way... In fact, the modelPath property should be a modelUrl property
URL url = null;
try
{
url = modelDescriptorResource.getURL();
}
catch (IOException e1)
{
throw new ModelException("ClassPathOperation", "Error accessing model URL '" + modelDescriptorResource.getDescription() + "'.");
}
String modelPath = url.toString();
int index = modelPath.lastIndexOf(StringUtil.FOLDER_SEP_CHAR);
if (index > 0)
{
modelPath = modelPath.substring(0, index);
}
model.setModelPath(modelPath);
// Register the model
try
{
registerModel(model);
}
catch (ModelException e)
{
getMsgContainer().addMsg(null, "Error registering model $0 in model manager $1", new Object[]
{
model.getName(), getClass().getName(), e
});
return null;
}
// Read the model items
ItemTypeDescriptor[] itds = getItemTypeDescriptors(ItemTypeRegistry.SKIP_MODEL | ItemTypeRegistry.SKIP_INVISIBLE);
for (int i = 0; i < itds.length; ++i)
{
readItems(model, modelPath, itds[i]);
}
LogUtil.info(getClass(), "Loaded model $0 from classpath.", model.getQualifier());
return model;
}