Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RiceXmlImportList |
|
| 1.75;1.75 |
1 | /** | |
2 | * Copyright 2005-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/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.core.util.jaxb; | |
17 | ||
18 | import java.io.Serializable; | |
19 | import java.util.AbstractList; | |
20 | ||
21 | /** | |
22 | * Custom subclass of AbstractList that, when adding new items, will pass them on to a listener instead of | |
23 | * storing them internally. | |
24 | * | |
25 | * <p>This is based off of the JAXB "streaming" unmarshalling strategy, which is briefly mentioned here: | |
26 | * | |
27 | * <p>http://jaxb.java.net/guide/Dealing_with_large_documents.html | |
28 | * | |
29 | * <p>and is presented in the example code available here: | |
30 | * | |
31 | * <p>http://jaxb.java.net/2.2.4/ | |
32 | * | |
33 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
34 | */ | |
35 | public final class RiceXmlImportList<E> extends AbstractList<E> implements Serializable { | |
36 | ||
37 | private static final long serialVersionUID = 1L; | |
38 | ||
39 | /** The listener that this list will pass new items to. */ | |
40 | private final RiceXmlListAdditionListener<E> listAdditionListener; | |
41 | ||
42 | /** | |
43 | * Constructs a new streaming list that will pass new items to the given listener instead of storing them. | |
44 | * | |
45 | * @param listAdditionListener The listener to use. | |
46 | * @throws IllegalArgumentException if listAdditionListener is null. | |
47 | */ | |
48 | public RiceXmlImportList(RiceXmlListAdditionListener<E> listAdditionListener) { | |
49 | 0 | super(); |
50 | 0 | if (listAdditionListener == null) { |
51 | 0 | throw new IllegalArgumentException("listAdditionListener cannot be null"); |
52 | } | |
53 | 0 | this.listAdditionListener = listAdditionListener; |
54 | 0 | } |
55 | ||
56 | /** | |
57 | * Instead of adding the item to the list, simply invoke the appropriate listener. | |
58 | * | |
59 | * <p>This is based off of the "streaming" unmarshalling strategy used in one of the JAXB sample apps. | |
60 | * | |
61 | * @return false, since the list never gets altered as a result of invoking this method. | |
62 | */ | |
63 | @Override | |
64 | public boolean add(E e) { | |
65 | 0 | listAdditionListener.newItemAdded(e); |
66 | 0 | return false; |
67 | } | |
68 | ||
69 | /** | |
70 | * This method always throws an exception, since the list never contains any items. | |
71 | * | |
72 | * @throws IndexOutOfBoundsException | |
73 | */ | |
74 | @Override | |
75 | public E get(int index) { | |
76 | 0 | throw new IndexOutOfBoundsException(); |
77 | } | |
78 | ||
79 | /** | |
80 | * This method always returns zero, since items are never actually added to the list. | |
81 | * | |
82 | * @return zero. | |
83 | */ | |
84 | @Override | |
85 | public int size() { | |
86 | 0 | return 0; |
87 | } | |
88 | } |