View Javadoc
1   /**
2    * Copyright 2005-2014 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.krad.data.metadata.impl;
17  
18  import java.util.Collections;
19  import java.util.List;
20  
21  import org.kuali.rice.krad.data.metadata.DataObjectCollection;
22  import org.kuali.rice.krad.data.metadata.DataObjectCollectionSortAttribute;
23  
24  /**
25  * Collection meta data.
26  *
27  * <p>
28  * Implementation that represents the meta data for a collection in a data object.
29  * </p>
30  *
31  * @author Kuali Rice Team (rice.collab@kuali.org)
32  */
33  public class DataObjectCollectionImpl extends MetadataChildBase implements DataObjectCollection {
34  	private static final long serialVersionUID = -785119931770775640L;
35  
36  	protected DataObjectCollection embeddedCollection;
37  
38      protected String elementLabel;
39  	protected Long minItems;
40  	protected Long maxItems;
41  	protected List<DataObjectCollectionSortAttribute> defaultOrdering;
42  	protected Boolean indirectCollection;
43  
44      /**
45      * The elementLabel defines the name to be used for a single object within the collection.
46      *
47      * <p>
48      * For example: "Address" may be the name of one object within the "Addresses" collection.
49      * </p>
50      */
51      @Override
52  	public String getElementLabel() {
53  		if (elementLabel == null) {
54  			elementLabel = getLabelFromPropertyName(relatedType.getSimpleName());
55  		}
56          return elementLabel;
57      }
58  
59      /**
60      * Sets name used for single object within collection.
61      *
62      * @param elementLabel single object name
63      */
64      public void setElementLabel(String elementLabel) {
65          this.elementLabel = elementLabel;
66      }
67  
68  	@Override
69  	public Long getMinItems() {
70  		if (minItems != null) {
71  			return minItems;
72  		}
73  		if (embeddedCollection != null) {
74  			return embeddedCollection.getMinItems();
75  		}
76  		return null;
77      }
78  
79      /**
80      * Sets minimum items in collection.
81      *
82      * @param minOccurs minimum items in collection.
83      */
84  	public void setMinItemsInCollection(Long minOccurs) {
85  		this.minItems = minOccurs;
86      }
87  
88      /**
89      * {@inheritDoc}
90      */
91  	@Override
92  	public Long getMaxItems() {
93  		if (maxItems != null) {
94  			return maxItems;
95  		}
96  		if (embeddedCollection != null) {
97  			return embeddedCollection.getMaxItems();
98  		}
99  		return null;
100     }
101 
102     /**
103     * Sets maximum items in collection.
104     *
105     * @param maxOccurs maximum items in collection.
106     */
107 	public void setMaxItemsInCollection(Long maxOccurs) {
108 		this.maxItems = maxOccurs;
109     }
110 
111     /**
112     * {@inheritDoc}
113     */
114 	@Override
115 	public List<DataObjectCollectionSortAttribute> getDefaultOrdering() {
116 		if (defaultOrdering != null) {
117 			return defaultOrdering;
118 		}
119 		if (embeddedCollection != null) {
120 			return embeddedCollection.getDefaultOrdering();
121 		}
122 		return Collections.emptyList();
123 	}
124 
125     /**
126     * Sets attribute that the default order of the collection.
127     *
128     * @param defaultCollectionOrdering attribute name
129     */
130 	public void setDefaultCollectionOrderingAttributeNames(
131 			List<DataObjectCollectionSortAttribute> defaultCollectionOrdering) {
132 		this.defaultOrdering = defaultCollectionOrdering;
133 	}
134 
135     /**
136     * {@inheritDoc}
137     */
138 	@Override
139 	public boolean isIndirectCollection() {
140 		if (indirectCollection != null) {
141 			return indirectCollection;
142 		}
143 		if (embeddedCollection != null) {
144 			return embeddedCollection.isIndirectCollection();
145 		}
146 		return false;
147 	}
148 
149     /**
150     * Sets whether linked item is used.
151     *
152     * @param indirectCollection whether link item used.
153     */
154 	public void setIndirectCollection(boolean indirectCollection) {
155 		this.indirectCollection = indirectCollection;
156 	}
157 
158     /**
159     * Gets the embedded collection.
160     *
161     * @return the embedded collection, if it exists.
162     */
163 	public DataObjectCollection getEmbeddedCollection() {
164 		return embeddedCollection;
165 	}
166 
167 	public void setEmbeddedCollection(DataObjectCollection embeddedCollection) {
168 		this.embeddedCollection = embeddedCollection;
169 		setEmbeddedMetadataChild(embeddedCollection);
170 	}
171 
172 }