Search in sources :

Example 1 with RepositoryServiceFactory

use of org.apache.jackrabbit.spi.RepositoryServiceFactory in project jackrabbit by apache.

the class Jcr2spiRepositoryFactory method getServiceFactory.

// -----------------------------------------------------< private >---
private static RepositoryServiceFactory getServiceFactory(Map<?, ?> parameters) throws RepositoryException {
    Object serviceFactoryParam = parameters.get(PARAM_REPOSITORY_SERVICE_FACTORY);
    if (serviceFactoryParam == null) {
        return null;
    }
    log.debug("Acquiring RepositoryServiceFactory from {}", PARAM_REPOSITORY_SERVICE_FACTORY);
    if (serviceFactoryParam instanceof RepositoryServiceFactory) {
        log.debug("Found RepositoryServiceFactory {}", serviceFactoryParam);
        return (RepositoryServiceFactory) serviceFactoryParam;
    } else if (serviceFactoryParam instanceof String) {
        String serviceFactoryName = (String) serviceFactoryParam;
        log.debug("Found RepositoryServiceFactory class name {}", serviceFactoryName);
        try {
            Class<?> serviceFactoryClass;
            try {
                serviceFactoryClass = Class.forName(serviceFactoryName, true, Thread.currentThread().getContextClassLoader());
            } catch (ClassNotFoundException e) {
                // Backup for OSGi
                serviceFactoryClass = Class.forName(serviceFactoryName);
            }
            Object serviceFactory = serviceFactoryClass.newInstance();
            if (serviceFactory instanceof RepositoryServiceFactory) {
                log.debug("Found RepositoryServiceFactory {}", serviceFactory);
                return (RepositoryServiceFactory) serviceFactory;
            } else {
                String msg = "Error acquiring RepositoryServiceFactory " + serviceFactoryParam;
                log.error(msg);
                throw new RepositoryException(msg);
            }
        } catch (Exception e) {
            String msg = "Error acquiring RepositoryServiceFactory";
            log.error(msg, e);
            throw new RepositoryException(msg, e);
        }
    } else {
        String msg = "Error acquiring RepositoryServiceFactory from " + serviceFactoryParam;
        log.error(msg);
        throw new RepositoryException(msg);
    }
}
Also used : RepositoryServiceFactory(org.apache.jackrabbit.spi.RepositoryServiceFactory) RepositoryException(javax.jcr.RepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 2 with RepositoryServiceFactory

use of org.apache.jackrabbit.spi.RepositoryServiceFactory in project jackrabbit by apache.

the class RepositoryFactoryImplTest method testGetRepositoryFromServiceFactory.

public void testGetRepositoryFromServiceFactory() throws RepositoryException {
    Map<String, RepositoryServiceFactory> parameters = Collections.singletonMap("org.apache.jackrabbit.spi.RepositoryServiceFactory", RepositoryServiceFactoryImpl.INSTANCE);
    Repository repo = factory.getRepository(parameters);
    assertNotNull(repo);
}
Also used : Repository(javax.jcr.Repository) RepositoryServiceFactory(org.apache.jackrabbit.spi.RepositoryServiceFactory)

Example 3 with RepositoryServiceFactory

use of org.apache.jackrabbit.spi.RepositoryServiceFactory in project jackrabbit by apache.

the class Jcr2spiRepositoryFactory method getRepository.

/**
     * <p>Creates a SPI based <code>Repository</code> instance based on the
     * <code>parameters</code> passed.</p>
     *
     * <p>If the {@link #PARAM_REPOSITORY_SERVICE_FACTORY} parameter is set,
     * the specified {@link RepositoryServiceFactory} is used to create the
     * {@link RepositoryService} instance. All parameters are passed to
     * {@link RepositoryServiceFactory#createRepositoryService(Map)}.</p>
     *
     * <p>If the {@link #PARAM_REPOSITORY_CONFIG} parameter is set, the
     * specified {@link RepositoryConfig} instance is used to create the
     * repository.</p>
     *
     * <p>If both parameters are set, the latter takes precedence and the
     * former is ignores.</p>
     *
     * <p>The known SPI implementations and its <code>RepositoryServiceFactory</code>s are:
     * <ul>
     * <li>SPI2DAVex (see jackrabbit-spi2dav module): <code>Spi2davRepositoryServiceFactory</code></li>
     * <li>SPI2DAV (see jackrabbit-spi2dav module): <code>Spi2davexRepositoryServiceFactory</code></li>
     * <li>SPI2JCR (see jackrabbit-spi2jcr module) <code>Spi2jcrRepositoryServiceFactory</code></li>
     * </ul>
     * <p>
     * NOTE: If the <code>parameters</code> map contains an
     * {@link #PARAM_LOG_WRITER_PROVIDER} entry the
     * {@link org.apache.jackrabbit.spi.RepositoryService RepositoryService} obtained
     * from the configuration is wrapped by a SPI logger. See the
     * {@link org.apache.jackrabbit.spi.commons.logging.SpiLoggerFactory SpiLoggerFactory}
     * for details.
     *
     * @see RepositoryFactory#getRepository(java.util.Map)
     */
public Repository getRepository(@SuppressWarnings("unchecked") Map parameters) throws RepositoryException {
    RepositoryServiceFactory serviceFactory = getServiceFactory(parameters);
    Object configParam = parameters.get(PARAM_REPOSITORY_CONFIG);
    if (serviceFactory == null && configParam == null) {
        return null;
    }
    RepositoryConfig config;
    if (configParam instanceof RepositoryConfig) {
        config = (RepositoryConfig) configParam;
        if (serviceFactory != null) {
            log.warn("Ignoring {} since {} was specified", PARAM_REPOSITORY_SERVICE_FACTORY, PARAM_REPOSITORY_CONFIG);
        }
    } else {
        if (serviceFactory == null) {
            return null;
        } else {
            config = new RepositoryConfigImpl(serviceFactory, parameters);
        }
    }
    config = SpiLoggerConfig.wrap(config, parameters);
    return RepositoryImpl.create(config);
}
Also used : RepositoryConfig(org.apache.jackrabbit.jcr2spi.config.RepositoryConfig) RepositoryServiceFactory(org.apache.jackrabbit.spi.RepositoryServiceFactory)

Aggregations

RepositoryServiceFactory (org.apache.jackrabbit.spi.RepositoryServiceFactory)3 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 RepositoryConfig (org.apache.jackrabbit.jcr2spi.config.RepositoryConfig)1