KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > deployment > annotations > metadata > CommonAnnotationMetadata


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: CommonAnnotationMetadata.java 1121 2006-09-27 08:51:06Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.metadata;
27
28 import java.util.Arrays JavaDoc;
29
30 import org.objectweb.easybeans.deployment.annotations.impl.JAnnotationResource;
31 import org.objectweb.easybeans.deployment.annotations.impl.JEjbEJB;
32 import org.objectweb.easybeans.deployment.annotations.impl.JavaxPersistenceContext;
33 import org.objectweb.easybeans.deployment.annotations.impl.JavaxPersistenceUnit;
34 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.ISharedMetadata;
35
36 /**
37  * Defines Metadata shared by Field, Method and Classes. For example
38  * @javax.annotation.EJB, @javax.annotation.Resource, etc.
39  * @author Florent Benoit
40  */

41 public class CommonAnnotationMetadata implements ISharedMetadata {
42
43     /**
44      * This field is used as a PersistenceContext.
45      */

46     private JavaxPersistenceContext javaxPersistenceContext = null;
47
48     /**
49      * This field is used as a PersistenceUnit.
50      */

51     private JavaxPersistenceUnit javaxPersistenceUnit = null;
52
53     /**
54      * Object representing @{@link javax.ejb.EJB} annotation.
55      */

56     private JEjbEJB jEjbEJB = null;
57
58     /**
59      * Object representing @{@link javax.annotation.Resource} annotation.
60      */

61     private JAnnotationResource jAnnotationResource = null;
62
63     /**
64      * @return JEjbEJB object representing javax.ejb.EJB annotation.
65      */

66     public JEjbEJB getJEjbEJB() {
67         return jEjbEJB;
68     }
69
70     /**
71      * Set JAnnotationEJB object.
72      * @param jEjbEJB object representing javax.annotation.EJB annotation.
73      */

74     public void setJEjbEJB(final JEjbEJB jEjbEJB) {
75         this.jEjbEJB = jEjbEJB;
76     }
77
78     /**
79      * @return JAnnotationResource object representing javax.annotation.Resource
80      * annotation.
81      */

82     public JAnnotationResource getJAnnotationResource() {
83         return jAnnotationResource;
84     }
85
86     /**
87      * Set JAnnotationResource object.
88      * @param jAnnotationResource object representing javax.annotation.Resource
89      * annotation.
90      */

91     public void setJAnnotationResource(final JAnnotationResource jAnnotationResource) {
92         this.jAnnotationResource = jAnnotationResource;
93     }
94
95     /**
96      * @return true if this field is used as a persistence context.
97      */

98     public boolean isPersistenceContext() {
99         return javaxPersistenceContext != null;
100     }
101
102     /**
103      * @return the persistence context infos.
104      */

105     public JavaxPersistenceContext getJavaxPersistenceContext() {
106         return javaxPersistenceContext;
107     }
108
109     /**
110      * Sets the persistence context info on this field.
111      * @param javaxPersistenceContext information on persistence context.
112      */

113     public void setJavaxPersistenceContext(final JavaxPersistenceContext javaxPersistenceContext) {
114         this.javaxPersistenceContext = javaxPersistenceContext;
115     }
116
117     /**
118      * @return true if this field is used as a persistence unit.
119      */

120     public boolean isPersistenceUnit() {
121         return javaxPersistenceUnit != null;
122     }
123
124     /**
125      * @return the persistence unit infos.
126      */

127     public JavaxPersistenceUnit getJavaxPersistenceUnit() {
128         return javaxPersistenceUnit;
129     }
130
131     /**
132      * Sets the persistence unit info on this field.
133      * @param javaxPersistenceUnit information on persistence unit.
134      */

135     public void setJavaxPersistenceUnit(final JavaxPersistenceUnit javaxPersistenceUnit) {
136         this.javaxPersistenceUnit = javaxPersistenceUnit;
137     }
138
139     /**
140      * @return string representation
141      */

142     @Override JavaDoc
143     public String JavaDoc toString() {
144         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
145         String JavaDoc titleIndent = " ";
146         // classname
147
sb.append(titleIndent);
148         sb.append(this.getClass().getName().substring(this.getClass().getPackage().getName().length() + 1));
149         sb.append("[\n");
150
151         // jEjbEJB
152
concatStringBuilder("jEjbEJB", jEjbEJB, sb);
153
154         // jAnnotationResource
155
concatStringBuilder("jAnnotationResource", jAnnotationResource, sb);
156
157         // javaxPersistenceContext
158
concatStringBuilder("javaxPersistenceContext", javaxPersistenceContext, sb);
159
160         // javaxPersistenceUnit
161
concatStringBuilder("javaxPersistenceUnit", javaxPersistenceUnit, sb);
162
163         sb.append(titleIndent);
164         sb.append("]\n");
165         return sb.toString();
166     }
167
168     /**
169      * Adds an entry to the given StringBuilder.
170      * @param name the name of the entry.
171      * @param object object to add.
172      * @param sb the string builder object on which add the given element.
173      * @param indent the indent to add at each line.
174      */

175     protected static void concatStringBuilder(final String JavaDoc name, final Object JavaDoc object, final StringBuilder JavaDoc sb,
176             final String JavaDoc indent) {
177         if (object instanceof Boolean JavaDoc) {
178             // do not print if false.
179
if (!((Boolean JavaDoc) object).booleanValue()) {
180                 return;
181             }
182         }
183         if (object != null) {
184             sb.append(indent);
185             sb.append(name);
186             sb.append("=");
187             // For arrays, use asList
188
if (object instanceof Object JavaDoc[]) {
189                 sb.append(Arrays.asList((Object JavaDoc[]) object));
190             } else {
191                 sb.append(object);
192             }
193             sb.append("\n");
194         }
195     }
196
197     /**
198      * Adds an entry to the given StringBuilder.
199      * @param name the name of the entry.
200      * @param object object to add.
201      * @param sb the string builder object on which add the given element.
202      */

203     protected static void concatStringBuilder(final String JavaDoc name, final Object JavaDoc object, final StringBuilder JavaDoc sb) {
204         concatStringBuilder(name, object, sb, " ");
205     }
206
207 }
208
Popular Tags