| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FieldOverrideForListElementReplaceImpl | 
  | 
  | 2.5;2.5 | 
| 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.kns.datadictionary.impl; | |
| 17 | ||
| 18 |  import java.util.List; | |
| 19 | ||
| 20 |  import org.kuali.rice.kns.datadictionary.FieldOverride; | |
| 21 | ||
| 22 |  /** | |
| 23 |   * A Field Override used to replace list elements in a Data Dictionary bean.  | |
| 24 |   *  | |
| 25 |   * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 26 |   *  | |
| 27 |   */ | |
| 28 | 0 |  public class FieldOverrideForListElementReplaceImpl extends FieldOverrideForListElementBase implements FieldOverride { | 
| 29 |          private Object replaceWith; | |
| 30 | ||
| 31 |          public Object getReplaceWith() { | |
| 32 | 0 |                  return replaceWith; | 
| 33 | }  | |
| 34 | ||
| 35 | public void setReplaceWith(Object replaceAt) {  | |
| 36 | 0 |                  this.replaceWith = replaceAt; | 
| 37 | 0 |          } | 
| 38 | ||
| 39 | protected void varifyConfig() {  | |
| 40 | 0 |                  if (replaceWith == null) { | 
| 41 | 0 |                          throw new RuntimeException( | 
| 42 |                                          "Configuration Error, Missing required replaceWith parameter...."); | |
| 43 | }  | |
| 44 | 0 |          } | 
| 45 | ||
| 46 |          public Object performFieldOverride(Object bean, Object property) { | |
| 47 | 0 |                  varifyConfig(); | 
| 48 | 0 |                  List oldList = (List) property; | 
| 49 | ||
| 50 | 0 |                  int replacePos = getElementPositionInList(getElement(), oldList); | 
| 51 | ||
| 52 | 0 |                  if (replacePos == -1) { | 
| 53 | 0 |                          throw new RuntimeException( | 
| 54 |                                          "Configuration Error, replace element could not be located."); | |
| 55 | }  | |
| 56 | 0 |                  if (replacePos >= 0 && replacePos < oldList.size()) { | 
| 57 | 0 |                          oldList.remove(replacePos); | 
| 58 | 0 |                          oldList.add(replacePos, getReplaceWith()); | 
| 59 | }  | |
| 60 | ||
| 61 | 0 |                  return oldList; | 
| 62 | }  | |
| 63 | }  |