Search in sources :

Example 6 with RepositoryInformationProvider

use of io.crnk.core.engine.information.repository.RepositoryInformationProvider 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

RepositoryInformationProvider (io.crnk.core.engine.information.repository.RepositoryInformationProvider)6 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)5 DefaultRepositoryInformationProviderContext (io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext)3 Test (org.junit.Test)3 ClientStubInvocationHandler (io.crnk.client.internal.ClientStubInvocationHandler)1 RelationshipRepositoryInformation (io.crnk.core.engine.information.repository.RelationshipRepositoryInformation)1 RepositoryInformation (io.crnk.core.engine.information.repository.RepositoryInformation)1 RepositoryInformationProviderContext (io.crnk.core.engine.information.repository.RepositoryInformationProviderContext)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 ResponseRelationshipEntry (io.crnk.core.engine.registry.ResponseRelationshipEntry)1 RelationshipMatcher (io.crnk.core.repository.RelationshipMatcher)1 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)1 DirectResponseRelationshipEntry (io.crnk.legacy.internal.DirectResponseRelationshipEntry)1 Serializable (java.io.Serializable)1 InvocationHandler (java.lang.reflect.InvocationHandler)1