View Javadoc
1   /*
2    * Copyright 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  package org.kuali.ole.sys.document.datadictionary;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.ole.sys.businessobject.AccountingLine;
22  import org.kuali.ole.sys.document.web.TableJoining;
23  import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase;
24  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
25  
26  /**
27   * Data dictionary definition of information about how to render an accounting line.
28   */
29  public class AccountingLineViewDefinition extends DataDictionaryDefinitionBase {
30      private List<AccountingLineViewRenderableElementDefinition> elements;
31  
32      /**
33       * Checks that this accounting line view has at least one child renderable element.  Also checks
34       * that none of its direct children elements are "line" elements 
35       * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
36       */
37      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
38          if (elements == null || elements.size() == 0) {
39              // there's not even one element. not even one.
40              throw new AttributeValidationException("Please specify at least one element to be rendered for an accounting line view.");
41          }
42          for (AccountingLineViewRenderableElementDefinition elementDefinition : elements) {
43              if (elementDefinition instanceof AccountingLineViewLineDefinition) {
44                  throw new AttributeValidationException("AccountingViewLine definitions must always be wrapped by AccountingLineViewLines definitions");
45              }
46          }
47      }
48  
49      /**
50       * Gets the elements attribute. 
51       * @return Returns the elements.
52       */
53      public List<AccountingLineViewRenderableElementDefinition> getElements() {
54          return elements;
55      }
56  
57      /**
58       * Sets the elements attribute value.
59       * @param elements The elements to set.
60       */
61      public void setElements(List<AccountingLineViewRenderableElementDefinition> elements) {
62          this.elements = elements;
63      }
64      
65      /**
66       * Creates a list of layout elements for this accounting line view
67       * @param accountingLineClass the class of the accounting line to be rendered by this view
68       * @return a List of TableJoining layout elements that represent how the accounting line should be rendered
69       */
70      public List<TableJoining> getAccountingLineLayoutElements(Class<? extends AccountingLine> accountingLineClass) {
71          List<TableJoining> layoutElements = new ArrayList<TableJoining>();
72          for (AccountingLineViewRenderableElementDefinition layoutElementDefinition : elements) {
73              final TableJoining layoutElement = layoutElementDefinition.createLayoutElement(accountingLineClass);
74              if (layoutElement != null) {
75                  layoutElements.add(layoutElement);
76              }
77          }
78          return layoutElements;
79      }
80  }