}
protected TemplateModel create(Object object) {
Class clazz = object.getClass();
ModelFactory factory = null;
if (classToFactoryIsConcurrent) {
factory = (ModelFactory) classToFactory.get(clazz);
}
if (factory == null) {
synchronized(classToFactory) {
factory = (ModelFactory)classToFactory.get(clazz);
if(factory == null) {
String className = clazz.getName();
// clear mappings when class reloading is detected
if(!mappedClassNames.add(className)) {
classToFactory.clear();
mappedClassNames.clear();
mappedClassNames.add(className);
}
factory = wrapper.getModelFactory(clazz);
classToFactory.put(clazz, factory);
}
}
}
return factory.create(object, wrapper);
}