Search in sources :

Example 1 with ClientStubInvocationHandler

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);
}
Also used : Serializable(java.io.Serializable) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) ClientStubInvocationHandler(io.crnk.client.internal.ClientStubInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) ClientStubInvocationHandler(io.crnk.client.internal.ClientStubInvocationHandler) DefaultRepositoryInformationProviderContext(io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider)

Aggregations

ClientStubInvocationHandler (io.crnk.client.internal.ClientStubInvocationHandler)1 RepositoryInformationProvider (io.crnk.core.engine.information.repository.RepositoryInformationProvider)1 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)1 DefaultRepositoryInformationProviderContext (io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext)1 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)1 Serializable (java.io.Serializable)1 InvocationHandler (java.lang.reflect.InvocationHandler)1