View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.api.action;
17  
18  import java.util.Collection;
19  import java.util.Collections;
20  import java.util.EnumSet;
21  import java.util.Set;
22  
23  import javax.xml.bind.annotation.XmlAccessType;
24  import javax.xml.bind.annotation.XmlAccessorType;
25  import javax.xml.bind.annotation.XmlAnyElement;
26  import javax.xml.bind.annotation.XmlElement;
27  import javax.xml.bind.annotation.XmlRootElement;
28  import javax.xml.bind.annotation.XmlType;
29  
30  import org.kuali.rice.core.api.CoreConstants;
31  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
32  import org.w3c.dom.Element;
33  
34  @XmlRootElement(name = RequestedActions.Constants.ROOT_ELEMENT_NAME)
35  @XmlAccessorType(XmlAccessType.NONE)
36  @XmlType(name = RequestedActions.Constants.TYPE_NAME, propOrder = {
37  		RequestedActions.Elements.COMPLETE_REQUESTED,
38  		RequestedActions.Elements.APPROVE_REQUESTED,
39  		RequestedActions.Elements.ACKNOWLEDGE_REQUESTED,
40  		RequestedActions.Elements.FYI_REQUESTED,
41  		CoreConstants.CommonElements.FUTURE_ELEMENTS
42  })
43  public final class RequestedActions extends AbstractDataTransferObject {
44      
45  	private static final long serialVersionUID = -6600754341497697330L;
46  
47      @XmlElement(name = Elements.COMPLETE_REQUESTED, required = true)
48      private final boolean completeRequested;
49  	
50  	@XmlElement(name = Elements.APPROVE_REQUESTED, required = true)
51      private final boolean approveRequested;
52  	
53  	@XmlElement(name = Elements.ACKNOWLEDGE_REQUESTED, required = true)
54  	private final boolean acknowledgeRequested;
55  	
56  	@XmlElement(name = Elements.FYI_REQUESTED, required = true)
57  	private final boolean fyiRequested;
58      
59      @SuppressWarnings("unused")
60      @XmlAnyElement
61      private final Collection<Element> _futureElements = null;
62  
63      private RequestedActions() {
64      	this.completeRequested = false;
65      	this.approveRequested = false;
66      	this.acknowledgeRequested = false;
67      	this.fyiRequested = false;
68      }
69      
70      private RequestedActions(boolean completeRequested, boolean approveRequested, boolean acknowledgeRequested, boolean fyiRequested) {
71      	this.completeRequested = completeRequested;
72      	this.approveRequested = approveRequested;
73      	this.acknowledgeRequested = acknowledgeRequested;
74      	this.fyiRequested = fyiRequested;
75      }
76      
77      public static RequestedActions create(boolean completeRequested, boolean approveRequested, boolean acknowledgeRequested, boolean fyiRequested) {
78      	return new RequestedActions(completeRequested, approveRequested, acknowledgeRequested, fyiRequested);
79      }
80      
81  	public boolean isCompleteRequested() {
82  		return completeRequested;
83  	}
84  
85  	public boolean isApproveRequested() {
86  		return approveRequested;
87  	}
88  
89  	public boolean isAcknowledgeRequested() {
90  		return acknowledgeRequested;
91  	}
92  
93  	public boolean isFyiRequested() {
94  		return fyiRequested;
95      }
96  
97      /**
98       * Returns a Set of {@link ActionRequestType}s which indicate the actions which have been requested.  This will
99       * essentially contain request types for any of the request-related methods on this class which return "true".  If
100      * no actions are requested, the empty set will be returned (this method will never return null).
101      *
102      * @return an unmodifiable Set of action request types which have been requested, or an empty set if no actions are
103      * requested
104      */
105     public Set<ActionRequestType> getRequestedActions() {
106         EnumSet<ActionRequestType> requestedActions = EnumSet.noneOf(ActionRequestType.class);
107         if (isCompleteRequested()) {
108             requestedActions.add(ActionRequestType.COMPLETE);
109         }
110         if (isApproveRequested()) {
111             requestedActions.add(ActionRequestType.APPROVE);
112         }
113         if (isAcknowledgeRequested()) {
114             requestedActions.add(ActionRequestType.ACKNOWLEDGE);
115         }
116         if (isFyiRequested()) {
117             requestedActions.add(ActionRequestType.FYI);
118         }
119         return Collections.unmodifiableSet(requestedActions);
120     }
121 
122     /**
123      * Returns true if this set of requested actions contains the given action request type.
124      *
125      * @param actionRequestType the {@link ActionRequestType} to check for, can't be null
126      *
127      * @return true if the action is requested, false otherwise
128      *
129      * @throws IllegalArgumentException if actionRequestType is null
130      */
131     public boolean contains(ActionRequestType actionRequestType) {
132         if (actionRequestType == null) {
133             throw new IllegalArgumentException("actionRequestType was null");
134         }
135         return getRequestedActions().contains(actionRequestType);
136     }
137     
138     /**
139      * Defines some internal constants used on this class.
140      */
141     static class Constants {
142         final static String ROOT_ELEMENT_NAME = "requestedActions";
143         final static String TYPE_NAME = "RequestedActionsType";
144     }
145     
146     /**
147      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
148      */
149     static class Elements {
150         final static String COMPLETE_REQUESTED = "completeRequested";
151         final static String APPROVE_REQUESTED = "approveRequested";
152         final static String ACKNOWLEDGE_REQUESTED = "acknowledgeRequested";
153         final static String FYI_REQUESTED = "fyiRequested";
154     }
155 
156 }