001/*
002 * (C) Copyright 2006-2016 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 *     Florent Guillaume
018 */
019package org.nuxeo.ecm.directory;
020
021import org.nuxeo.ecm.core.api.NuxeoException;
022import org.nuxeo.ecm.directory.api.DirectoryService;
023import org.nuxeo.runtime.api.Framework;
024import org.nuxeo.runtime.model.ComponentInstance;
025import org.nuxeo.runtime.model.DefaultComponent;
026
027/**
028 * Default implementation for a directory factory component, that simply delegates registration of descriptors to the
029 * {@link DirectoryService}.
030 *
031 * @since 8.2
032 */
033public class DefaultDirectoryFactory extends DefaultComponent {
034
035    public static final String DIRECTORIES_XP = "directories";
036
037    @Override
038    public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
039        if (!DIRECTORIES_XP.equals(extensionPoint)) {
040            throw new NuxeoException("Unknown extension point: " + extensionPoint);
041        }
042        BaseDirectoryDescriptor descriptor = (BaseDirectoryDescriptor) contribution;
043        Framework.getService(DirectoryService.class).registerDirectoryDescriptor(descriptor);
044    }
045
046    @Override
047    public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
048        if (!DIRECTORIES_XP.equals(extensionPoint)) {
049            return;
050        }
051        BaseDirectoryDescriptor descriptor = (BaseDirectoryDescriptor) contribution;
052        Framework.getService(DirectoryService.class).unregisterDirectoryDescriptor(descriptor);
053    }
054
055}