001/*
002 * (C) Copyright 2006-2012 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 *     Thomas Roger <troger@nuxeo.com>
018 */
019
020package org.nuxeo.ecm.activity;
021
022import org.nuxeo.common.xmap.annotation.XNode;
023import org.nuxeo.common.xmap.annotation.XObject;
024import org.nuxeo.ecm.core.api.NuxeoException;
025
026/**
027 * Descriptor object for registering {@link ActivityLinkBuilder}s.
028 *
029 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
030 * @since 5.6
031 */
032@XObject("activityLinkBuilder")
033public class ActivityLinkBuilderDescriptor {
034
035    @XNode("@name")
036    protected String name;
037
038    @XNode("@class")
039    protected Class<? extends ActivityLinkBuilder> activityLinkBuilderClass;
040
041    @XNode("@default")
042    protected boolean isDefault = false;
043
044    @XNode("@enabled")
045    protected boolean enabled = true;
046
047    public String getName() {
048        return name;
049    }
050
051    public void setName(String name) {
052        this.name = name;
053    }
054
055    public Class<? extends ActivityLinkBuilder> getActivityLinkBuilderClass() {
056        return activityLinkBuilderClass;
057    }
058
059    public void setActivityLinkBuilderClass(Class<? extends ActivityLinkBuilder> activityLinkBuilderClass) {
060        this.activityLinkBuilderClass = activityLinkBuilderClass;
061    }
062
063    public ActivityLinkBuilder getActivityLinkBuilder() {
064        try {
065            return activityLinkBuilderClass.newInstance();
066        } catch (ReflectiveOperationException e) {
067            throw new NuxeoException(e);
068        }
069    }
070
071    public boolean isDefault() {
072        return isDefault;
073    }
074
075    public void setDefault(boolean isDefault) {
076        this.isDefault = isDefault;
077    }
078
079    public boolean isEnabled() {
080        return enabled;
081    }
082
083    public void setEnabled(boolean enabled) {
084        this.enabled = enabled;
085    }
086
087    @Override
088    public ActivityLinkBuilderDescriptor clone() {
089        ActivityLinkBuilderDescriptor clone = new ActivityLinkBuilderDescriptor();
090        clone.setName(name);
091        clone.setActivityLinkBuilderClass(activityLinkBuilderClass);
092        clone.setDefault(isDefault);
093        clone.setEnabled(enabled);
094        return clone;
095    }
096
097}