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