001/*
002 * (C) Copyright 2011 Nuxeo SA (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 *     Thomas Roger <troger@nuxeo.com>
016 */
017
018package org.nuxeo.ecm.activity;
019
020import org.nuxeo.common.xmap.annotation.XNode;
021import org.nuxeo.common.xmap.annotation.XObject;
022import org.nuxeo.ecm.core.api.NuxeoException;
023
024/**
025 * Descriptor object for registering {@link ActivityStreamFilter}s.
026 *
027 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
028 * @since 5.5
029 */
030@XObject("activityStreamFilter")
031public class ActivityStreamFilterDescriptor {
032
033    @XNode("@enabled")
034    protected boolean enabled = true;
035
036    @XNode("@class")
037    protected Class<? extends ActivityStreamFilter> activityStreamFilterClass;
038
039    public ActivityStreamFilterDescriptor() {
040    }
041
042    public ActivityStreamFilterDescriptor(Class<? extends ActivityStreamFilter> activityStreamFilterClass,
043            boolean enabled) {
044        this.activityStreamFilterClass = activityStreamFilterClass;
045        this.enabled = enabled;
046    }
047
048    public boolean isEnabled() {
049        return enabled;
050    }
051
052    public ActivityStreamFilter getActivityStreamFilter() {
053        try {
054            return activityStreamFilterClass.newInstance();
055        } catch (ReflectiveOperationException e) {
056            throw new NuxeoException(e);
057        }
058    }
059
060}