001/*
002 * Copyright 2008 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.ole.sys.document.datadictionary;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import org.kuali.ole.sys.businessobject.AccountingLine;
022import org.kuali.ole.sys.document.web.TableJoining;
023import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase;
024import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
025
026/**
027 * Data dictionary definition of information about how to render an accounting line.
028 */
029public class AccountingLineViewDefinition extends DataDictionaryDefinitionBase {
030    private List<AccountingLineViewRenderableElementDefinition> elements;
031
032    /**
033     * Checks that this accounting line view has at least one child renderable element.  Also checks
034     * that none of its direct children elements are "line" elements 
035     * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
036     */
037    public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
038        if (elements == null || elements.size() == 0) {
039            // there's not even one element. not even one.
040            throw new AttributeValidationException("Please specify at least one element to be rendered for an accounting line view.");
041        }
042        for (AccountingLineViewRenderableElementDefinition elementDefinition : elements) {
043            if (elementDefinition instanceof AccountingLineViewLineDefinition) {
044                throw new AttributeValidationException("AccountingViewLine definitions must always be wrapped by AccountingLineViewLines definitions");
045            }
046        }
047    }
048
049    /**
050     * Gets the elements attribute. 
051     * @return Returns the elements.
052     */
053    public List<AccountingLineViewRenderableElementDefinition> getElements() {
054        return elements;
055    }
056
057    /**
058     * Sets the elements attribute value.
059     * @param elements The elements to set.
060     */
061    public void setElements(List<AccountingLineViewRenderableElementDefinition> elements) {
062        this.elements = elements;
063    }
064    
065    /**
066     * Creates a list of layout elements for this accounting line view
067     * @param accountingLineClass the class of the accounting line to be rendered by this view
068     * @return a List of TableJoining layout elements that represent how the accounting line should be rendered
069     */
070    public List<TableJoining> getAccountingLineLayoutElements(Class<? extends AccountingLine> accountingLineClass) {
071        List<TableJoining> layoutElements = new ArrayList<TableJoining>();
072        for (AccountingLineViewRenderableElementDefinition layoutElementDefinition : elements) {
073            final TableJoining layoutElement = layoutElementDefinition.createLayoutElement(accountingLineClass);
074            if (layoutElement != null) {
075                layoutElements.add(layoutElement);
076            }
077        }
078        return layoutElements;
079    }
080}