001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thierry Delprat
016 */
017package org.nuxeo.ecm.webdav.service;
018
019import org.nuxeo.ecm.webdav.backend.BackendFactory;
020import org.nuxeo.ecm.webdav.backend.SearchBackendFactory;
021import org.nuxeo.runtime.api.Framework;
022import org.nuxeo.runtime.model.ComponentInstance;
023import org.nuxeo.runtime.model.ComponentName;
024import org.nuxeo.runtime.model.DefaultComponent;
025
026public class WebDavService extends DefaultComponent {
027
028    public static final ComponentName NAME = new ComponentName("org.nuxeo.ecm.webdav.service");
029
030    public static String BACKEND_FACTORY_XP = "backendFactory";
031
032    protected BackendFactory backendFactory = new SearchBackendFactory();
033
034    public static WebDavService instance() {
035        return (WebDavService) Framework.getRuntime().getComponent(WebDavService.NAME);
036    }
037
038    public BackendFactory getBackendFactory() {
039        return backendFactory;
040    }
041
042    // used by tests
043    public void setBackendFactory(BackendFactory backendFactory) {
044        this.backendFactory = backendFactory;
045    }
046
047    @Override
048    public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
049        if (BACKEND_FACTORY_XP.equals(extensionPoint)) {
050            BackendFactoryDescriptor desc = (BackendFactoryDescriptor) contribution;
051            Class<?> factoryClass = desc.getFactoryClass();
052            try {
053                backendFactory = (BackendFactory) factoryClass.newInstance();
054            } catch (ReflectiveOperationException e) {
055                throw new RuntimeException(e);
056            }
057        }
058    }
059
060}