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