Search in sources :

Example 1 with DelegatingRepositoryImplConfig

use of org.eclipse.rdf4j.repository.config.DelegatingRepositoryImplConfig in project rdf4j by eclipse.

the class LocalRepositoryManager method createRepositoryStack.

/**
 * Creates the stack of Repository objects for the repository represented by the specified
 * {@link org.eclipse.rdf4j.repository.config.RepositoryImplConfig}. Uses a
 * {@link org.eclipse.rdf4j.repository.config.RepositoryFactory} to create the repository and initialize
 * it.
 *
 * @param config
 *        The node representing the to-be-created repository in the configuration.
 * @return The created repository, or <tt>null</tt> if no such repository exists.
 * @throws RepositoryConfigException
 *         If no repository could be created due to invalid or incomplete configuration data.
 */
private Repository createRepositoryStack(RepositoryImplConfig config) throws RepositoryConfigException {
    RepositoryFactory factory = RepositoryRegistry.getInstance().get(config.getType()).orElseThrow(() -> new RepositoryConfigException("Unsupported repository type: " + config.getType()));
    Repository repository = factory.getRepository(config);
    if (repository instanceof RepositoryResolverClient) {
        ((RepositoryResolverClient) repository).setRepositoryResolver(this);
    }
    if (repository instanceof FederatedServiceResolverClient) {
        ((FederatedServiceResolverClient) repository).setFederatedServiceResolver(getFederatedServiceResolver());
    }
    if (repository instanceof SessionManagerDependent) {
        ((SessionManagerDependent) repository).setHttpClientSessionManager(client);
    } else if (repository instanceof HttpClientDependent) {
        ((HttpClientDependent) repository).setHttpClient(getHttpClient());
    }
    if (config instanceof DelegatingRepositoryImplConfig) {
        RepositoryImplConfig delegateConfig = ((DelegatingRepositoryImplConfig) config).getDelegate();
        Repository delegate = createRepositoryStack(delegateConfig);
        try {
            ((DelegatingRepository) repository).setDelegate(delegate);
        } catch (ClassCastException e) {
            throw new RepositoryConfigException("Delegate specified for repository that is not a DelegatingRepository: " + delegate.getClass(), e);
        }
    }
    return repository;
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) DelegatingRepository(org.eclipse.rdf4j.repository.DelegatingRepository) RepositoryImplConfig(org.eclipse.rdf4j.repository.config.RepositoryImplConfig) DelegatingRepositoryImplConfig(org.eclipse.rdf4j.repository.config.DelegatingRepositoryImplConfig) DelegatingRepositoryImplConfig(org.eclipse.rdf4j.repository.config.DelegatingRepositoryImplConfig) RepositoryFactory(org.eclipse.rdf4j.repository.config.RepositoryFactory) FederatedServiceResolverClient(org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedServiceResolverClient) SessionManagerDependent(org.eclipse.rdf4j.http.client.SessionManagerDependent) DelegatingRepository(org.eclipse.rdf4j.repository.DelegatingRepository) RepositoryConfigException(org.eclipse.rdf4j.repository.config.RepositoryConfigException) RepositoryResolverClient(org.eclipse.rdf4j.repository.RepositoryResolverClient) HttpClientDependent(org.eclipse.rdf4j.http.client.HttpClientDependent)

Aggregations

HttpClientDependent (org.eclipse.rdf4j.http.client.HttpClientDependent)1 SessionManagerDependent (org.eclipse.rdf4j.http.client.SessionManagerDependent)1 FederatedServiceResolverClient (org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedServiceResolverClient)1 DelegatingRepository (org.eclipse.rdf4j.repository.DelegatingRepository)1 Repository (org.eclipse.rdf4j.repository.Repository)1 RepositoryResolverClient (org.eclipse.rdf4j.repository.RepositoryResolverClient)1 DelegatingRepositoryImplConfig (org.eclipse.rdf4j.repository.config.DelegatingRepositoryImplConfig)1 RepositoryConfigException (org.eclipse.rdf4j.repository.config.RepositoryConfigException)1 RepositoryFactory (org.eclipse.rdf4j.repository.config.RepositoryFactory)1 RepositoryImplConfig (org.eclipse.rdf4j.repository.config.RepositoryImplConfig)1