use of io.crnk.client.internal.ClientStubInvocationHandler in project crnk-framework by crnk-project.
the class CrnkClient method getRepositoryForInterface.
@SuppressWarnings("unchecked")
public <R extends ResourceRepositoryV2<?, ?>> R getRepositoryForInterface(Class<R> repositoryInterfaceClass) {
init();
RepositoryInformationProvider informationBuilder = moduleRegistry.getRepositoryInformationBuilder();
PreconditionUtil.assertTrue("no a valid repository interface", informationBuilder.accept(repositoryInterfaceClass));
ResourceRepositoryInformation repositoryInformation = (ResourceRepositoryInformation) informationBuilder.build(repositoryInterfaceClass, new DefaultRepositoryInformationProviderContext(moduleRegistry));
Class<?> resourceClass = repositoryInformation.getResourceInformation().get().getResourceClass();
Object actionStub = actionStubFactory != null ? actionStubFactory.createStub(repositoryInterfaceClass) : null;
ResourceRepositoryV2<?, Serializable> repositoryStub = getQuerySpecRepository(resourceClass);
ClassLoader classLoader = repositoryInterfaceClass.getClassLoader();
InvocationHandler invocationHandler = new ClientStubInvocationHandler(repositoryInterfaceClass, repositoryStub, actionStub);
return (R) Proxy.newProxyInstance(classLoader, new Class[] { repositoryInterfaceClass, ResourceRepositoryV2.class }, invocationHandler);
}
Aggregations