View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.batch;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.springframework.beans.factory.InitializingBean;
22  
23  
24  /**
25   * Abstract class which is the parent of all FlatFileSpecification implementations
26   */
27  public abstract class AbstractFlatFileSpecificationBase implements FlatFileSpecification, InitializingBean {
28      protected Class<?> defaultBusinessObjectClass;
29      protected List<FlatFileObjectSpecification> objectSpecifications;
30      private List<Class<?>> childrenList = new ArrayList<Class<?>>();
31      
32      /**
33       * @see org.kuali.ole.sys.batch.FlatFileSpecification#getObjectSpecification(Class)
34       */
35      public FlatFileObjectSpecification getObjectSpecification(Class<?> businessObjectClass) {
36          for (FlatFileObjectSpecification objectSpecification : objectSpecifications) {
37              if (objectSpecification.getBusinessObjectClass().equals(businessObjectClass)) {
38                  return objectSpecification;
39              }
40          }
41          return null;
42      }
43  
44      /**
45       * @see org.kuali.ole.sys.batch.FlatFileSpecification#getObjectSpecifications()
46       */
47      public List<FlatFileObjectSpecification> getObjectSpecifications() {
48          return objectSpecifications;
49      }
50      
51  
52      /**
53       * Sets the list of FlatFileObjectSpecifications which instruct the FlatFileSpecification how to parse
54       * @param objectSpecifications
55       */
56      public void setObjectSpecifications(List<FlatFileObjectSpecification> objectSpecifications) {
57          this.objectSpecifications = objectSpecifications;
58      }
59  
60      public void setDefaultBusinessObjectClass(Class<?> businessObjectClass) {
61          this.defaultBusinessObjectClass = businessObjectClass;
62      }
63      
64      public void afterPropertiesSet() throws Exception{
65          Class<?> child;
66          for(FlatFileObjectSpecification specification: objectSpecifications) {
67              if(specification.getParentBusinessObjectClass() != null) {
68                  child = specification.getBusinessObjectClass();
69                  if(childrenList.contains(child)) {
70                      //A child can't appear twice within the same configuration, without having two parents
71                      throw new Exception("The child " + child + " can't have more than one parent");
72                  } else {
73                      childrenList.add(child);
74                  }
75              }
76          }
77      }
78  
79  }