| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| RiceXmlExportList | 
  | 
  | 2.3333333333333335;2.333 | 
| 1 |  /* | |
| 2 |   * Copyright 2011 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/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.rice.core.util.jaxb; | |
| 17 | ||
| 18 |  import java.io.Serializable; | |
| 19 |  import java.util.AbstractList; | |
| 20 |  import java.util.List; | |
| 21 | ||
| 22 |  /** | |
| 23 |   * Custom subclass of AbstractList that, whenever the "get" method is called, will pass an | |
| 24 |   * internally-stored list's object to the given listener for conversion into another object matching | |
| 25 |   * the list's type. This allows for the marshalling process to discard generated items after they | |
| 26 |   * have been marshalled. | |
| 27 |   *  | |
| 28 |   * <p>These lists are constructed by passing in another list containing the unconverted items, | |
| 29 |   * as well as a listener that will create items of this list's type upon each invocation of | |
| 30 |   * the "get" method. | |
| 31 |   *  | |
| 32 |   * <p>This is similar to the "streaming" unmarshalling strategy used in the RiceXmlImportList | |
| 33 |   * class, except that this list has been adapted for marshalling instead. | |
| 34 |   *  | |
| 35 |   * @param E The type that the list is expected to return. | |
| 36 |   * @param T The type that the list stores internally and passes to the listener for conversion as needed.  | |
| 37 |   *  | |
| 38 |   * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 39 |   */ | |
| 40 | public final class RiceXmlExportList<E,T> extends AbstractList<E> implements Serializable {  | |
| 41 | ||
| 42 | private static final long serialVersionUID = 1L;  | |
| 43 | ||
| 44 | private final List<? extends T> sourceList;  | |
| 45 | private final RiceXmlListGetterListener<E,T> listGetterListener;  | |
| 46 | ||
| 47 |      /** | |
| 48 |       * Constructs a new export list that will rely on the given listener for converting the provided | |
| 49 |       * list's items into the appropriate type. | |
| 50 |       *  | |
| 51 |       * @param sourceList The list of objects to convert. | |
| 52 |       * @param listGetterListener The listener to use. | |
| 53 |       * @throws IllegalArgumentException if sourceList or listGetterListener are null. | |
| 54 |       */ | |
| 55 | public RiceXmlExportList(List<? extends T> sourceList, RiceXmlListGetterListener<E,T> listGetterListener) {  | |
| 56 | 0 |          super(); | 
| 57 | 0 |          if (sourceList == null) { | 
| 58 | 0 |              throw new IllegalArgumentException("sourceList cannot be null"); | 
| 59 | 0 |          } else if (listGetterListener == null) { | 
| 60 | 0 |              throw new IllegalArgumentException("listGetterListener cannot be null"); | 
| 61 | }  | |
| 62 | 0 |          this.sourceList = sourceList; | 
| 63 | 0 |          this.listGetterListener = listGetterListener; | 
| 64 | 0 |      } | 
| 65 | ||
| 66 |      /** | |
| 67 |       * Passes the item at the given index of the internal list to the listener, and then returns | |
| 68 |       * the listener's result. | |
| 69 |       *  | |
| 70 |       * @param index The unconverted item's index in the internal list. | |
| 71 |       * @return The item converted by the listener at the given list index. | |
| 72 |       */ | |
| 73 | @Override  | |
| 74 | public E get(int index) {  | |
| 75 | 0 |          return listGetterListener.gettingNextItem(sourceList.get(index), index); | 
| 76 | }  | |
| 77 | ||
| 78 |      /** | |
| 79 |       * Returns the size of the internal list. | |
| 80 |       *  | |
| 81 |       * @return The size of the internal list. | |
| 82 |       */ | |
| 83 | @Override  | |
| 84 | public int size() {  | |
| 85 | 0 |          return sourceList.size(); | 
| 86 | }  | |
| 87 | ||
| 88 | }  |