Coverage Report - org.kuali.rice.krad.datadictionary.impl.FieldOverrideForListElementInsertImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldOverrideForListElementInsertImpl
0%
0/33
0%
0/22
3.143
 
 1  
 /*
 2  
  * Copyright 2007-2010 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.impl;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.kuali.rice.krad.datadictionary.FieldOverride;
 21  
 
 22  
 /**
 23  
  * A Field Override used to insert elements into a Data Dictionary Bean.
 24  
  * 
 25  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 26  
  *
 27  
  */
 28  0
 public class FieldOverrideForListElementInsertImpl extends FieldOverrideForListElementBase  implements FieldOverride{
 29  
         
 30  
         private Object insertBefore;
 31  
     private Object insertAfter;
 32  
     
 33  
     public Object getInsertBefore() {
 34  0
         return insertBefore;
 35  
     }
 36  
 
 37  
     public void setInsertBefore(Object insertBefore) {
 38  0
         this.insertBefore = insertBefore;
 39  0
     }
 40  
 
 41  
     public Object getInsertAfter() {
 42  0
         return insertAfter;
 43  
     }
 44  
 
 45  
 
 46  
     public void setInsertAfter(Object insertAfter) {
 47  0
         this.insertAfter = insertAfter;
 48  0
     }
 49  
 
 50  
 
 51  
     protected void varifyConfig()
 52  
     {
 53  0
         if ( insertBefore != null && insertAfter != null )
 54  
         {
 55  0
             throw new RuntimeException("Configuration Error, insertBefore and insertAfter can not be both NOT-NULL");
 56  
         }
 57  0
         if ( insertBefore == null && insertAfter == null )
 58  
         {
 59  0
             throw new RuntimeException("Configuration Error, Either insertBefore or insertAfter should be NOT-NULL");            
 60  
         }
 61  0
     }
 62  
     
 63  
     private Object getObjectToInsert()
 64  
     {
 65  0
         Object objToInsert = null;
 66  0
         if ( insertBefore != null )
 67  
         {
 68  0
             objToInsert = insertBefore;
 69  
         }
 70  0
         if ( insertAfter != null )
 71  
         {
 72  0
             if ( objToInsert != null )
 73  
             {
 74  0
                 throw new RuntimeException("Configuration Error, insertBefore and insertAfter can not be both NOT-NULL");
 75  
             }
 76  0
             objToInsert = insertAfter;
 77  
         }
 78  0
         if ( objToInsert == null )
 79  
         {
 80  0
             throw new RuntimeException("Configuration Error, Either insertBefore or insertAfter must be NOT-NULL");                        
 81  
         }
 82  0
         return objToInsert;
 83  
     }
 84  
     
 85  
     public Object performFieldOverride(Object bean, Object property) {
 86  0
         Object objToInsert = getObjectToInsert();
 87  
         
 88  0
         List oldList = (List)property;
 89  
         
 90  0
         int insertPos = getElementPositionInList(getElement(), oldList);
 91  
 
 92  0
         if ( insertPos == -1 )
 93  
         {
 94  0
             insertPos = oldList.size();
 95  
         }
 96  
         else
 97  
         {
 98  0
             if ( insertAfter != null )
 99  
             {
 100  0
                 insertPos = insertPos + 1;
 101  
             }
 102  
         }
 103  
 
 104  0
         if ( objToInsert instanceof List )
 105  
         {
 106  0
             oldList.addAll(insertPos, (List)objToInsert);
 107  
         }
 108  
         else
 109  
         {
 110  0
             oldList.add(insertPos, objToInsert);
 111  
         }
 112  0
         return oldList;
 113  
     }
 114  
 }