001/*
002 * (C) Copyright 2007 Nuxeo SAS (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 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.comment.service;
021
022import org.apache.commons.logging.Log;
023import org.apache.commons.logging.LogFactory;
024import org.nuxeo.ecm.platform.comment.api.CommentManager;
025import org.nuxeo.ecm.platform.comment.impl.CommentManagerImpl;
026import org.nuxeo.runtime.model.ComponentInstance;
027import org.nuxeo.runtime.model.DefaultComponent;
028
029/**
030 * @author <a href="mailto:glefter@nuxeo.com">George Lefter</a>
031 */
032public class CommentService extends DefaultComponent {
033
034    public static final String ID = "org.nuxeo.ecm.platform.comment.service.CommentService";
035
036    public static final String VERSIONING_EXTENSION_POINT_RULES = "rules";
037
038    private static final Log log = LogFactory.getLog(CommentService.class);
039
040    private CommentManager commentManager;
041
042    private CommentServiceConfig config;
043
044    @Override
045    public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
046        if ("config".equals(extensionPoint)) {
047            config = (CommentServiceConfig) contribution;
048            log.debug("registered service config: " + config);
049        } else {
050            log.warn("unknown extension point: " + extensionPoint);
051        }
052    }
053
054    @Override
055    public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
056        // do nothing
057    }
058
059    public CommentManager getCommentManager() {
060        log.debug("getCommentManager");
061        if (commentManager == null) {
062            commentManager = new CommentManagerImpl(config);
063        }
064        return commentManager;
065    }
066
067    public CommentServiceConfig getConfig() {
068        return config;
069    }
070
071    @Override
072    public <T> T getAdapter(Class<T> adapter) {
073        if (adapter == CommentManager.class) {
074            return adapter.cast(getCommentManager());
075        }
076        return null;
077    }
078
079}