{
Class defaultImplementation = ReflectionUtils.getDefaultImplementation(manageableObjectsClass);
if (defaultImplementation == null)
{
throw new JcrMappingException("No default implementation for the interface " + manageableObjectsClass);
}
else
{
manageableObjectsClass = defaultImplementation;
}
}
//if the class is implementing the Collection interface
if (ReflectionUtils.implementsInterface(manageableObjectsClass, Collection.class))
{
return new ManageableCollectionImpl((Collection) ReflectionUtils.newInstance(manageableObjectsClass));
}
//if the class is implementing the Map interface
if (ReflectionUtils.implementsInterface(manageableObjectsClass, Map.class))
{
return new ManageableMapImpl((Map) ReflectionUtils.newInstance(manageableObjectsClass));
}
Object manageableObjects = manageableObjectsClass.newInstance();
if (!(manageableObjects instanceof ManageableObjects)) {
throw new JcrMappingException("Unsupported collection type :"
+ manageableObjectsClass.getName());
}
else {
return (ManageableObjects) manageableObjects;
}
}
catch (Exception e) {
throw new JcrMappingException("Cannot create manageable objects (Collection or Map)", e);
}
}