001/*
002 * (C) Copyright 2006-2010 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 *     Laurent Doguin
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.mail.action;
021
022import org.nuxeo.common.xmap.annotation.XNode;
023import org.nuxeo.common.xmap.annotation.XObject;
024import org.nuxeo.ecm.platform.mail.listener.action.CreateDocumentsFromAutomationChainAction;
025
026/**
027 * @author Laurent Doguin
028 */
029@XObject("action")
030public class MessageActionDescriptor {
031
032    @XNode("@id")
033    private String id;
034
035    @XNode("@to")
036    private String to;
037
038    @XNode("@chain")
039    private String chain;
040
041    @XNode
042    Class<? extends MessageAction> action;
043
044    public String getTo() {
045        return to;
046    }
047
048    public void setTo(String to) {
049        this.to = to;
050    }
051
052    public String getId() {
053        if (id == null || "".equals(id)) {
054            id = action.getSimpleName();
055        }
056        return id;
057    }
058
059    public MessageAction getAction() {
060        try {
061            if (action == null || chain != null) {
062                return new CreateDocumentsFromAutomationChainAction(chain);
063            }
064            return action.newInstance();
065        } catch (InstantiationException e) {
066            throw new RuntimeException("Could not get MessageAction new Instance", e);
067        } catch (IllegalAccessException e) {
068            throw new RuntimeException(e);
069        }
070    }
071
072}