01: package org.osbl.item;
02:
03: import java.util.*;
04: import java.beans.*;
05:
06: public class BeanLocalizationCollector extends AbstractItemCollector {
07: Class beanClass;
08: List<String> items;
09:
10: public BeanLocalizationCollector(Class beanClass) {
11: this .beanClass = beanClass;
12: }
13:
14: public Collection<String> getItems() {
15: if (items == null) {
16: try {
17: BeanInfo info = Introspector.getBeanInfo(beanClass,
18: Object.class);
19: PropertyDescriptor[] descriptors = info
20: .getPropertyDescriptors();
21:
22: items = new ArrayList<String>(descriptors.length + 1);
23: StringBuilder builder = new StringBuilder(beanClass
24: .getName());
25: items.add(build(builder));
26:
27: for (int i = 0; i < descriptors.length; i++) {
28: PropertyDescriptor descriptor = descriptors[i];
29: items
30: .add(build(builder, ".", descriptor
31: .getName()));
32:
33: Class<?> propertyType = descriptor
34: .getPropertyType();
35: if (propertyType.isEnum())
36: items.addAll(new EnumLocalizationCollector(
37: propertyType).getItems());
38: }
39: } catch (Exception e) {
40: throw new RuntimeException(e);
41: }
42: }
43: return items;
44: }
45:
46: public boolean equals(Object o) {
47: if (this == o)
48: return true;
49: if (o == null || getClass() != o.getClass())
50: return false;
51:
52: BeanLocalizationCollector that = (BeanLocalizationCollector) o;
53:
54: if (!beanClass.equals(that.beanClass))
55: return false;
56:
57: return true;
58: }
59:
60: public int hashCode() {
61: return beanClass.hashCode();
62: }
63: }
|