001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.data.metadata.impl; 017 018import java.util.Collections; 019import java.util.List; 020 021import org.kuali.rice.krad.data.metadata.DataObjectCollection; 022import org.kuali.rice.krad.data.metadata.DataObjectCollectionSortAttribute; 023 024/** 025* Collection meta data. 026* 027* <p> 028* Implementation that represents the meta data for a collection in a data object. 029* </p> 030* 031* @author Kuali Rice Team (rice.collab@kuali.org) 032*/ 033public class DataObjectCollectionImpl extends MetadataChildBase implements DataObjectCollection { 034 private static final long serialVersionUID = -785119931770775640L; 035 036 protected DataObjectCollection embeddedCollection; 037 038 protected String elementLabel; 039 protected Long minItems; 040 protected Long maxItems; 041 protected List<DataObjectCollectionSortAttribute> defaultOrdering; 042 protected Boolean indirectCollection; 043 044 /** 045 * The elementLabel defines the name to be used for a single object within the collection. 046 * 047 * <p> 048 * For example: "Address" may be the name of one object within the "Addresses" collection. 049 * </p> 050 */ 051 @Override 052 public String getElementLabel() { 053 if (elementLabel == null) { 054 elementLabel = getLabelFromPropertyName(relatedType.getSimpleName()); 055 } 056 return elementLabel; 057 } 058 059 /** 060 * Sets name used for single object within collection. 061 * 062 * @param elementLabel single object name 063 */ 064 public void setElementLabel(String elementLabel) { 065 this.elementLabel = elementLabel; 066 } 067 068 @Override 069 public Long getMinItems() { 070 if (minItems != null) { 071 return minItems; 072 } 073 if (embeddedCollection != null) { 074 return embeddedCollection.getMinItems(); 075 } 076 return null; 077 } 078 079 /** 080 * Sets minimum items in collection. 081 * 082 * @param minOccurs minimum items in collection. 083 */ 084 public void setMinItemsInCollection(Long minOccurs) { 085 this.minItems = minOccurs; 086 } 087 088 /** 089 * {@inheritDoc} 090 */ 091 @Override 092 public Long getMaxItems() { 093 if (maxItems != null) { 094 return maxItems; 095 } 096 if (embeddedCollection != null) { 097 return embeddedCollection.getMaxItems(); 098 } 099 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}