001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.ecm.webdav.service; 020 021import org.nuxeo.ecm.webdav.backend.BackendFactory; 022import org.nuxeo.ecm.webdav.backend.SearchBackendFactory; 023import org.nuxeo.runtime.api.Framework; 024import org.nuxeo.runtime.model.ComponentInstance; 025import org.nuxeo.runtime.model.ComponentName; 026import org.nuxeo.runtime.model.DefaultComponent; 027 028public class WebDavService extends DefaultComponent { 029 030 public static final ComponentName NAME = new ComponentName("org.nuxeo.ecm.webdav.service"); 031 032 public static String BACKEND_FACTORY_XP = "backendFactory"; 033 034 protected BackendFactory backendFactory = new SearchBackendFactory(); 035 036 public static WebDavService instance() { 037 return (WebDavService) Framework.getRuntime().getComponent(WebDavService.NAME); 038 } 039 040 public BackendFactory getBackendFactory() { 041 return backendFactory; 042 } 043 044 // used by tests 045 public void setBackendFactory(BackendFactory backendFactory) { 046 this.backendFactory = backendFactory; 047 } 048 049 @Override 050 public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 051 if (BACKEND_FACTORY_XP.equals(extensionPoint)) { 052 BackendFactoryDescriptor desc = (BackendFactoryDescriptor) contribution; 053 Class<?> factoryClass = desc.getFactoryClass(); 054 try { 055 backendFactory = (BackendFactory) factoryClass.newInstance(); 056 } catch (ReflectiveOperationException e) { 057 throw new RuntimeException(e); 058 } 059 } 060 } 061 062}