|  | 
|  | 1 | +package com.cedarsoftware.io.factory; | 
|  | 2 | + | 
|  | 3 | +import java.util.Collection; | 
|  | 4 | +import java.util.Collections; | 
|  | 5 | +import java.util.Enumeration; | 
|  | 6 | +import java.util.Iterator; | 
|  | 7 | +import java.util.List; | 
|  | 8 | +import java.util.ListIterator; | 
|  | 9 | +import java.util.Map; | 
|  | 10 | +import java.util.NavigableMap; | 
|  | 11 | +import java.util.NavigableSet; | 
|  | 12 | +import java.util.Set; | 
|  | 13 | +import java.util.SortedMap; | 
|  | 14 | +import java.util.SortedSet; | 
|  | 15 | + | 
|  | 16 | +import com.cedarsoftware.io.JsonIoException; | 
|  | 17 | +import com.cedarsoftware.io.JsonObject; | 
|  | 18 | +import com.cedarsoftware.io.JsonReader; | 
|  | 19 | +import com.cedarsoftware.io.Resolver; | 
|  | 20 | + | 
|  | 21 | +/** | 
|  | 22 | + * @author John DeRegnaucourt ([email protected]) | 
|  | 23 | + *         <br> | 
|  | 24 | + *         Copyright (c) Cedar Software LLC | 
|  | 25 | + *         <br><br> | 
|  | 26 | + *         Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 27 | + *         you may not use this file except in compliance with the License. | 
|  | 28 | + *         You may obtain a copy of the License at | 
|  | 29 | + *         <br><br> | 
|  | 30 | + *         <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a> | 
|  | 31 | + *         <br><br> | 
|  | 32 | + *         Unless required by applicable law or agreed to in writing, software | 
|  | 33 | + *         distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 34 | + *         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 35 | + *         See the License for the specific language governing permissions and | 
|  | 36 | + *         limitations under the License. | 
|  | 37 | + */ | 
|  | 38 | +public class EmptyFactory implements JsonReader.ClassFactory { | 
|  | 39 | +    public Object newInstance(Class<?> c, JsonObject jObj, Resolver resolver) { | 
|  | 40 | +        if (NavigableSet.class.isAssignableFrom(c) || SortedSet.class.isAssignableFrom(c)) { | 
|  | 41 | +            return Collections.emptyNavigableSet(); | 
|  | 42 | +        } else if (Set.class.isAssignableFrom(c)) { | 
|  | 43 | +            return Collections.emptySet(); | 
|  | 44 | +        } else if (List.class.isAssignableFrom(c) || Collection.class.isAssignableFrom(c)) { | 
|  | 45 | +            return Collections.emptyList(); | 
|  | 46 | +        } else if (NavigableMap.class.isAssignableFrom(c) || SortedMap.class.isAssignableFrom(c)) { | 
|  | 47 | +            return Collections.emptyNavigableMap(); | 
|  | 48 | +        } else if (Map.class.isAssignableFrom(c)) { | 
|  | 49 | +            return Collections.emptyMap(); | 
|  | 50 | +        } else if (ListIterator.class.isAssignableFrom(c)) { | 
|  | 51 | +            return Collections.emptyListIterator(); | 
|  | 52 | +        } else if (Iterator.class.isAssignableFrom(c)) { | 
|  | 53 | +            return Collections.emptyIterator(); | 
|  | 54 | +        } else if (Enumeration.class.isAssignableFrom(c)) { | 
|  | 55 | +            return Collections.emptyEnumeration(); | 
|  | 56 | +        } | 
|  | 57 | +        throw new JsonIoException("EmptyFactory handed Class for which it was not expecting: " + c.getName()); | 
|  | 58 | +    } | 
|  | 59 | +} | 
|  | 60 | + | 
0 commit comments