use of org.apache.sling.models.impl.model.InjectableMethod in project sling by apache.
the class ModelAdapterFactory method createInvocationHandler.
private <ModelType> Result<InvocationHandler> createInvocationHandler(final Object adaptable, final ModelClass<ModelType> modelClass) {
InjectableMethod[] injectableMethods = modelClass.getInjectableMethods();
final Map<Method, Object> methods = new HashMap<Method, Object>();
SetMethodsCallback callback = new SetMethodsCallback(methods);
MapBackedInvocationHandler handler = new MapBackedInvocationHandler(methods);
DisposalCallbackRegistryImpl registry = new DisposalCallbackRegistryImpl();
registerCallbackRegistry(handler, registry);
final Map<ValuePreparer, Object> preparedValues = new HashMap<ValuePreparer, Object>(VALUE_PREPARERS_COUNT);
MissingElementsException missingElements = new MissingElementsException("Could not create all mandatory methods for interface of model " + modelClass);
for (InjectableMethod method : injectableMethods) {
RuntimeException t = injectElement(method, adaptable, registry, callback, preparedValues);
if (t != null) {
missingElements.addMissingElementExceptions(new MissingElementException(method.getAnnotatedElement(), t));
}
}
registry.seal();
if (!missingElements.isEmpty()) {
return new Result<InvocationHandler>(missingElements);
}
return new Result<InvocationHandler>(handler);
}
use of org.apache.sling.models.impl.model.InjectableMethod in project sling by apache.
the class ModelAdapterFactory method setMethod.
private RuntimeException setMethod(InjectableMethod injectableMethod, Map<Method, Object> methods, Object value) {
Method method = injectableMethod.getMethod();
Result<Object> result = adaptIfNecessary(value, method.getReturnType(), method.getGenericReturnType());
if (result.wasSuccessful()) {
methods.put(method, result.getValue());
return null;
} else {
return result.getThrowable();
}
}
Aggregations