View Javadoc

1   /*
2    * Copyright 2005-2008 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  
17  package org.kuali.rice.kns.datadictionary;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
21  import org.kuali.rice.kns.datadictionary.validation.capability.CollectionSizeConstrainable;
22  
23  /**
24   * A single Collection attribute definition in the DataDictionary, which contains information relating to the display, validation,
25   * and general maintenance of a specific Collection attribute of an entry.
26   * 
27   * 
28   */
29  public class CollectionDefinition extends DataDictionaryDefinitionBase implements CollectionSizeConstrainable{
30      private static final long serialVersionUID = -2644072136271281041L;
31      
32      protected String dataObjectClass;
33      protected String name;
34      protected String label;
35      protected String shortLabel;
36      protected String elementLabel;
37      
38      protected String summary;
39  
40  	protected String description;
41      
42  	protected Integer minOccurs;
43  	protected Integer maxOccurs;
44  
45      public CollectionDefinition() {
46      	//empty
47      }
48  
49      public String getName() {
50          return name;
51      }
52  
53      public void setName(String name) {
54          if (StringUtils.isBlank(name)) {
55              throw new IllegalArgumentException("invalid (blank) name");
56          }
57          this.name = name;
58      }
59  
60      public String getLabel() {
61          return label;
62      }
63  
64      public void setLabel(String label) {
65          if (StringUtils.isBlank(label)) {
66              throw new IllegalArgumentException("invalid (blank) label");
67          }
68          this.label = label;
69      }
70  
71      /**
72       * @return the shortLabel, or the label if no shortLabel has been set
73       */
74      public String getShortLabel() {
75          return (shortLabel != null) ? shortLabel : label;
76      }
77  
78      public void setShortLabel(String shortLabel) {
79          if (StringUtils.isBlank(shortLabel)) {
80              throw new IllegalArgumentException("invalid (blank) shortLabel");
81          }
82          this.shortLabel = shortLabel;
83      }
84  
85      /**
86       * Gets the elementLabel attribute. 
87       * @return Returns the elementLabel.
88       */
89      public String getElementLabel() {
90          return elementLabel;
91      }
92  
93      /**
94   	 * The elementLabel defines the name to be used for a single object
95       * within the collection.  For example: "Address" may be the name
96       * of one object within the "Addresses" collection.
97       */
98      public void setElementLabel(String elementLabel) {
99          this.elementLabel = elementLabel;
100     }
101 
102     public String getSummary() {
103         return summary;
104     }
105 
106     /**
107 	 * The summary element is used to provide a short description of the
108      * attribute or collection.  This is designed to be used for help purposes.
109      */
110     public void setSummary(String summary) {
111         this.summary = summary;
112     }
113 
114     public String getDescription() {
115         return description;
116     }
117 
118     /**
119 	 * The description element is used to provide a long description of the
120 	 * attribute or collection.  This is designed to be used for help purposes.
121      */
122     public void setDescription(String description) {
123         this.description = description;
124     }
125     
126            
127     /**
128 	 * @return the objectClass
129 	 */
130 	public String getDataObjectClass() {
131 		return this.dataObjectClass;
132 	}
133 
134 	/**
135 	 * @param objectClass the objectClass to set
136 	 */
137 	public void setDataObjectClass(String dataObjectClass) {
138 		this.dataObjectClass = dataObjectClass;
139 	}
140 
141 	/**
142      * Directly validate simple fields, call completeValidation on Definition fields.
143      * 
144      * @see org.kuali.rice.kns.datadictionary.DataDictionaryEntry#completeValidation()
145      */
146     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
147         if (!DataDictionary.isCollectionPropertyOf(rootBusinessObjectClass, name)) {
148             throw new AttributeValidationException("property '" + name + "' is not a collection property of class '" + rootBusinessObjectClass + "' (" + "" + ")");
149         }
150     }
151 
152 
153     /**
154      * @see java.lang.Object#toString()
155      */
156     @Override
157     public String toString() {
158         return "CollectionDefinition for collection " + getName();
159     }
160 
161 	/**
162 	 * @see org.kuali.rice.kns.datadictionary.validation.constraint.CollectionSizeConstraint#getMaximumNumberOfElements()
163 	 */
164 	@Override
165 	public Integer getMaximumNumberOfElements() {
166 		return this.maxOccurs;
167 	}
168 
169 	/**
170 	 * @see org.kuali.rice.kns.datadictionary.validation.constraint.CollectionSizeConstraint#getMinimumNumberOfElements()
171 	 */
172 	@Override
173 	public Integer getMinimumNumberOfElements() {
174 		return this.minOccurs;
175 	}
176 
177     /**
178 	 * @return the minOccurs
179 	 */
180 	public Integer getMinOccurs() {
181 		return this.minOccurs;
182 	}
183 
184 	/**
185 	 * @param minOccurs the minOccurs to set
186 	 */
187 	public void setMinOccurs(Integer minOccurs) {
188 		this.minOccurs = minOccurs;
189 	}
190 
191 	/**
192 	 * @return the maxOccurs
193 	 */
194 	public Integer getMaxOccurs() {
195 		return this.maxOccurs;
196 	}
197 
198 	/**
199 	 * @param maxOccurs the maxOccurs to set
200 	 */
201 	public void setMaxOccurs(Integer maxOccurs) {
202 		this.maxOccurs = maxOccurs;
203 	}
204 
205 }