View Javadoc

1   /**
2    * Copyright 2005-2011 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.Set;
21  
22  import javax.xml.bind.annotation.XmlAccessType;
23  import javax.xml.bind.annotation.XmlAccessorType;
24  import javax.xml.bind.annotation.XmlAnyElement;
25  import javax.xml.bind.annotation.XmlElement;
26  import javax.xml.bind.annotation.XmlElementWrapper;
27  import javax.xml.bind.annotation.XmlRootElement;
28  import javax.xml.bind.annotation.XmlType;
29  
30  import org.apache.commons.lang.StringUtils;
31  import org.kuali.rice.core.api.CoreConstants;
32  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
33  import org.w3c.dom.Element;
34  
35  @XmlRootElement(name = AdHocRevoke.Constants.ROOT_ELEMENT_NAME)
36  @XmlAccessorType(XmlAccessType.NONE)
37  @XmlType(name = AdHocRevoke.Constants.TYPE_NAME, propOrder = {
38  		AdHocRevoke.Elements.NODE_NAMES,
39  		AdHocRevoke.Elements.PRINCIPAL_IDS,
40  		AdHocRevoke.Elements.GROUP_IDS,
41  		CoreConstants.CommonElements.FUTURE_ELEMENTS
42  })
43  public final class AdHocRevoke extends AbstractDataTransferObject {
44  
45  	private static final long serialVersionUID = 5848714514445793355L;
46  	
47  	@XmlElementWrapper(name = Elements.NODE_NAMES, required = false)
48  	@XmlElement(name = Elements.NODE_NAME, required = false)
49  	private final Set<String> nodeNames;
50  	
51  	@XmlElementWrapper(name = Elements.PRINCIPAL_IDS, required = false)
52  	@XmlElement(name = Elements.PRINCIPAL_ID, required = false)
53  	private final Set<String> principalIds;
54  	
55  	@XmlElementWrapper(name = Elements.GROUP_IDS, required = false)
56  	@XmlElement(name = Elements.GROUP_ID, required = false)
57  	private final Set<String> groupIds;
58  		
59      @SuppressWarnings("unused")
60      @XmlAnyElement
61      private final Collection<Element> _futureElements = null;
62  	
63      /**
64       * Private constructor used only by JAXB.
65       */
66      private AdHocRevoke() {
67          this.nodeNames = null;
68          this.principalIds = null;
69          this.groupIds = null;
70      }
71  
72      
73      private AdHocRevoke(Set<String> nodeNames, Set<String> principalIds, Set<String> groupIds) {
74      	this.nodeNames = nodeNames;
75      	this.principalIds = principalIds;
76      	this.groupIds = groupIds;
77      }
78      
79      public static AdHocRevoke create(Set<String> nodeNames, Set<String> principalIds, Set<String> groupIds) {
80      	return new AdHocRevoke(nodeNames, principalIds, groupIds);
81      }
82      
83      public static AdHocRevoke createRevokeFromPrincipal(String principalId) {
84      	if (StringUtils.isBlank(principalId)) {
85      		throw new IllegalArgumentException("principalId was null or blank");
86      	}
87      	return create(null, Collections.singleton(principalId), null);
88      }
89      
90      public static AdHocRevoke createRevokeFromGroup(String groupId) {
91      	if (StringUtils.isBlank(groupId)) {
92      		throw new IllegalArgumentException("groupId was null or blank");
93      	}
94      	return create(null, null, Collections.singleton(groupId));
95      }
96      
97      public static AdHocRevoke createRevokeAtNode(String nodeName) {
98      	if (StringUtils.isBlank(nodeName)) {
99      		throw new IllegalArgumentException("nodeName was null or blank");
100     	}
101     	return create(Collections.singleton(nodeName), null, null);
102     }
103     
104 	public Set<String> getNodeNames() {
105 		if (nodeNames == null) {
106 			return Collections.emptySet();
107 		}
108 		return Collections.unmodifiableSet(nodeNames);
109 	}
110 	
111 	public Set<String> getPrincipalIds() {
112 		if (principalIds == null) {
113 			return Collections.emptySet();
114 		}
115 		return Collections.unmodifiableSet(principalIds);
116 	}
117 	
118 	public Set<String> getGroupIds() {
119 		if (groupIds == null) {
120 			return Collections.emptySet();
121 		}
122 		return Collections.unmodifiableSet(groupIds);
123 	}
124 	
125 	/**
126      * Defines some internal constants used on this class.
127      */
128     static class Constants {
129         final static String ROOT_ELEMENT_NAME = "adHocRevoke";
130         final static String TYPE_NAME = "AdHocRevokeType";
131     }
132     
133     /**
134      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
135      */
136     static class Elements {
137     	final static String NODE_NAMES = "nodeNames";
138         final static String NODE_NAME = "nodeName";
139         final static String PRINCIPAL_IDS = "principalIds";
140         final static String PRINCIPAL_ID = "principalId";
141         final static String GROUP_IDS = "groupIds";
142         final static String GROUP_ID = "groupId";
143     }
144 
145 }