in src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java [663:702]
private <ModelType> Result<InvocationHandler> createInvocationHandler(final Object adaptable, final ModelClass<ModelType> modelClass) {
InjectableMethod[] injectableMethods = modelClass.getInjectableMethods();
final Map<Method, Object> methods = new HashMap<>();
SetMethodsCallback callback = new SetMethodsCallback(methods);
MapBackedInvocationHandler handler = new MapBackedInvocationHandler(methods);
DisposalCallbackRegistryImpl registry = new DisposalCallbackRegistryImpl();
final Map<ValuePreparer, Object> preparedValues = new HashMap<>(VALUE_PREPARERS_COUNT);
List<MissingElementException> missingElements = null;
final BundleContext modelContext = getModelBundleContext(modelClass);
for (InjectableMethod method : injectableMethods) {
RuntimeException t = injectElement(method, adaptable, registry, callback, preparedValues, modelContext);
if (t != null) {
if (missingElements == null) {
missingElements = new ArrayList<>();
}
missingElements.add(new MissingElementException(method.getAnnotatedElement(), t));
}
}
if (!registry.callbacks.isEmpty()) {
registry.seal();
if (adaptable instanceof SlingHttpServletRequest &&
((SlingHttpServletRequest) adaptable).getAttribute(REQUEST_MARKER_ATTRIBUTE) == REQUEST_MARKER_VALUE) {
registerRequestCallbackRegistry((SlingHttpServletRequest) adaptable, registry);
} else {
registerCallbackRegistry(handler, registry);
}
}
if (missingElements != null) {
MissingElementsException missingElementsException = new MissingElementsException("Could not create all mandatory methods for interface of model " + modelClass);
for (MissingElementException me : missingElements) {
missingElementsException.addMissingElementExceptions(me);
}
return new Result<>(missingElementsException);
}
return new Result<InvocationHandler>(handler);
}