001/* 002 * Copyright (c) 2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Florent Guillaume 011 */ 012package org.nuxeo.ecm.core.storage.mongodb; 013 014import org.nuxeo.ecm.core.repository.RepositoryFactory; 015import org.nuxeo.runtime.api.Framework; 016 017/** 018 * MongoDB implementation of a {@link RepositoryFactory}, creating a {@link MongoDBRepository}. 019 * 020 * @since 5.9.4 021 */ 022public class MongoDBRepositoryFactory implements RepositoryFactory { 023 024 protected String repositoryName; 025 026 @Override 027 public void init(String repositoryName) { 028 this.repositoryName = repositoryName; 029 } 030 031 @Override 032 public Object call() { 033 MongoDBRepositoryService repositoryService = Framework.getLocalService(MongoDBRepositoryService.class); 034 MongoDBRepositoryDescriptor descriptor = repositoryService.getRepositoryDescriptor(repositoryName); 035 if (descriptor == null) { 036 throw new IllegalStateException("No descriptor registered for: " + repositoryName); 037 } 038 return new MongoDBRepository(descriptor); 039 } 040 041}