001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.rice.kew.api.action;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.core.api.CoreConstants;
020import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021import org.w3c.dom.Element;
022
023import javax.xml.bind.annotation.XmlAccessType;
024import javax.xml.bind.annotation.XmlAccessorType;
025import javax.xml.bind.annotation.XmlAnyElement;
026import javax.xml.bind.annotation.XmlElement;
027import javax.xml.bind.annotation.XmlRootElement;
028import javax.xml.bind.annotation.XmlType;
029import java.util.Collection;
030
031/**
032 * Represents the definition of an Action invocation against an action item.
033 * 
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 *
036 */
037@XmlRootElement(name = ActionInvocation.Constants.ROOT_ELEMENT_NAME)
038@XmlAccessorType(XmlAccessType.NONE)
039@XmlType(name = ActionInvocation.Constants.TYPE_NAME, propOrder = {
040        ActionInvocation.Elements.ACTION,
041        ActionInvocation.Elements.ACTION_ITEM_ID,
042        CoreConstants.CommonElements.FUTURE_ELEMENTS
043})
044public class ActionInvocation extends AbstractDataTransferObject {
045
046    @XmlElement(name = Elements.ACTION, required = true)
047    private final ActionType action;
048
049    @XmlElement(name = Elements.ACTION_ITEM_ID, required = true)
050    private final String actionItemId;
051
052    @SuppressWarnings("unused")
053    @XmlAnyElement
054    private final Collection<Element> _futureElements = null;
055
056    @SuppressWarnings("unused")
057    private ActionInvocation() {
058        this.action = null;
059        this.actionItemId = null;
060    }
061
062    private ActionInvocation(ActionType action, String actionItemId) {
063        if (action == null) {
064                        throw new IllegalArgumentException("action was null");
065                }
066        if (StringUtils.isBlank(actionItemId)) {
067                        throw new IllegalArgumentException("actionItemId was a null or blank value");
068                }
069                this.actionItemId = actionItemId;
070                this.action = action;
071    }
072
073    /**
074     * Creates a new {@code ActionInvocation} which indicates that the specified action should be executed against the
075     * action item with the given id.
076     *
077     * @param action the action to execute against the action item
078     * @param actionItemId the id of the action item against which to execute the action
079     *
080     * @return a new {@code ActionInvocation} containing the provided values
081     *
082     * @throws IllegalArgumentException if {@code action} is null or {@code actionItemId} is a null or blank value
083     */
084        public static ActionInvocation create(ActionType action, String actionItemId) {
085        return new ActionInvocation(action, actionItemId);
086        }
087                
088        public ActionType getAction() {
089                return action;
090        }
091        
092        public String getActionItemId() {
093                return actionItemId;
094        }
095
096    /**
097     * Defines some internal constants used on this class.
098     */
099    static class Constants {
100        final static String ROOT_ELEMENT_NAME = "actionInvocation";
101        final static String TYPE_NAME = "ActionInvocationType";
102    }
103
104    /**
105     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
106     */
107    static class Elements {
108        final static String ACTION = "action";
109        final static String ACTION_ITEM_ID = "actionItemId";
110    }
111                
112}