* @return
*/
public static IdManager createIdManager(Class<?> containedClass,
DatastoreService datastore, ServiceRepository repository, PropertyProvider provider, HierarchyManager hierarchyManager) {
logger.config("defining id manager");
IdManager returned = null;
Field[] fields = containedClass.getDeclaredFields();
for (Field f : fields) {
// only non static fields are used
if (!Modifier.isStatic(f.getModifiers())) {
boolean isIdField = f.getAnnotation(Id.class) != null;
if (isIdField) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("found id field of "
+ containedClass.getName() + "\nIt is "
+ f.toGenericString());
}
if (returned != null)
throw new BadIdAnnotatedClassException(containedClass);
if (logger.isLoggable(Level.CONFIG))
logger.config("the field " + f.toGenericString()
+ " seems to be an id field");
if (Long.class.equals(f.getType())
|| Long.TYPE.equals(f.getType())) {
returned = new LongIdManager(containedClass, datastore, provider, repository, hierarchyManager);
logger.config("using standard LongIdManager");
} else if (String.class.equals(f.getType())) {
logger.config("using standard StringIdManager");
} else {
throw new NoSuchIdManagerException(f);
}
if (logger.isLoggable(Level.FINE)) {
logger.fine("As a consequence, id manager is a "
+ returned.getClass().getName());
}
}
// Side effect : access to the field !
f.setAccessible(true);
}