| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ImmutableCollectionAdapter |
|
| 1.0;1 |
| 1 | package org.kuali.rice.core.util.jaxb; | |
| 2 | ||
| 3 | import javax.xml.bind.annotation.adapters.XmlAdapter; | |
| 4 | import java.util.Arrays; | |
| 5 | import java.util.Collection; | |
| 6 | import java.util.Collections; | |
| 7 | ||
| 8 | /** | |
| 9 | * Handles JAXB mapping that ensures that any Collection created from unmarshalled XML will be an immutable | |
| 10 | * non-null Collection reference.. | |
| 11 | */ | |
| 12 | 0 | public class ImmutableCollectionAdapter extends XmlAdapter<Object[], Collection<?>> { |
| 13 | ||
| 14 | /** | |
| 15 | * <p>Returns an immutable Collection when a Collection is meant to be unmarshalled from XML. This is done to ensure service | |
| 16 | * contracts, which are to return immutable objects, also return immutable Collections when an XML sequence is returned | |
| 17 | * via a remote SOAP call.</p> | |
| 18 | * | |
| 19 | * <p>If the XML being unmarshalled, represented by the objects parameter, is empty or null then an empty List | |
| 20 | * is returned.</p> | |
| 21 | * | |
| 22 | * @param objects an array of Objects collected from XML to be transformed into an immutable Collection | |
| 23 | * @return An immutable Collection | |
| 24 | * @throws Exception | |
| 25 | */ | |
| 26 | @Override | |
| 27 | public Collection<?> unmarshal(Object[] objects) throws Exception { | |
| 28 | 0 | return Collections.unmodifiableCollection(Arrays.asList(objects)); |
| 29 | } | |
| 30 | ||
| 31 | /** | |
| 32 | * Creates an array of Object[] from a passed in Collection for JAXB marshalling. There is no requirement of what kind of | |
| 33 | * Collection is used when marshalling to XML. | |
| 34 | * | |
| 35 | * @param objects | |
| 36 | * @return An Object[] containing the same contents as the passed in Collection. | |
| 37 | * @throws Exception | |
| 38 | */ | |
| 39 | @Override | |
| 40 | public Object[] marshal(Collection<?> objects) throws Exception { | |
| 41 | 0 | return objects.toArray(); |
| 42 | } | |
| 43 | } | |
| 44 |