01: package com.bm.introspectors;
02:
03: import java.lang.annotation.Annotation;
04:
05: import javax.persistence.Embeddable;
06:
07: import org.apache.log4j.Logger;
08:
09: /**
10: * This class inspects all relevant fields of an embedded class and holds the
11: * information.
12: *
13: * @author Daniel Wiese
14: * @param <T> -
15: * the type of the embedded class
16: * @since 07.10.2005
17: */
18: public class EmbeddedClassIntrospector<T> extends
19: AbstractPersistentClassIntrospector<T> implements
20: Introspector<T> {
21:
22: private static final Logger log = Logger
23: .getLogger(EmbeddedClassIntrospector.class);
24:
25: /** the type of the ebmedded class* */
26: private final Class<T> embeddedClassName;
27:
28: /** the name of the attribute in the bean class holding the embedded class* */
29: private final Property attibuteName;
30:
31: /**
32: * Constructor with the class to inspect.
33: *
34: * @param toInspect -
35: * the class to inspect
36: */
37: @SuppressWarnings("unchecked")
38: public EmbeddedClassIntrospector(Property toInspect) {
39: this .embeddedClassName = toInspect.getType();
40: this .attibuteName = toInspect;
41:
42: Annotation[] classAnnotations = this .embeddedClassName
43: .getAnnotations();
44: boolean isEbeddeable = false;
45:
46: // iterate over the annotations
47: for (Annotation a : classAnnotations) {
48: if (a instanceof Embeddable) {
49:
50: isEbeddeable = true;
51: }
52: }
53:
54: // check for mandatory conditions
55: if (!isEbeddeable) {
56: log.error("The class "
57: + this .embeddedClassName.getSimpleName()
58: + " is not a ebededable class");
59: throw new RuntimeException("The class "
60: + this .embeddedClassName.getSimpleName()
61: + " is not a ebededable class");
62: }
63:
64: // TODO currently abbeded classses have always field access
65: this .processAccessTypeField(this .embeddedClassName);
66: }
67:
68: /**
69: * Returns the embeddedClassName.
70: *
71: * @return Returns the embeddedClassName.
72: */
73: public Class getEmbeddedClassName() {
74: return embeddedClassName;
75: }
76:
77: /**
78: * Returns the filed/gett/setter Name of the source class.
79: *
80: * @return Returns the attibuteName.
81: */
82: public Property getAttibuteName() {
83: return attibuteName;
84: }
85:
86: /**
87: * Returns the logger for this class.
88: * @return
89: */
90: protected Logger getLogger() {
91: return log;
92: }
93: }
|