001/*
002 * (C) Copyright 2006-2007 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 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.directory.ldap;
023
024import org.nuxeo.ecm.core.api.NuxeoException;
025import org.nuxeo.ecm.directory.DefaultDirectoryFactory;
026import org.nuxeo.ecm.directory.DirectoryServiceImpl;
027import org.nuxeo.ecm.directory.api.DirectoryService;
028import org.nuxeo.ecm.directory.ldap.registry.LDAPServerRegistry;
029import org.nuxeo.runtime.api.Framework;
030import org.nuxeo.runtime.model.ComponentInstance;
031
032public class LDAPDirectoryFactory extends DefaultDirectoryFactory {
033
034    public static final String SERVERS_XP = "servers";
035
036    protected LDAPServerRegistry servers = new LDAPServerRegistry();
037
038    public LDAPServerDescriptor getServer(String name) {
039        return servers.getServer(name);
040    }
041
042    protected static DirectoryServiceImpl getDirectoryService() {
043        return (DirectoryServiceImpl) Framework.getService(DirectoryService.class);
044    }
045
046    @Override
047    public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
048        if (DIRECTORIES_XP.equals(extensionPoint)) {
049            super.registerContribution(contribution, extensionPoint, contributor);
050        } else if (SERVERS_XP.equals(extensionPoint)) {
051            registerServerContribution((LDAPServerDescriptor) contribution);
052        } else {
053            throw new NuxeoException("Unknown extension point: " + extensionPoint);
054        }
055    }
056
057    @Override
058    public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
059        if (DIRECTORIES_XP.equals(extensionPoint)) {
060            super.unregisterContribution(contribution, extensionPoint, contributor);
061        } else if (SERVERS_XP.equals(extensionPoint)) {
062            unregisterServerContribution((LDAPServerDescriptor) contribution);
063        }
064    }
065
066    public void registerServerContribution(LDAPServerDescriptor descriptor) {
067        servers.addContribution(descriptor);
068    }
069
070    public void unregisterServerContribution(LDAPServerDescriptor descriptor) {
071        servers.removeContribution(descriptor);
072    }
073
074}