KickJava   Java API By Example, From Geeks To Geeks.

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


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: MethodAnnotationMetadata.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.List JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import javax.ejb.Remove JavaDoc;
32 import javax.ejb.TransactionAttributeType JavaDoc;
33
34 import org.objectweb.easybeans.deployment.annotations.InterceptorType;
35 import org.objectweb.easybeans.deployment.annotations.JClassInterceptor;
36 import org.objectweb.easybeans.deployment.annotations.JMethod;
37 import org.objectweb.easybeans.deployment.annotations.impl.JInterceptors;
38 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IAnnotationSecurityPermitAll;
39 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IAnnotationSecurityRolesAllowed;
40 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IEJBInterceptors;
41 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.ITransactionAttribute;
42
43 /**
44  * This class represents the annotation metadata of a method.
45  * @author Florent Benoit
46  */

47 public class MethodAnnotationMetadata extends CommonAnnotationMetadata
48     implements Cloneable JavaDoc, ITransactionAttribute, IEJBInterceptors, IAnnotationSecurityRolesAllowed, IAnnotationSecurityPermitAll {
49
50     /**
51      * Logger.
52      */

53     //private static JLog logger = JLogFactory.getLog(MethodAnnotationMetadata.class);
54

55     /**
56      * Method on which we got metadata.
57      */

58     private JMethod jMethod = null;
59
60     /**
61      * Parent metadata.
62      */

63     private ClassAnnotationMetadata classAnnotationMetadata = null;
64
65
66     /**
67      * Original parent metadata (if method is inherited).
68      */

69     private ClassAnnotationMetadata originalClassAnnotationMetadata = null;
70
71     /**
72      * Type of transaction.
73      */

74     private TransactionAttributeType JavaDoc transactionAttributeType = null;
75
76     /**
77      * @{@link javax.ejb.Remove} annotation.
78      */

79     private Remove JavaDoc remove = null;
80
81     /**
82      * This method is a business method ?
83      */

84     private boolean businessMethod = false;
85
86     /**
87      * PostConstruct method ?
88      */

89     private boolean postConstruct = false;
90
91     /**
92      * PreDestroy method ?
93      */

94     private boolean preDestroy = false;
95
96     /**
97      * PostActivate method ?
98      */

99     private boolean postActivate = false;
100
101     /**
102      * PrePassivate method ?
103      */

104     private boolean prePassivate = false;
105
106     /**
107      * @{@link javax.interceptor.AroundInvoke} method used by interceptors ?
108      */

109     private boolean aroundInvoke = false;
110
111     /**
112      *This method is a method from a super class ?<br>
113      * This flag is used by enhancers
114      */

115     private boolean inherited = false;
116
117     /**
118      * &#64;{@link javax.interceptor.ExcludeClassInterceptors} method ?
119      */

120     private boolean excludeClassInterceptors = false;
121
122     /**
123      * &#64;{@link javax.ejb.Timeout} method ?
124      */

125     private boolean timeout = false;
126
127     /**
128      * EasyBeans global interceptors.<br>
129      * These interceptors correspond to a list of interceptors
130      * that need to be present first on this current method.
131      */

132     private List JavaDoc<JClassInterceptor> globalEasyBeansInterceptors = null;
133
134     /**
135      * EasyBeans method interceptors. These interceptors correspond to a list of Interceptors like security or transaction.
136      */

137     private List JavaDoc<JClassInterceptor> interceptors = null;
138
139     /**
140      * List of annotation interceptors.
141      */

142     private JInterceptors annotationInterceptors = null;
143
144     /**
145      * User interceptors. These interceptors correspond to a list of Interceptor that user has specified in its bean class.
146      * Map&lt;interceptor type &lt;--&gt; List of methods/class corresponding to the interceptor&gt;
147      */

148     private Map JavaDoc<InterceptorType, List JavaDoc<JClassInterceptor>> userInterceptors = null;
149
150     /**
151      * List of roles that are allowed on this class/bean.
152      */

153     private List JavaDoc<String JavaDoc> rolesAllowed = null;
154
155     /**
156      * This class/bean has the PermitAll annotation.
157      */

158     private boolean permitAll = false;
159
160     /**
161      * This class/bean has the DenyAll annotation.
162      */

163     private boolean denyAll = false;
164
165
166     /**
167      * Constructor.
168      * @param jMethod the method on which we will set/add metadata
169      * @param classAnnotationMetadata the parent metadata.
170      */

171     public MethodAnnotationMetadata(final JMethod jMethod, final ClassAnnotationMetadata classAnnotationMetadata) {
172         this.jMethod = jMethod;
173         this.classAnnotationMetadata = classAnnotationMetadata;
174     }
175
176     /**
177      * @return name of the method
178      */

179     public String JavaDoc getMethodName() {
180         return this.jMethod.getName();
181     }
182
183     /**
184      * @return JMethod object
185      */

186     public JMethod getJMethod() {
187         return this.jMethod;
188     }
189
190     /**
191      * @return transaction Attribute type.
192      * @see javax.ejb.TransactionAttributeType
193      */

194     public TransactionAttributeType JavaDoc getTransactionAttributeType() {
195         return transactionAttributeType;
196     }
197
198     /**
199      * Sets Transaction Attribute Type.
200      * @see javax.ejb.TransactionAttributeType
201      * @param transactionAttributeType the type of transaction.
202      */

203     public void setTransactionAttributeType(final TransactionAttributeType JavaDoc transactionAttributeType) {
204         this.transactionAttributeType = transactionAttributeType;
205     }
206
207     /**
208      * @return true if the method is a business method.
209      */

210     public boolean isBusinessMethod() {
211         return businessMethod;
212     }
213
214     /**
215      * This method is a business method.
216      * @param flag true/false if method is a business method.
217      */

218     public void setBusinessMethod(final boolean flag) {
219         this.businessMethod = flag;
220     }
221
222     /**
223      * @return true if the method is a lifecycle method.
224      */

225     public boolean isLifeCycleMethod() {
226         return isPostActivate() || isPostConstruct() || isPreDestroy() || isPrePassivate();
227     }
228
229     /**
230      * @return remove attributes &#64;{@link javax.ejb.Remove} attributes
231      */

232     public Remove JavaDoc getJRemove() {
233         return this.remove;
234     }
235
236     /**
237      * Sets &#64;{@link javax.ejb.Remove} attribute.
238      * @param remove contains the attribute with retainIfException.
239      */

240     public void setRemove(final Remove JavaDoc remove) {
241         this.remove = remove;
242     }
243
244
245
246     /**
247      * @return string representation
248      */

249     @Override JavaDoc
250     public String JavaDoc toString() {
251         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
252         String JavaDoc titleIndent = " ";
253
254         // classname
255
sb.append(titleIndent);
256         sb.append(this.getClass().getName().substring(this.getClass().getPackage().getName().length() + 1));
257         sb.append("[\n");
258
259         // Add super class toString()
260
sb.append(super.toString());
261
262         // Method
263
concatStringBuilder("jMethod", jMethod, sb);
264
265         // inherited
266
concatStringBuilder("inherited", Boolean.valueOf(inherited), sb);
267
268         // transactionAttributeType
269
concatStringBuilder("transactionAttributeType", transactionAttributeType, sb);
270
271         // remove
272
concatStringBuilder("remove", remove, sb);
273
274         // businessMethod
275
concatStringBuilder("businessMethod", Boolean.valueOf(businessMethod), sb);
276
277         // aroundInvoke
278
concatStringBuilder("aroundInvoke", Boolean.valueOf(aroundInvoke), sb);
279
280         // postConstruct
281
concatStringBuilder("postConstruct", Boolean.valueOf(postConstruct), sb);
282
283         // preDestroy
284
concatStringBuilder("preDestroy", Boolean.valueOf(preDestroy), sb);
285
286         // postActivate
287
concatStringBuilder("postActivate", Boolean.valueOf(postActivate), sb);
288
289         // prePassivate
290
concatStringBuilder("prePassivate", Boolean.valueOf(prePassivate), sb);
291
292         // timeout
293
concatStringBuilder("timeout", Boolean.valueOf(timeout), sb);
294
295         // annotation Interceptors
296
concatStringBuilder("annotationInterceptors", annotationInterceptors, sb);
297
298         // interceptors
299
concatStringBuilder("interceptors", interceptors, sb);
300
301         // rolesAllowed
302
concatStringBuilder("rolesAllowed", rolesAllowed, sb);
303
304         // permitAll
305
concatStringBuilder("permitAll", Boolean.valueOf(permitAll), sb);
306
307         // denyAll
308
concatStringBuilder("denyAll", Boolean.valueOf(denyAll), sb);
309
310         sb.append(titleIndent);
311         sb.append("]\n");
312         return sb.toString();
313     }
314
315     /**
316      * @return true if method has &#64;{@link javax.ejb.PostActivate}
317      */

318     public boolean isPostActivate() {
319         return postActivate;
320     }
321
322     /**
323      * Sets true if method has &#64;{@link javax.ejb.PostActivate}.
324      * @param postActivate true/false.
325      */

326     public void setPostActivate(final boolean postActivate) {
327         this.postActivate = postActivate;
328     }
329
330     /**
331      * @return true if method has &#64;{@link javax.annotation.PostConstruct}.
332      */

333     public boolean isPostConstruct() {
334         return postConstruct;
335     }
336
337     /**
338      * Sets true if method has &#64;{@link javax.annotation.PostConstruct}.
339      * @param postConstruct true/false.
340      */

341     public void setPostConstruct(final boolean postConstruct) {
342         this.postConstruct = postConstruct;
343     }
344
345     /**
346      * @return true if method has &#64;{@link javax.annotation.PreDestroy}.
347      */

348
349     public boolean isPreDestroy() {
350         return preDestroy;
351     }
352
353     /**
354      * Sets true if method has &#64;{@link javax.annotation.PreDestroy}.
355      * @param preDestroy true/false.
356      */

357     public void setPreDestroy(final boolean preDestroy) {
358         this.preDestroy = preDestroy;
359     }
360
361     /**
362      * @return true if method has &#64;{@link javax.ejb.PrePassivate}.
363      */

364
365     public boolean isPrePassivate() {
366         return prePassivate;
367     }
368
369     /**
370      * Sets true if method has &#64;{@link javax.ejb.PrePassivate}.
371      * @param prePassivate true/false.
372      */

373     public void setPrePassivate(final boolean prePassivate) {
374         this.prePassivate = prePassivate;
375     }
376
377     /**
378      * @return true if method has &#64;{@link javax.ejb.Timeout}.
379      */

380     public boolean isTimeout() {
381         return timeout;
382     }
383
384     /**
385      * Sets true if method has &#64;{@link javax.ejb.Timeout}.
386      * @param timeout true/false.
387      */

388     public void setTimeout(final boolean timeout) {
389         this.timeout = timeout;
390     }
391
392     /**
393      * @return true if method has &#64;{@link javax.interceptor.AroundInvoke}.
394      */

395     public boolean isAroundInvoke() {
396         return aroundInvoke;
397     }
398
399     /**
400      * Sets true if method has &#64;{@link javax.interceptor.AroundInvoke}.
401      * @param aroundInvoke true/false
402      */

403     public void setAroundInvoke(final boolean aroundInvoke) {
404         this.aroundInvoke = aroundInvoke;
405     }
406
407     /**
408      * @return true if this method is inherited from a super class
409      */

410     public boolean isInherited() {
411         return inherited;
412     }
413
414     /**
415      * Sets the inheritance of this method.
416      * @param inherited true if method is from a super class
417      * @param originalClassAnnotationMetadata the metadata of the original class (not inherited)
418      */

419     public void setInherited(final boolean inherited, final ClassAnnotationMetadata originalClassAnnotationMetadata) {
420         this.inherited = inherited;
421         this.originalClassAnnotationMetadata = originalClassAnnotationMetadata;
422     }
423
424     /**
425      * @return true if this method won't use user interceptors.
426      */

427     public boolean isExcludedClassInterceptors() {
428         return excludeClassInterceptors;
429     }
430
431     /**
432      * Flag this method as a method which exclude user interceptors.
433      * @param excludeClassInterceptors true if this method is a method which exclude user interceptors.
434      */

435     public void setExcludeClassInterceptors(final boolean excludeClassInterceptors) {
436         this.excludeClassInterceptors = excludeClassInterceptors;
437     }
438
439
440
441     /**
442      * @return parent metadata (class)
443      */

444     public ClassAnnotationMetadata getClassAnnotationMetadata() {
445         return classAnnotationMetadata;
446     }
447
448     /**
449      * @return original parent metadata (class) if inherited.
450      */

451     public ClassAnnotationMetadata getOriginalClassAnnotationMetadata() {
452         return originalClassAnnotationMetadata;
453     }
454
455     /**
456      * @return list of interceptors that enhancer will use. (ie : security/transaction)
457      */

458     public List JavaDoc<JClassInterceptor> getInterceptors() {
459         return interceptors;
460     }
461
462     /**
463      * Sets the list of interceptors(tx, security, etc) that enhancers will use.<br>
464      * These interceptors are defined per methods.
465      * @param interceptors list of interceptors that enhancer will use.
466      */

467     public void setInterceptors(final List JavaDoc<JClassInterceptor> interceptors) {
468         this.interceptors = interceptors;
469     }
470
471     /**
472      * @return object representing list of &#64;{@link javax.interceptor.Interceptors}.
473      */

474     public JInterceptors getAnnotationInterceptors() {
475         return annotationInterceptors;
476     }
477
478     /**
479      * Sets the object representing the &#64;{@link javax.interceptor.Interceptors} annotation.
480      * @param annotationInterceptors list of classes
481      */

482     public void setAnnotationsInterceptors(final JInterceptors annotationInterceptors) {
483         this.annotationInterceptors = annotationInterceptors;
484     }
485
486     /**
487      * @return Map&lt;interceptor type &lt;--&gt; List of methods/class corresponding to the interceptor&gt;
488      * of user interceptors that enhancer will use.
489      */

490     public Map JavaDoc<InterceptorType, List JavaDoc<JClassInterceptor>> getUserEasyBeansInterceptors() {
491         return userInterceptors;
492     }
493
494     /**
495      * Sets the list of user interceptors that enhancers will use.<br>
496      * These interceptors are defined in bean class.
497      * @param userInterceptors list of interceptors that enhancer will use.
498      */

499     public void setUserInterceptors(final Map JavaDoc<InterceptorType, List JavaDoc<JClassInterceptor>> userInterceptors) {
500         this.userInterceptors = userInterceptors;
501     }
502
503     /**
504      * @return list of global interceptors that enhancer will use. (ie : Remove interceptor)
505      */

506     public List JavaDoc<JClassInterceptor> getGlobalEasyBeansInterceptors() {
507         return globalEasyBeansInterceptors;
508     }
509
510     /**
511      * Sets the list of global interceptors that enhancers will use.
512      * @param globalEasyBeansInterceptors list of interceptors that enhancer will use.
513      */

514     public void setGlobalEasyBeansInterceptors(final List JavaDoc<JClassInterceptor> globalEasyBeansInterceptors) {
515         this.globalEasyBeansInterceptors = globalEasyBeansInterceptors;
516     }
517
518     /**
519      * @return a clone object.
520      */

521     @Override JavaDoc
522     public Object JavaDoc clone() {
523         MethodAnnotationMetadata newMethodAnnotationMetadata = new MethodAnnotationMetadata(jMethod, classAnnotationMetadata);
524         newMethodAnnotationMetadata.setAnnotationsInterceptors(annotationInterceptors);
525         newMethodAnnotationMetadata.setAroundInvoke(aroundInvoke);
526         newMethodAnnotationMetadata.setBusinessMethod(businessMethod);
527         newMethodAnnotationMetadata.setExcludeClassInterceptors(excludeClassInterceptors);
528         newMethodAnnotationMetadata.setInherited(inherited, originalClassAnnotationMetadata);
529         newMethodAnnotationMetadata.setInterceptors(interceptors);
530         newMethodAnnotationMetadata.setJAnnotationResource(getJAnnotationResource());
531         newMethodAnnotationMetadata.setJEjbEJB(getJEjbEJB());
532         newMethodAnnotationMetadata.setJavaxPersistenceContext(getJavaxPersistenceContext());
533         newMethodAnnotationMetadata.setJavaxPersistenceUnit(getJavaxPersistenceUnit());
534         newMethodAnnotationMetadata.setPostActivate(postActivate);
535         newMethodAnnotationMetadata.setPostConstruct(postConstruct);
536         newMethodAnnotationMetadata.setPreDestroy(preDestroy);
537         newMethodAnnotationMetadata.setPrePassivate(prePassivate);
538         newMethodAnnotationMetadata.setRemove(remove);
539         newMethodAnnotationMetadata.setTimeout(timeout);
540         newMethodAnnotationMetadata.setTransactionAttributeType(transactionAttributeType);
541         newMethodAnnotationMetadata.setUserInterceptors(userInterceptors);
542         newMethodAnnotationMetadata.setGlobalEasyBeansInterceptors(globalEasyBeansInterceptors);
543         newMethodAnnotationMetadata.setDenyAll(denyAll);
544         newMethodAnnotationMetadata.setPermitAll(permitAll);
545         newMethodAnnotationMetadata.setRolesAllowed(rolesAllowed);
546         return newMethodAnnotationMetadata;
547     }
548
549
550     /**
551      * Replace the link to the classannotation metadata.
552      * @param classAnnotationMetadata new object for the link.
553      */

554     public void setClassAnnotationMetadata(final ClassAnnotationMetadata classAnnotationMetadata) {
555         this.classAnnotationMetadata = classAnnotationMetadata;
556     }
557
558     /**
559      * Set the list of roles allowed on this class/method.
560      * @param rolesAllowed the list of roles.
561      */

562     public void setRolesAllowed(final List JavaDoc<String JavaDoc> rolesAllowed) {
563         this.rolesAllowed = rolesAllowed;
564     }
565
566     /**
567      * @return the list of roles allowed on this class/method.
568      */

569     public List JavaDoc<String JavaDoc> getRolesAllowed() {
570         return rolesAllowed;
571     }
572
573     /**
574      * This method has PermitAll annotation.
575      * @param permitAll the boolean value.
576      */

577     public void setPermitAll(final boolean permitAll) {
578         this.permitAll = permitAll;
579     }
580
581     /**
582      * @return true if PermitAll annotation.
583      */

584     public boolean hasPermitAll() {
585         return permitAll;
586     }
587
588     /**
589      * This method has DenyAll annotation.
590      * @param denyAll the boolean value.
591      */

592     public void setDenyAll(final boolean denyAll) {
593         this.denyAll = denyAll;
594     }
595
596     /**
597      * @return true if DenyAll annotation.
598      */

599     public boolean hasDenyAll() {
600         return denyAll;
601     }
602 }
603
Popular Tags