use of io.crnk.client.internal.RelationshipRepositoryStubImpl in project crnk-framework by crnk-project.
the class CrnkClient method allocateRepositoryRelation.
private RelationshipRepositoryAdapter allocateRepositoryRelation(Class sourceClass, Class targetClass) {
// allocate relations as well
ClientResourceRegistry clientResourceRegistry = (ClientResourceRegistry) resourceRegistry;
if (!clientResourceRegistry.isInitialized(sourceClass)) {
allocateRepository(sourceClass);
}
if (!clientResourceRegistry.isInitialized(targetClass)) {
allocateRepository(targetClass);
}
RegistryEntry sourceEntry = resourceRegistry.getEntry(sourceClass);
final RegistryEntry targetEntry = resourceRegistry.getEntry(targetClass);
String targetResourceType = targetEntry.getResourceInformation().getResourceType();
Map relationshipEntries = sourceEntry.getRelationshipEntries();
DirectResponseRelationshipEntry relationshipEntry = (DirectResponseRelationshipEntry) relationshipEntries.get(targetResourceType);
if (!relationshipEntries.containsKey(targetResourceType)) {
final RelationshipRepositoryStubImpl relationshipRepositoryStub = new RelationshipRepositoryStubImpl(this, sourceClass, targetClass, sourceEntry.getResourceInformation(), urlBuilder);
RepositoryInstanceBuilder<RelationshipRepository> relationshipRepositoryInstanceBuilder = new RepositoryInstanceBuilder<RelationshipRepository>(null, null) {
@Override
public RelationshipRepository buildRepository() {
return relationshipRepositoryStub;
}
};
relationshipEntry = new DirectResponseRelationshipEntry(relationshipRepositoryInstanceBuilder) {
@Override
public String getTargetResourceType() {
return targetEntry.getResourceInformation().getResourceType();
}
};
relationshipEntries.put(targetResourceType, relationshipEntry);
}
Object repoInstance = relationshipEntry.getRepositoryInstanceBuilder();
return new RelationshipRepositoryAdapter(sourceEntry.getResourceInformation(), moduleRegistry, repoInstance);
}
Aggregations