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.framework.document.search;
17  
18  import org.apache.commons.collections.CollectionUtils;
19  import org.kuali.rice.core.api.CoreConstants;
20  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
21  import org.kuali.rice.core.api.mo.ModelBuilder;
22  import org.kuali.rice.core.api.mo.ModelObjectUtils;
23  import org.w3c.dom.Element;
24  
25  import javax.xml.bind.annotation.XmlAccessType;
26  import javax.xml.bind.annotation.XmlAccessorType;
27  import javax.xml.bind.annotation.XmlAnyElement;
28  import javax.xml.bind.annotation.XmlElement;
29  import javax.xml.bind.annotation.XmlElementWrapper;
30  import javax.xml.bind.annotation.XmlRootElement;
31  import javax.xml.bind.annotation.XmlType;
32  import java.io.Serializable;
33  import java.util.ArrayList;
34  import java.util.Collection;
35  import java.util.List;
36  
37  /**
38   * An immutable data transfer object implementation of the {@link DocumentSearchResultValuesContract}.
39   * Instances of this class should be constructed using the nested {@link Builder} class.
40   *
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  @XmlRootElement(name = DocumentSearchResultValues.Constants.ROOT_ELEMENT_NAME)
44  @XmlAccessorType(XmlAccessType.NONE)
45  @XmlType(name = DocumentSearchResultValues.Constants.TYPE_NAME, propOrder = {
46      DocumentSearchResultValues.Elements.RESULT_VALUES,
47      CoreConstants.CommonElements.FUTURE_ELEMENTS
48  })
49  public final class DocumentSearchResultValues extends AbstractDataTransferObject implements DocumentSearchResultValuesContract {
50  
51      @XmlElementWrapper(name = Elements.RESULT_VALUES, required = false)
52      @XmlElement(name = Elements.RESULT_VALUE, required = false)
53      private final List<DocumentSearchResultValue> resultValues;
54  
55      @SuppressWarnings("unused")
56      @XmlAnyElement
57      private final Collection<Element> _futureElements = null;
58  
59      /**
60       * Private constructor used only by JAXB.
61       */
62      @SuppressWarnings("unused")
63      private DocumentSearchResultValues() {
64          this.resultValues = null;
65      }
66  
67      private DocumentSearchResultValues(Builder builder) {
68          this.resultValues = ModelObjectUtils.buildImmutableCopy(builder.getResultValues());
69      }
70  
71      @Override
72      public List<DocumentSearchResultValue> getResultValues() {
73          return this.resultValues;
74      }
75  
76      /**
77       * A builder which can be used to construct {@link DocumentSearchResultValues} instances.  Enforces the
78       * constraints of the {@link DocumentSearchResultValuesContract}.
79       */
80      public final static class Builder implements Serializable, ModelBuilder, DocumentSearchResultValuesContract {
81  
82          private List<DocumentSearchResultValue.Builder> resultValues;
83  
84          private Builder() {
85              setResultValues(new ArrayList<DocumentSearchResultValue.Builder>());
86          }
87  
88          /**
89           * Creates new empty builder instance.  The various lists on this builder are initialized to empty lists.  The
90           * internal list of result value builders is initialized to an empty list.
91           *
92           * @return a new empty builder instance
93           */
94          public static Builder create() {
95              return new Builder();
96          }
97  
98          /**
99           * Creates a new builder instance initialized with copies of the properties from the given contract.
100          *
101          * @param contract the contract from which to copy properties
102          *
103          * @return a builder instance initialized with properties from the given contract
104          *
105          * @throws IllegalArgumentException if the given contract is null
106          */
107         public static Builder create(DocumentSearchResultValuesContract contract) {
108             if (contract == null) {
109                 throw new IllegalArgumentException("contract was null");
110             }
111             Builder builder = create();
112             if (!CollectionUtils.isEmpty(contract.getResultValues())) {
113                 for (DocumentSearchResultValueContract resultValueContract : contract.getResultValues()) {
114                     //builder.getResultValues().add(DocumentSearchResultValue.Builder.create(resultValueContract));
115                 }
116             }
117             return builder;
118         }
119 
120         @Override
121         public DocumentSearchResultValues build() {
122             return new DocumentSearchResultValues(this);
123         }
124 
125         @Override
126         public List<DocumentSearchResultValue.Builder> getResultValues() {
127             return this.resultValues;
128         }
129 
130         public void setResultValues(List<DocumentSearchResultValue.Builder> resultValues) {
131             this.resultValues = resultValues;
132         }
133 
134     }
135 
136     /**
137      * Defines some internal constants used on this class.
138      */
139     static class Constants {
140         final static String ROOT_ELEMENT_NAME = "documentSearchResultValues";
141         final static String TYPE_NAME = "DocumentSearchResultValuesType";
142     }
143 
144     /**
145      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
146      */
147     static class Elements {
148         final static String RESULT_VALUES = "resultValues";
149         final static String RESULT_VALUE = "resultValue";
150     }
151 
152 }