01: package com.bm.utils;
02:
03: import java.lang.reflect.Field;
04: import java.util.Set;
05:
06: import com.bm.introspectors.Property;
07:
08: /**
09: * Creates an instance of a id class.
10: *
11: * @author Daniel Wiese
12: *
13: */
14: public class IdClassInstanceGen {
15:
16: private Object newInstance;
17:
18: public IdClassInstanceGen(Set<Property> idFields, Class<?> idClass,
19: Object entityBean) {
20: try {
21: newInstance = idClass.newInstance();
22: for (Property property : idFields) {
23: Object fieldValue = property.getField(entityBean);
24: Field declaredField = idClass.getDeclaredField(property
25: .getPropertyName());
26: declaredField.setAccessible(true);
27: declaredField.set(newInstance, fieldValue);
28: }
29: } catch (InstantiationException e) {
30: throw new RuntimeException(e);
31: } catch (IllegalAccessException e) {
32: throw new RuntimeException(e);
33: } catch (SecurityException e) {
34: throw new RuntimeException(e);
35: } catch (NoSuchFieldException e) {
36: throw new RuntimeException(e);
37: }
38:
39: }
40:
41: /**
42: * Getter to return the newInstance.
43: *
44: * @return the newInstance
45: */
46: public Object getIDClassIntance() {
47: return newInstance;
48: }
49:
50: }
|