| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package be.objectify.led.factory.type; |
| 17 | |
|
| 18 | |
import be.objectify.led.FactoryResolver; |
| 19 | |
import be.objectify.led.GenericTypes; |
| 20 | |
import be.objectify.led.ObjectFactory; |
| 21 | |
import be.objectify.led.TypeFactory; |
| 22 | |
import be.objectify.led.factory.object.SetFactory; |
| 23 | |
import be.objectify.led.util.StringUtils; |
| 24 | |
|
| 25 | |
import java.lang.reflect.Field; |
| 26 | |
import java.util.ArrayList; |
| 27 | |
import java.util.Collection; |
| 28 | |
import java.util.HashSet; |
| 29 | |
import java.util.List; |
| 30 | |
import java.util.Set; |
| 31 | |
import java.util.StringTokenizer; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 4 | public class SetTypeFactory implements TypeFactory<Set> |
| 38 | |
{ |
| 39 | |
private final FactoryResolver factoryResolver; |
| 40 | |
|
| 41 | |
public SetTypeFactory(FactoryResolver factoryResolver) |
| 42 | 4 | { |
| 43 | 4 | this.factoryResolver = factoryResolver; |
| 44 | 4 | } |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public SetFactory createObjectFactory(Class[] classes, |
| 50 | |
Field field) |
| 51 | |
{ |
| 52 | 4 | return new SetFactory(classes[0], |
| 53 | |
field, |
| 54 | |
factoryResolver) |
| 55 | 4 | { |
| 56 | |
protected Collection parse(String propertyName, |
| 57 | |
String propertyValue, |
| 58 | |
ObjectFactory objectFactory) |
| 59 | |
{ |
| 60 | 4 | List list = new ArrayList(); |
| 61 | 4 | if (!StringUtils.isEmpty(propertyValue)) |
| 62 | |
{ |
| 63 | 1 | for (StringTokenizer stringTokenizer = new StringTokenizer(propertyValue); stringTokenizer.hasMoreTokens();) |
| 64 | |
{ |
| 65 | 2 | list.add(objectFactory.createObject(propertyName, |
| 66 | |
stringTokenizer.nextToken())); |
| 67 | |
} |
| 68 | |
} |
| 69 | 4 | return list; |
| 70 | |
} |
| 71 | |
|
| 72 | |
protected Set createSet() |
| 73 | |
{ |
| 74 | 4 | return new HashSet(); |
| 75 | |
} |
| 76 | |
}; |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
public Class<Set> getBoundClass() |
| 83 | |
{ |
| 84 | 4 | return Set.class; |
| 85 | |
} |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
public Class[] determineClassType(Class fieldType, |
| 91 | |
GenericTypes genericTypes) |
| 92 | |
{ |
| 93 | 4 | if (genericTypes == null || genericTypes.value().length != 1) |
| 94 | |
{ |
| 95 | 0 | throw new RuntimeException("GenericTypes(value class) annotation required to determine Collection value type"); |
| 96 | |
} |
| 97 | |
|
| 98 | 4 | return genericTypes.value(); |
| 99 | |
} |
| 100 | |
} |