View Javadoc

1   /**
2    * Copyright 2005-2012 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.datadictionary;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.bo.BusinessObject;
20  import org.kuali.rice.krad.datadictionary.exception.ClassValidationException;
21  
22  import java.util.List;
23  
24  /**
25   * A single BusinessObject entry in the DataDictionary, which contains information relating to the display, validation,
26   * and general maintenance of a BusinessObject and its attributes.
27   *
28   * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class BusinessObjectEntry extends DataObjectEntry {
33  
34      protected Class<? extends BusinessObject> baseBusinessObjectClass;
35  
36      public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
37          super.setDataObjectClass(businessObjectClass);
38  
39          if (businessObjectClass == null) {
40              throw new IllegalArgumentException("invalid (null) dataObjectClass");
41          }
42  
43          if (getRelationships() != null) {
44              for (RelationshipDefinition rd : getRelationships()) {
45                  rd.setSourceClass(businessObjectClass);
46              }
47          }
48      }
49  
50      public Class<? extends BusinessObject> getBusinessObjectClass() {
51          return (Class<? extends BusinessObject>) super.getDataObjectClass();
52      }
53  
54      /**
55       * The baseBusinessObjectClass is an optional parameter for specifying a superclass
56       * for the dataObjectClass, allowing the data dictionary to index by superclass
57       * in addition to the current class.
58       */
59  
60      public void setBaseBusinessObjectClass(Class<? extends BusinessObject> baseBusinessObjectClass) {
61          this.baseBusinessObjectClass = baseBusinessObjectClass;
62      }
63  
64      public Class<? extends BusinessObject> getBaseBusinessObjectClass() {
65          return baseBusinessObjectClass;
66      }
67  
68      /**
69       * Directly validate simple fields, call completeValidation on Definition fields.
70       */
71      @Override
72      public void completeValidation() {
73          try {
74  
75              if (baseBusinessObjectClass != null && !baseBusinessObjectClass.isAssignableFrom(getDataObjectClass())) {
76                  throw new ClassValidationException("The baseBusinessObjectClass " + baseBusinessObjectClass.getName() +
77                          " is not a superclass of the dataObjectClass " + getDataObjectClass().getName());
78              }
79  
80              super.completeValidation();
81  
82              if (inactivationBlockingDefinitions != null && !inactivationBlockingDefinitions.isEmpty()) {
83                  for (InactivationBlockingDefinition inactivationBlockingDefinition : inactivationBlockingDefinitions) {
84                      inactivationBlockingDefinition.completeValidation(getDataObjectClass(), null);
85                  }
86              }
87          } catch (DataDictionaryException ex) {
88              // just rethrow
89              throw ex;
90          } catch (Exception ex) {
91              throw new DataDictionaryException("Exception validating " + this, ex);
92          }
93      }
94  
95      /**
96       * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase#afterPropertiesSet()
97       */
98      @SuppressWarnings("unchecked")
99      @Override
100     public void afterPropertiesSet() throws Exception {
101         super.afterPropertiesSet();
102         if (inactivationBlockingDefinitions != null) {
103             for (InactivationBlockingDefinition ibd : inactivationBlockingDefinitions) {
104                 ibd.setBusinessObjectClass(getBusinessObjectClass());
105                 if (StringUtils.isNotBlank(ibd.getBlockedReferencePropertyName()) &&
106                         ibd.getBlockedBusinessObjectClass() == null) {
107                     // if the user didn't specify a class name for the blocked reference, determine it here
108                     ibd.setBlockedBusinessObjectClass(DataDictionary
109                             .getAttributeClass(getDataObjectClass(), ibd.getBlockedReferencePropertyName()));
110                 }
111                 ibd.setBlockingReferenceBusinessObjectClass(getBusinessObjectClass());
112             }
113         }
114     }
115 
116     /**
117      * @see java.lang.Object#toString()
118      */
119     @Override
120     public String toString() {
121         return "BusinessObjectEntry for " + getBusinessObjectClass();
122     }
123 }