View Javadoc

1   package com.bm.introspectors;
2   
3   import java.lang.annotation.Annotation;
4   
5   import javax.persistence.Embeddable;
6   
7   import org.slf4j.Logger;
8   
9   
10  /**
11   * This class inspects all relevant fields of an embedded class and holds the
12   * information.
13   * 
14   * @author Daniel Wiese
15   * @param <T> -
16   *            the type of the embedded class
17   * @since 07.10.2005
18   */
19  public class EmbeddedClassIntrospector<T> extends AbstractPersistentClassIntrospector<T>
20  		implements Introspector<T> {
21  
22  	private static final org.slf4j.Logger log = org.slf4j.LoggerFactory
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.getAnnotations();
43  		boolean isEbeddeable = false;
44  
45  		// iterate over the annotations
46  		for (Annotation a : classAnnotations) {
47  			if (a instanceof Embeddable) {
48  
49  				isEbeddeable = true;
50  			}
51  		}
52  
53  		// check for mandatory conditions
54  		if (!isEbeddeable) {
55  			log.error("The class " + this.embeddedClassName.getSimpleName()
56  					+ " is not a ebededable class");
57  			throw new RuntimeException("The class "
58  					+ this.embeddedClassName.getSimpleName()
59  					+ " is not a ebededable class");
60  		}
61  
62  		// TODO currently abbeded classses have always field access
63  		this.processAccessTypeField(this.embeddedClassName);
64  	}
65  
66  	/**
67  	 * Returns the embeddedClassName.
68  	 * 
69  	 * @return Returns the embeddedClassName.
70  	 */
71  	public Class getEmbeddedClassName() {
72  		return embeddedClassName;
73  	}
74  
75  	/**
76  	 * Returns the filed/gett/setter Name of the source class.
77  	 * 
78  	 * @return Returns the attibuteName.
79  	 */
80  	public Property getAttibuteName() {
81  		return attibuteName;
82  	}
83  
84  	/**
85  	 * Returns the logger for this class.
86  	 * @return
87  	 */
88  	protected Logger getLogger() {
89  		return log;
90  	}
91  }