View Javadoc

1   /*
2    * Copyright 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/ecl1.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.document;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.List;
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.XmlElementWrapper;
28  import javax.xml.bind.annotation.XmlRootElement;
29  import javax.xml.bind.annotation.XmlType;
30  
31  import org.kuali.rice.core.api.CoreConstants;
32  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
33  import org.kuali.rice.core.api.mo.ModelBuilder;
34  import org.kuali.rice.kew.api.action.ActionRequest;
35  import org.kuali.rice.kew.api.action.ActionTaken;
36  import org.kuali.rice.kew.api.document.node.RouteNodeInstance;
37  import org.w3c.dom.Element;
38  
39  @XmlRootElement(name = DocumentDetail.Constants.ROOT_ELEMENT_NAME)
40  @XmlAccessorType(XmlAccessType.NONE)
41  @XmlType(name = DocumentDetail.Constants.TYPE_NAME, propOrder = {
42      DocumentDetail.Elements.DOCUMENT,
43      DocumentDetail.Elements.ACTION_REQUESTS,
44      DocumentDetail.Elements.ACTIONS_TAKEN,
45      DocumentDetail.Elements.ROUTE_NODE_INSTANCES,
46      CoreConstants.CommonElements.FUTURE_ELEMENTS
47  })
48  public final class DocumentDetail extends AbstractDataTransferObject implements DocumentDetailContract {
49  
50  	private static final long serialVersionUID = -8569515693892958719L;
51  
52  	@XmlElement(name = Elements.DOCUMENT, required = true)
53      private final Document document;
54      
55      @XmlElementWrapper(name = Elements.ACTION_REQUESTS, required = true)
56      @XmlElement(name = Elements.ACTION_REQUEST, required = false)
57      private final List<ActionRequest> actionRequests;
58      
59      @XmlElementWrapper(name = Elements.ACTIONS_TAKEN, required = true)
60      @XmlElement(name = Elements.ACTION_TAKEN, required = false)
61      private final List<ActionTaken> actionsTaken;
62      
63      @XmlElementWrapper(name = Elements.ROUTE_NODE_INSTANCES, required = true)
64      @XmlElement(name = Elements.ROUTE_NODE_INSTANCES, required = true)
65      private final List<RouteNodeInstance> routeNodeInstances;
66      
67      @SuppressWarnings("unused")
68      @XmlAnyElement
69      private final Collection<Element> _futureElements = null;
70  
71      /**
72       * Private constructor used only by JAXB.
73       */
74      private DocumentDetail() {
75          this.document = null;
76          this.actionRequests = null;
77          this.actionsTaken = null;
78          this.routeNodeInstances = null;
79      }
80  
81      private DocumentDetail(Builder builder) {
82          this.document = builder.getDocument();
83          this.actionRequests = builder.getActionRequests();
84          this.actionsTaken = builder.getActionsTaken();
85          this.routeNodeInstances = builder.getRouteNodeInstances();
86      }
87  
88      @Override
89      public Document getDocument() {
90          return this.document;
91      }
92  
93      @Override
94      public List<ActionRequest> getActionRequests() {
95          return this.actionRequests;
96      }
97  
98      @Override
99      public List<ActionTaken> getActionsTaken() {
100         return this.actionsTaken;
101     }
102 
103     @Override
104     public List<RouteNodeInstance> getRouteNodeInstances() {
105         return this.routeNodeInstances;
106     }
107 
108 
109     /**
110      * A builder which can be used to construct {@link DocumentDetail} instances.  Enforces the constraints of the {@link DocumentDetailContract}.
111      */
112     public final static class Builder implements Serializable, ModelBuilder, DocumentDetailContract {
113 
114 		private static final long serialVersionUID = 3108177943363491329L;
115 
116 		private Document document;
117         private List<ActionRequest> actionRequests;
118         private List<ActionTaken> actionsTaken;
119         private List<RouteNodeInstance> routeNodeInstances;
120 
121         private Builder() {
122             // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods
123         }
124 
125         public static Builder create(Document document) {
126             Builder builder = new Builder();
127             builder.setDocument(document);
128             builder.setActionRequests(new ArrayList<ActionRequest>());
129             builder.setActionsTaken(new ArrayList<ActionTaken>());
130             builder.setRouteNodeInstances(new ArrayList<RouteNodeInstance>());
131             return builder;
132         }
133 
134         public static Builder create(DocumentDetailContract contract) {
135             if (contract == null) {
136                 throw new IllegalArgumentException("contract was null");
137             }
138             Builder builder = create(contract.getDocument());
139             builder.setActionRequests(contract.getActionRequests());
140             builder.setActionsTaken(contract.getActionsTaken());
141             builder.setRouteNodeInstances(contract.getRouteNodeInstances());
142             return builder;
143         }
144 
145         public DocumentDetail build() {
146             return new DocumentDetail(this);
147         }
148 
149         @Override
150         public Document getDocument() {
151             return this.document;
152         }
153 
154         @Override
155         public List<ActionRequest> getActionRequests() {
156             return this.actionRequests;
157         }
158 
159         @Override
160         public List<ActionTaken> getActionsTaken() {
161             return this.actionsTaken;
162         }
163 
164         @Override
165         public List<RouteNodeInstance> getRouteNodeInstances() {
166             return this.routeNodeInstances;
167         }
168 
169         public void setDocument(Document document) {
170             if (document == null) {
171             	throw new IllegalArgumentException("document was null");
172             }
173             this.document = document;
174         }
175 
176         public void setActionRequests(List<ActionRequest> actionRequests) {
177             if (actionRequests == null) {
178             	throw new IllegalArgumentException("actionRequests was null");
179             }
180             this.actionRequests = actionRequests;
181         }
182 
183         public void setActionsTaken(List<ActionTaken> actionsTaken) {
184         	if (actionsTaken == null) {
185             	throw new IllegalArgumentException("actionsTaken was null");
186             }
187             this.actionsTaken = actionsTaken;
188         }
189 
190         public void setRouteNodeInstances(List<RouteNodeInstance> routeNodeInstances) {
191         	if (routeNodeInstances == null) {
192             	throw new IllegalArgumentException("routeNodeInstances was null");
193             }
194             this.routeNodeInstances = routeNodeInstances;
195         }
196 
197     }
198 
199     /**
200      * Defines some internal constants used on this class.
201      */
202     static class Constants {
203         final static String ROOT_ELEMENT_NAME = "documentDetail";
204         final static String TYPE_NAME = "DocumentDetailType";
205     }
206 
207     /**
208      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
209      */
210     static class Elements {
211         final static String DOCUMENT = "document";
212         final static String ACTION_REQUESTS = "actionRequests";
213         final static String ACTION_REQUEST = "actionRequest";
214         final static String ACTIONS_TAKEN = "actionsTaken";
215         final static String ACTION_TAKEN = "actionTaken";
216         final static String ROUTE_NODE_INSTANCES = "routeNodeInstances";
217         final static String ROUTE_NODE_INSTANCE = "routeNodeInstance";
218     }
219 
220 }
221