View Javadoc

1   package com.bm.ejb3metadata.annotations.metadata;
2   
3   import com.bm.ejb3metadata.annotations.JField;
4   
5   /**
6    * This class represents the annotation metadata of a field.
7    * 
8    * @author Daniel Wiese
9    */
10  public class FieldAnnotationMetadata extends CommonAnnotationMetadata {
11  
12  	/**
13  	 * Method on which we got metadata.
14  	 */
15  	private JField jField = null;
16  
17  	/**
18  	 * Parent metadata.
19  	 */
20  	private ClassAnnotationMetadata classAnnotationMetadata = null;
21  
22  	/**
23  	 * This field is a field from a super class ?<br>
24  	 */
25  	private boolean inherited = false;
26  
27  	/**
28  	 * Constructor.
29  	 * 
30  	 * @param jField
31  	 *            the field on which we will set/add metadata
32  	 * @param classAnnotationMetadata
33  	 *            the parent metadata.
34  	 */
35  	public FieldAnnotationMetadata(final JField jField,
36  			final ClassAnnotationMetadata classAnnotationMetadata) {
37  		this.jField = jField;
38  		this.classAnnotationMetadata = classAnnotationMetadata;
39  	}
40  
41  	/**
42  	 * @return name of the field
43  	 */
44  	public String getFieldName() {
45  		return this.jField.getName();
46  	}
47  
48  	/**
49  	 * @return JMethod object
50  	 */
51  	public JField getJField() {
52  		return this.jField;
53  	}
54  
55  	/**
56  	 * @return string representation
57  	 */
58  	@Override
59  	public String toString() {
60  		StringBuilder sb = new StringBuilder();
61  		String titleIndent = " ";
62  		String indent = "   ";
63  		// classname
64  		sb.append(titleIndent);
65  		sb.append(this.getClass().getName().substring(
66  				this.getClass().getPackage().getName().length() + 1));
67  		sb.append("[\n");
68  
69  		// Add super class toString()
70  		sb.append(super.toString());
71  
72  		// Field
73  		sb.append(indent);
74  		sb.append("jField=");
75  		sb.append(jField);
76  		sb.append("\n");
77  
78  		// inherited
79  		if (inherited) {
80  			sb.append(indent);
81  			sb.append("inherited=");
82  			sb.append(inherited);
83  			sb.append("\n");
84  		}
85  
86  		sb.append(titleIndent);
87  		sb.append("]\n");
88  		return sb.toString();
89  	}
90  
91  	/**
92  	 * @return true if this method is inherited from a super class
93  	 */
94  	public boolean isInherited() {
95  		return inherited;
96  	}
97  
98  	/**
99  	 * Sets the inheritance of this method.
100 	 * 
101 	 * @param inherited
102 	 *            true if method is from a super class
103 	 */
104 	public void setInherited(final boolean inherited) {
105 		this.inherited = inherited;
106 	}
107 
108 	/**
109 	 * @return parent metadata (class)
110 	 */
111 	public ClassAnnotationMetadata getClassAnnotationMetadata() {
112 		return classAnnotationMetadata;
113 	}
114 
115 }