KickJava   Java API By Example, From Geeks To Geeks.

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


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: ClassAnnotationMetadata.java 1121 2006-09-27 08:51:06Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.metadata;
27
28 import static javax.ejb.TransactionAttributeType.REQUIRED JavaDoc;
29 import static javax.ejb.TransactionManagementType.CONTAINER JavaDoc;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collection JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.LinkedList JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Map JavaDoc;
37
38 import javax.ejb.ApplicationException JavaDoc;
39 import javax.ejb.TransactionAttributeType JavaDoc;
40 import javax.ejb.TransactionManagementType JavaDoc;
41
42 import org.objectweb.easybeans.deployment.annotations.ClassType;
43 import org.objectweb.easybeans.deployment.annotations.InterceptorType;
44 import org.objectweb.easybeans.deployment.annotations.JClassInterceptor;
45 import org.objectweb.easybeans.deployment.annotations.JField;
46 import org.objectweb.easybeans.deployment.annotations.JMethod;
47 import org.objectweb.easybeans.deployment.annotations.exceptions.InterceptorsValidationException;
48 import org.objectweb.easybeans.deployment.annotations.impl.JAnnotationResource;
49 import org.objectweb.easybeans.deployment.annotations.impl.JCommonBean;
50 import org.objectweb.easybeans.deployment.annotations.impl.JEjbEJB;
51 import org.objectweb.easybeans.deployment.annotations.impl.JInterceptors;
52 import org.objectweb.easybeans.deployment.annotations.impl.JLocal;
53 import org.objectweb.easybeans.deployment.annotations.impl.JMessageDriven;
54 import org.objectweb.easybeans.deployment.annotations.impl.JRemote;
55 import org.objectweb.easybeans.deployment.annotations.impl.JStateful;
56 import org.objectweb.easybeans.deployment.annotations.impl.JStateless;
57 import org.objectweb.easybeans.deployment.annotations.impl.JavaxPersistenceContext;
58 import org.objectweb.easybeans.deployment.annotations.impl.JavaxPersistenceUnit;
59 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IAnnotationSecurityPermitAll;
60 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IAnnotationSecurityRolesAllowed;
61 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IEJBInterceptors;
62 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.ITransactionAttribute;
63 import org.objectweb.easybeans.log.JLog;
64 import org.objectweb.easybeans.log.JLogFactory;
65
66
67 /**
68  * This class represents the annotation metadata of a Bean.<br>
69  * From this class, we can access to all methods of a bean with its associated information.
70  * @author Florent Benoit
71  */

72 public class ClassAnnotationMetadata extends CommonAnnotationMetadata implements ITransactionAttribute, IEJBInterceptors,
73         IAnnotationSecurityRolesAllowed, IAnnotationSecurityPermitAll {
74
75     /**
76      * Logger.
77      */

78     private static JLog logger = JLogFactory.getLog(ClassAnnotationMetadata.class);
79
80     /**
81      * List of method annotations metadata.
82      */

83     private Map JavaDoc<JMethod, MethodAnnotationMetadata> methodsAnnotationMetadata = null;
84
85     /**
86      * List of field annotations metadata.
87      */

88     private Map JavaDoc<JField, FieldAnnotationMetadata> fieldsAnnotationMetadata = null;
89
90     /**
91      * Parent meta data.
92      */

93     private EjbJarAnnotationMetadata ejbJarAnnotationMetadata = null;
94
95     /**
96      * List of local interfaces.
97      */

98     private JLocal jLocal = null;
99
100     /**
101      * List of remote interfaces.
102      */

103     private JRemote jRemote = null;
104
105     /**
106      * CommonBean description.
107      */

108     private JCommonBean jCommonBean = null;
109
110     /**
111      * Message Driven attribute.
112      */

113     private JMessageDriven jMessageDriven = null;
114
115     /**
116      * Stateless attribute.
117      */

118     private JStateless jStateless = null;
119
120     /**
121      * Stateful attribute.
122      */

123     private JStateful jStateful = null;
124
125
126     /**
127      * Local Home.
128      */

129     private String JavaDoc localHome = null;
130
131     /**
132      * Remote Home.
133      */

134     private String JavaDoc remoteHome = null;
135
136     /**
137      * List of annotation interceptors.
138      */

139     private JInterceptors annotationInterceptors = null;
140
141     /**
142      * EasyBeans global interceptors.<br>
143      * These interceptors correspond to a list of interceptors
144      * that need to be present first on all methods.
145      */

146     private List JavaDoc<JClassInterceptor> globalEasyBeansInterceptors = null;
147
148     /**
149      * User interceptors. These interceptors correspond to a list of Interceptor that user has specified in its bean class.
150      * It is the interceptors defined in interceptor classes, not the bean class itself.
151      * Map&lt;interceptor type &lt;--&gt; List of methods/class corresponding to the interceptor&gt;
152      */

153     private Map JavaDoc<InterceptorType, List JavaDoc<JClassInterceptor>> externalUserInterceptors = null;
154
155     /**
156      * User interceptors. These interceptors correspond to a list of Interceptor that user has specified in the bean class.
157      * It is not defined in separated classes.
158      * Map&lt;interceptor type &lt;--&gt; List of methods/class corresponding to the interceptor&gt;
159      */

160     private Map JavaDoc<InterceptorType, List JavaDoc<JClassInterceptor>> internalUserInterceptors = null;
161
162
163     /**
164      * Transaction management type (default = container).
165      */

166     private TransactionManagementType JavaDoc transactionManagementType = CONTAINER;
167
168     /**
169      * Transaction attribute type (default = required).
170      */

171     private TransactionAttributeType JavaDoc transactionAttributeType = REQUIRED;
172
173     /**
174      * Application exception annotation.
175      */

176     private ApplicationException JavaDoc applicationException = null;
177
178     /**
179      * Superclass name.
180      */

181     private String JavaDoc superName = null;
182
183     /**
184      * Interfaces of this clas.
185      */

186     private String JavaDoc[] interfaces = null;
187
188     /**
189      * The type of the class.
190      * @see ClassType
191      */

192     private ClassType classType = null;
193
194     /**
195      * Name of the class associated to this metadata.
196      */

197     private String JavaDoc className = null;
198
199     /**
200      * List of &#64;{@link javax.interceptor.AroundInvoke} methods on this
201      * class (should be only one per class, validating occurs after).
202      */

203     private List JavaDoc<MethodAnnotationMetadata> aroundInvokeMethodsMetadata = null;
204
205     /**
206      * Object representing &#64;{@link javax.ejb.EJBs} annotation.
207      */

208     private List JavaDoc<JEjbEJB> jEjbEJBs = null;
209
210     /**
211      * Object representing &#64;{@link javax.annotation.Resources} annotation.
212      */

213     private List JavaDoc<JAnnotationResource> jAnnotationResources = null;
214
215     /**
216      * Object representing &#64;{@link javax.persistence.PersistenceContext} annotation.
217      */

218     private List JavaDoc<JavaxPersistenceContext> javaxPersistencePersistenceContexts = null;
219
220     /**
221      * Object representing &#64;{@link javax.persistence.PersistenceUnit} annotation.
222      */

223     private List JavaDoc<JavaxPersistenceUnit> javaxPersistencePersistenceUnits = null;
224
225     /**
226      * Methods used for &#64;{@link javax.annotation.PostConstruct} on this
227      * class (only one per class but may be defined in super classes).
228      */

229     private LinkedList JavaDoc<MethodAnnotationMetadata> postConstructMethodsMetadata = null;
230
231     /**
232      * Methods used for &#64;{@link javax.annotation.PreDestroy} on this class
233      * (only one per class but may be defined in super classes).
234      */

235     private LinkedList JavaDoc<MethodAnnotationMetadata> preDestroyMethodsMetadata = null;
236
237     /**
238      * Methods used for &#64;{@link javax.ejb.PostActivate} on this class (only
239      * one per class but may be defined in super classes).
240      */

241     private LinkedList JavaDoc<MethodAnnotationMetadata> postActivateMethodsMetadata = null;
242
243     /**
244      * Methods used for &#64;{@link javax.ejb.PrePassivate} on this class (only
245      * one per class but may be defined in super classes).
246      */

247     private LinkedList JavaDoc<MethodAnnotationMetadata> prePassivateMethodsMetadata = null;
248
249     /**
250      * Is that the class represented by this metadata has already been modified ?
251      */

252     private boolean modified = false;
253
254     /**
255      * List of roles that are declared on this class.
256      */

257     private List JavaDoc<String JavaDoc> declareRoles = null;
258
259     /**
260      * List of roles that are allowed on this class/bean.
261      */

262     private List JavaDoc<String JavaDoc> rolesAllowed = null;
263
264     /**
265      * This class/bean has the permitAll annotation.
266      */

267     private boolean permitAll = false;
268
269     /**
270      * The run-as security role (if any).
271      */

272     private String JavaDoc runAs = null;
273
274     /**
275      * Constructor.
276      * @param className name of the class associated to these metadatas.
277      * @param ejbJarAnnotationMetadata parent metadata object.
278      */

279     public ClassAnnotationMetadata(final String JavaDoc className, final EjbJarAnnotationMetadata ejbJarAnnotationMetadata) {
280         this.className = className;
281         this.methodsAnnotationMetadata = new HashMap JavaDoc<JMethod, MethodAnnotationMetadata>();
282         this.fieldsAnnotationMetadata = new HashMap JavaDoc<JField, FieldAnnotationMetadata>();
283         this.ejbJarAnnotationMetadata = ejbJarAnnotationMetadata;
284         this.postConstructMethodsMetadata = new LinkedList JavaDoc<MethodAnnotationMetadata>();
285         this.preDestroyMethodsMetadata = new LinkedList JavaDoc<MethodAnnotationMetadata>();
286         this.postActivateMethodsMetadata = new LinkedList JavaDoc<MethodAnnotationMetadata>();
287         this.prePassivateMethodsMetadata = new LinkedList JavaDoc<MethodAnnotationMetadata>();
288     }
289
290     /**
291      * @return name of the bean (associated to this metadata).
292      */

293     public String JavaDoc getClassName() {
294         return className;
295     }
296
297     /**
298      * Add method annotation metadata for a given Bean.
299      * @param methodAnnotationMetadata metadata of a method.
300      */

301     public void addMethodAnnotationMetadata(final MethodAnnotationMetadata methodAnnotationMetadata) {
302         JMethod key = methodAnnotationMetadata.getJMethod();
303         // already exists ?
304
if (methodsAnnotationMetadata.containsKey(key)) {
305             String JavaDoc msg = logger.getI18n().getMessage("BeanAnnotationMetadata.addMethodAnnotationMetadata.alreadyPresent", key);
306             logger.debug(msg);
307             throw new IllegalStateException JavaDoc(msg);
308         }
309         methodsAnnotationMetadata.put(key, methodAnnotationMetadata);
310     }
311
312     /**
313      * @param jMethod key of the map of methods annotations.
314      * @return method annotation metadata of a given method.
315      */

316     public MethodAnnotationMetadata getMethodAnnotationMetadata(final JMethod jMethod) {
317         return methodsAnnotationMetadata.get(jMethod);
318     }
319
320     /**
321      * Get collections of methods annotation metadata.
322      * @return collections of methods annotation metadata.
323      */

324     public Collection JavaDoc<MethodAnnotationMetadata> getMethodAnnotationMetadataCollection() {
325         return methodsAnnotationMetadata.values();
326     }
327
328
329     /**
330      * Add field annotation metadata for a given Bean.
331      * @param fieldAnnotationMetadata metadata of a field.
332      */

333     public void addFieldAnnotationMetadata(final FieldAnnotationMetadata fieldAnnotationMetadata) {
334         JField key = fieldAnnotationMetadata.getJField();
335         // already exists ?
336
if (fieldsAnnotationMetadata.containsKey(key)) {
337             String JavaDoc msg = logger.getI18n().getMessage("BeanAnnotationMetadata.addFieldAnnotationMetadata.alreadyPresent", key);
338             logger.debug(msg);
339             throw new IllegalStateException JavaDoc(msg);
340         }
341         fieldsAnnotationMetadata.put(key, fieldAnnotationMetadata);
342     }
343
344     /**
345      * @param jField key of the map of fields annotations.
346      * @return field annotation metadata of a given method.
347      */

348     public FieldAnnotationMetadata getFieldAnnotationMetadata(final JField jField) {
349         return fieldsAnnotationMetadata.get(jField);
350     }
351
352     /**
353      * Get collections of fields annotation metadata.
354      * @return collections of fields annotation metadata.
355      */

356     public Collection JavaDoc<FieldAnnotationMetadata> getFieldAnnotationMetadataCollection() {
357         return fieldsAnnotationMetadata.values();
358     }
359
360
361     /**
362      * Sets the local interfaces of this class.
363      * @param jLocal list of interfaces.
364      */

365     public void setLocalInterfaces(final JLocal jLocal) {
366         this.jLocal = jLocal;
367     }
368
369     /**
370      * Sets the remote interfaces of this class.
371      * @param jRemote list of interfaces.
372      */

373     public void setRemoteInterfaces(final JRemote jRemote) {
374         this.jRemote = jRemote;
375     }
376
377
378     /**
379      * @return the local interfaces of this class.
380      */

381     public JLocal getLocalInterfaces() {
382        return jLocal;
383     }
384
385     /**
386      * @return the remote interfaces of this class.
387      */

388     public JRemote getRemoteInterfaces() {
389         return jRemote;
390     }
391
392       /**
393      * @return true if the class is a stateless class
394      */

395     public boolean isStateless() {
396         return (classType != null && classType == ClassType.STATELESS);
397     }
398
399     /**
400      * @return true if the class is a stateful class
401      */

402     public boolean isStateful() {
403         return (classType != null && classType == ClassType.STATEFUL);
404     }
405
406     /**
407      * @return true if the class is a session bean class
408      */

409     public boolean isSession() {
410         return (classType != null && (classType == ClassType.STATELESS || classType == ClassType.STATEFUL));
411     }
412
413     /**
414      * @return true if the class is an MDB class
415      */

416     public boolean isMdb() {
417         return (classType != null && classType == ClassType.MDB);
418     }
419
420     /**
421      * Sets the type of this class.
422      * @param cType a type from enum class ClassType.
423      * @see org.objectweb.easybeans.deployment.annotations.ClassType
424      */

425     public void setClassType(final ClassType cType) {
426         this.classType = cType;
427     }
428
429     /**
430      * @return Message driven attribute.
431      */

432     public JMessageDriven getJMessageDriven() {
433         return jMessageDriven;
434     }
435
436     /**
437      * Sets the message driven bean object.
438      * @param messageDriven attributes of message driven bean.
439      */

440     public void setJMessageDriven(final JMessageDriven messageDriven) {
441         jMessageDriven = messageDriven;
442     }
443
444
445     /**
446      * @return string representation.
447      */

448     @Override JavaDoc
449     public String JavaDoc toString() {
450         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
451         // classname
452
sb.append(this.getClass().getName().substring(this.getClass().getPackage().getName().length() + 1));
453         sb.append("[\n");
454
455         // Add super class toString()
456
sb.append(super.toString());
457
458         // Class name
459
concatStringBuilder("className", className, sb);
460
461         // superclass name
462
concatStringBuilder("superName", superName, sb);
463
464         // interfaces
465
concatStringBuilder("interfaces", interfaces, sb);
466
467         // classType
468
concatStringBuilder("classType", classType, sb);
469
470         // jLocal
471
concatStringBuilder("jLocal", jLocal, sb);
472
473         // aroundInvokeMethodMetadatas
474
concatStringBuilder("aroundInvokeMethodsMetadata", aroundInvokeMethodsMetadata, sb);
475
476         // jRemote
477
concatStringBuilder("jRemote", jRemote, sb);
478
479         // jMessageDriven
480
concatStringBuilder("jMessageDriven", jMessageDriven, sb);
481
482         // remoteHome
483
concatStringBuilder("remoteHome", remoteHome, sb);
484
485         // localHome
486
concatStringBuilder("localHome", localHome, sb);
487
488         // transactionManagementType
489
concatStringBuilder("transactionManagementType", transactionManagementType, sb);
490
491         // transactionAttributeType
492
concatStringBuilder("transactionAttributeType", transactionAttributeType, sb);
493
494         // annotation Interceptors
495
concatStringBuilder("annotationInterceptors", annotationInterceptors, sb);
496
497         // jEjbEJBs
498
concatStringBuilder("jAnnotationEJBs", jEjbEJBs, sb);
499
500         // jAnnotationResources
501
concatStringBuilder("jAnnotationResources", jAnnotationResources, sb);
502
503         // javaxPersistencePersistenceContexts
504
concatStringBuilder("javaxPersistencePersistenceContexts", javaxPersistencePersistenceContexts, sb);
505
506         // javaxPersistencePersistenceUnits
507
concatStringBuilder("javaxPersistencePersistenceUnits", javaxPersistencePersistenceUnits, sb);
508
509
510         // Methods
511
for (MethodAnnotationMetadata methodAnnotationMetadata : getMethodAnnotationMetadataCollection()) {
512             concatStringBuilder("methods", methodAnnotationMetadata, sb);
513         }
514
515         // modified
516
concatStringBuilder("modified", Boolean.valueOf(modified), sb);
517
518         // declareRoles
519
concatStringBuilder("declareRoles", declareRoles, sb);
520
521         // rolesAllowed
522
concatStringBuilder("rolesAllowed", rolesAllowed, sb);
523
524         // permitAll
525
concatStringBuilder("permitAll", Boolean.valueOf(permitAll), sb);
526
527         // runAs
528
concatStringBuilder("runAs", runAs, sb);
529
530         sb.append("]");
531         return sb.toString();
532     }
533
534     /**
535      * @return the &#64;{@link javax.ejb.RemoteHome} class name.
536      */

537     public String JavaDoc getRemoteHome() {
538         return remoteHome;
539     }
540
541     /**
542      * Sets the &#64;{@link javax.ejb.RemoteHome} class name.
543      * @param remoteHome the class name.
544      */

545     public void setRemoteHome(final String JavaDoc remoteHome) {
546         this.remoteHome = remoteHome;
547     }
548
549     /**
550      * @return the &#64;{@link javax.ejb.LocalHome} class name.
551      */

552     public String JavaDoc getLocalHome() {
553         return localHome;
554     }
555
556     /**
557      * Sets the &#64;{@link javax.ejb.LocalHome} class name.
558      * @param localHome the class name.
559      */

560     public void setLocalHome(final String JavaDoc localHome) {
561         this.localHome = localHome;
562     }
563
564     /**
565      * @return transaction management type from @see TransactionManagementType.
566      */

567     public TransactionManagementType JavaDoc getTransactionManagementType() {
568         return transactionManagementType;
569     }
570
571     /**
572      * Sets transaction management type.
573      * @see javax.ejb.TransactionManagementType
574      * @param transactionManagementType value.
575      * (BEAN, CONTAINER)
576      */

577     public void setTransactionManagementType(final TransactionManagementType JavaDoc transactionManagementType) {
578         this.transactionManagementType = transactionManagementType;
579     }
580
581     /**
582      * @return transaction Attribute type.
583      * @see javax.ejb.TransactionAttributeType
584      */

585     public TransactionAttributeType JavaDoc getTransactionAttributeType() {
586         return transactionAttributeType;
587     }
588
589     /**
590      * Set Transaction Attribute Type.
591      * @see javax.ejb.TransactionAttributeType
592      * @param transactionAttributeType the type of transaction.
593      */

594     public void setTransactionAttributeType(final TransactionAttributeType JavaDoc transactionAttributeType) {
595         this.transactionAttributeType = transactionAttributeType;
596     }
597
598     /**
599      * @return object representing list of &#64;{@link javax.interceptor.Interceptors}.
600      */

601     public JInterceptors getAnnotationInterceptors() {
602         return annotationInterceptors;
603     }
604
605     /**
606      * Sets the object representing the &#64;{@link javax.interceptor.Interceptors} annotation.
607      * @param annotationInterceptors list of classes
608      */

609     public void setAnnotationsInterceptors(final JInterceptors annotationInterceptors) {
610         this.annotationInterceptors = annotationInterceptors;
611     }
612
613     /**
614      * @return the &#64;{@link javax.ejb.ApplicationException} annotation.
615      */

616     public ApplicationException JavaDoc getApplicationException() {
617         return applicationException;
618     }
619
620     /**
621      * Sets the object representing the &#64;{@link javax.ejb.ApplicationException} annotation.
622      * @param applicationException object representation
623      */

624     public void setApplicationException(final ApplicationException JavaDoc applicationException) {
625         this.applicationException = applicationException;
626     }
627
628     /**
629      * @return true if the classs is a Bean
630      */

631     public boolean isBean() {
632         return isStateless() || isStateful() || isMdb();
633     }
634
635     /**
636      * @return array of interfaces name.
637      */

638     public String JavaDoc[] getInterfaces() {
639         return interfaces;
640     }
641
642     /**
643      * Sets the interfaces of this class.
644      * @param interfaces name of interfaces.
645      */

646     public void setInterfaces(final String JavaDoc[] interfaces) {
647         this.interfaces = interfaces;
648     }
649
650     /**
651      * @return the super class name.
652      */

653     public String JavaDoc getSuperName() {
654         return superName;
655     }
656
657     /**
658      * Sets the super class name.
659      * @param superName name of the super class.
660      */

661     public void setSuperName(final String JavaDoc superName) {
662         this.superName = superName;
663     }
664
665     /**
666      * @return parent metadata object.
667      */

668     public EjbJarAnnotationMetadata getEjbJarAnnotationMetadata() {
669         return ejbJarAnnotationMetadata;
670     }
671
672     /**
673      * @return Map&lt;interceptor type &lt;--&gt; List of methods/class corresponding to the interceptor&gt; (interceptor classes)
674      * of user interceptors that enhancer will use.
675      */

676     public Map JavaDoc<InterceptorType, List JavaDoc<JClassInterceptor>> getExternalUserEasyBeansInterceptors() {
677         return externalUserInterceptors;
678     }
679
680     /**
681      * Sets the list of user interceptors that enhancers will use.<br>
682      * These interceptors are defined outside the bean class (interceptor classes).
683      * @param externalUserInterceptors list of interceptors that enhancer will use.
684      */

685     public void setExternalUserInterceptors(final Map JavaDoc<InterceptorType, List JavaDoc<JClassInterceptor>> externalUserInterceptors) {
686         this.externalUserInterceptors = externalUserInterceptors;
687     }
688
689
690     /**
691      * @return Map&lt;interceptor type &lt;--&gt; List of methods/class corresponding to the interceptor&gt; (bean classes)
692      * of user interceptors that enhancer will use.
693      */

694     public Map JavaDoc<InterceptorType, List JavaDoc<JClassInterceptor>> getInternalUserEasyBeansInterceptors() {
695         return internalUserInterceptors;
696     }
697
698     /**
699      * Sets the list of user interceptors that enhancers will use.<br>
700      * These interceptors are defined in bean class.
701      * @param internalUserInterceptors list of interceptors that enhancer will use.
702      */

703     public void setInternalUserInterceptors(final Map JavaDoc<InterceptorType, List JavaDoc<JClassInterceptor>> internalUserInterceptors) {
704         this.internalUserInterceptors = internalUserInterceptors;
705     }
706
707     /**
708      * @return list of global interceptors that enhancer will use. (ie : ENC)
709      */

710     public List JavaDoc<JClassInterceptor> getGlobalEasyBeansInterceptors() {
711         return globalEasyBeansInterceptors;
712     }
713
714     /**
715      * Sets the list of global interceptors that enhancers will use.
716      * @param globalEasyBeansInterceptors list of interceptors that enhancer will use.
717      */

718     public void setGlobalEasyBeansInterceptors(final List JavaDoc<JClassInterceptor> globalEasyBeansInterceptors) {
719         this.globalEasyBeansInterceptors = globalEasyBeansInterceptors;
720     }
721
722     /**
723      * @return the method metadata with annotation &#64;{@link javax.interceptor.AroundInvoke}.
724      */

725     public boolean isAroundInvokeMethodMetadata() {
726         return (aroundInvokeMethodsMetadata != null);
727     }
728
729
730     /**
731      * @return the list of methods metadata with annotation &#64;{@link javax.interceptor.AroundInvoke}.
732      */

733     public List JavaDoc<MethodAnnotationMetadata> getAroundInvokeMethodMetadatas() {
734         return aroundInvokeMethodsMetadata;
735     }
736
737     /**
738      * Add a &#64;{@link javax.interceptor.AroundInvoke} method of this class.
739      * @param aroundInvokeMethodMetadata the method.
740      */

741     public void addAroundInvokeMethodMetadata(final MethodAnnotationMetadata aroundInvokeMethodMetadata) {
742         if (aroundInvokeMethodsMetadata == null) {
743             this.aroundInvokeMethodsMetadata = new ArrayList JavaDoc<MethodAnnotationMetadata>();
744         }
745         aroundInvokeMethodsMetadata.add(aroundInvokeMethodMetadata);
746     }
747
748     /**
749      * @return the methods metadata with annotation &#64;{@link javax.annotation.PostConstruct}.
750      */

751     public LinkedList JavaDoc<MethodAnnotationMetadata> getPostConstructMethodsMetadata() {
752         return postConstructMethodsMetadata;
753     }
754
755     /**
756      * Adds a &#64;{@link javax.annotation.PostConstruct} method of this class.
757      * @param postConstructMethodMetadata the method.
758      */

759     public void addPostConstructMethodMetadata(final MethodAnnotationMetadata postConstructMethodMetadata) {
760       checkLifeCycleDuplicate(postConstructMethodMetadata, InterceptorType.POST_CONSTRUCT, getPostConstructMethodsMetadata());
761       this.postConstructMethodsMetadata.addFirst(postConstructMethodMetadata);
762     }
763
764     /**
765      * Checks that only method at one level of a class is present.
766      * @param postConstructMethodMetadata method to check
767      * @param itcType the type of interceptor (used for the error)
768      * @param existingList current list of methods
769      */

770     private void checkLifeCycleDuplicate(final MethodAnnotationMetadata postConstructMethodMetadata,
771             final InterceptorType itcType, final List JavaDoc<MethodAnnotationMetadata> existingList) {
772         // First case : not inherited
773
ClassAnnotationMetadata wantToAddClassMetadata = postConstructMethodMetadata.getClassAnnotationMetadata();
774         if (postConstructMethodMetadata.isInherited()) {
775             wantToAddClassMetadata = postConstructMethodMetadata.getOriginalClassAnnotationMetadata();
776         }
777         for (MethodAnnotationMetadata method : existingList) {
778             ClassAnnotationMetadata compareMetaData;
779             if (method.isInherited()) {
780                 compareMetaData = method.getOriginalClassAnnotationMetadata();
781             } else {
782                 compareMetaData = method.getClassAnnotationMetadata();
783             }
784             if (compareMetaData.equals(wantToAddClassMetadata)) {
785                 throw new InterceptorsValidationException("Class " + getClassName()
786                         + " has already a " + itcType + " method which is "
787                         + method.getMethodName() + ", cannot set new method "
788                         + postConstructMethodMetadata.getMethodName());
789             }
790         }
791     }
792
793
794     /**
795      * @return the methods metadata with annotation &#64;{@link javax.annotation.PreDestroy}.
796      */

797     public LinkedList JavaDoc<MethodAnnotationMetadata> getPreDestroyMethodsMetadata() {
798         return preDestroyMethodsMetadata;
799     }
800
801     /**
802      * Adds a &#64;{@link javax.annotation.PreDestroy} method of this class.
803      * @param preDestroyMethodMetadata the method.
804      */

805     public void addPreDestroyMethodMetadata(final MethodAnnotationMetadata preDestroyMethodMetadata) {
806         checkLifeCycleDuplicate(preDestroyMethodMetadata, InterceptorType.PRE_DESTROY, getPreDestroyMethodsMetadata());
807         this.preDestroyMethodsMetadata.addFirst(preDestroyMethodMetadata);
808     }
809
810
811     /**
812      * @return the methods metadata with annotation &#64;{@link javax.ejb.PostActivate}.
813      */

814     public LinkedList JavaDoc<MethodAnnotationMetadata> getPostActivateMethodsMetadata() {
815         return postActivateMethodsMetadata;
816     }
817
818     /**
819      * Adds a &#64;{@link javax.ejb.PostActivate} method of this class.
820      * @param postActivateMethodMetadata the method.
821      */

822     public void addPostActivateMethodMetadata(final MethodAnnotationMetadata postActivateMethodMetadata) {
823         checkLifeCycleDuplicate(postActivateMethodMetadata, InterceptorType.POST_ACTIVATE, getPostActivateMethodsMetadata());
824         this.postActivateMethodsMetadata.addFirst(postActivateMethodMetadata);
825     }
826
827
828     /**
829      * @return the method metadata with annotation &#64;{@link javax.ejb.PrePassivate}.
830      */

831     public LinkedList JavaDoc<MethodAnnotationMetadata> getPrePassivateMethodsMetadata() {
832         return prePassivateMethodsMetadata;
833     }
834
835     /**
836      * Adds a &#64;{@link javax.ejb.PrePassivate} method of this class.
837      * @param prePassivateMethodMetadata the method.
838      */

839     public void addPrePassivateMethodMetadata(final MethodAnnotationMetadata prePassivateMethodMetadata) {
840         checkLifeCycleDuplicate(prePassivateMethodMetadata, InterceptorType.PRE_PASSIVATE, getPrePassivateMethodsMetadata());
841         this.prePassivateMethodsMetadata.addFirst(prePassivateMethodMetadata);
842     }
843
844
845     /**
846      * Is that this class is an interceptor class ?
847      * @return true if it the case, else false.
848      */

849     public boolean isInterceptor() {
850         return (aroundInvokeMethodsMetadata != null && aroundInvokeMethodsMetadata.size() > 0)
851         || (postConstructMethodsMetadata != null && postConstructMethodsMetadata.size() > 0)
852         || (preDestroyMethodsMetadata != null && preDestroyMethodsMetadata.size() > 0)
853         || (prePassivateMethodsMetadata != null && prePassivateMethodsMetadata.size() > 0)
854         || (postActivateMethodsMetadata != null && postActivateMethodsMetadata.size() > 0);
855     }
856
857
858     /**
859      * @return jEjbEJBs list representing &#64;{@link javax.ejb.EJBs} annotation.
860      */

861     public List JavaDoc<JEjbEJB> getJEjbEJBs() {
862         return jEjbEJBs;
863     }
864
865     /**
866      * Set JEjbEJBs object.
867      * @param jEjbEJBs list representing javax.ejb.EJBs annotation.
868      */

869     public void setJEjbEJBs(final List JavaDoc<JEjbEJB> jEjbEJBs) {
870         this.jEjbEJBs = jEjbEJBs;
871     }
872
873
874     /**
875      * @return JAnnotationResources list representing &#64;{@link javax.annotation.Resources} annotation.
876      */

877     public List JavaDoc<JAnnotationResource> getJAnnotationResources() {
878         return jAnnotationResources;
879     }
880
881     /**
882      * Sets JAnnotationResources object.
883      * @param jAnnotationResources list representing javax.annotation.Resources annotation.
884      */

885     public void setJAnnotationResources(final List JavaDoc<JAnnotationResource> jAnnotationResources) {
886         this.jAnnotationResources = jAnnotationResources;
887     }
888
889     /**
890      * @return javaxPersistencePersistenceContexts list representing &#64;{@link javax.persistence.PersistenceContexts}
891      * annotation.
892      */

893     public List JavaDoc<JavaxPersistenceContext> getJavaxPersistencePersistenceContexts() {
894         return javaxPersistencePersistenceContexts;
895     }
896
897     /**
898      * Sets JavaxPersistencePersistenceContexts object.
899      * @param javaxPersistencePersistenceContexts list representing &#64;{@link javax.persistence.PersistenceContexts} annotation.
900      */

901     public void setJavaxPersistencePersistenceContexts(final List JavaDoc<JavaxPersistenceContext> javaxPersistencePersistenceContexts) {
902         this.javaxPersistencePersistenceContexts = javaxPersistencePersistenceContexts;
903     }
904
905     /**
906      * @return javaxPersistencePersistenceUnits list representing &#64;{@link javax.persistence.PersistenceUnits} annotation.
907      */

908     public List JavaDoc<JavaxPersistenceUnit> getJavaxPersistencePersistenceUnits() {
909         return javaxPersistencePersistenceUnits;
910     }
911
912     /**
913      * Sets setJavaxPersistencePersistenceUnits object.
914      * @param javaxPersistencePersistenceUnits list representing &#64;{@link javax.persistence.PersistenceUnits} annotation.
915      */

916     public void setJavaxPersistencePersistenceUnits(final List JavaDoc<JavaxPersistenceUnit> javaxPersistencePersistenceUnits) {
917         this.javaxPersistencePersistenceUnits = javaxPersistencePersistenceUnits;
918     }
919
920     /**
921      * @return the attributes for a Stateless/Stateful/MDB
922      */

923     public JCommonBean getJCommonBean() {
924         return jCommonBean;
925     }
926
927     /**
928      * Sets the attributes for a Stateless/Stateful/MDB.
929      * @param commonBean the attributes
930      */

931     public void setJCommonBean(final JCommonBean commonBean) {
932         // ensure that there is a bean name
933
String JavaDoc ejbName = commonBean.getName();
934         if (ejbName == null || "".equals(ejbName)) {
935             // if not set, it has to be the unqualified name of the bean class. (simplified spec : 10.1.1)
936
commonBean.setName(className.substring(className.lastIndexOf("/") + 1));
937         }
938         jCommonBean = commonBean;
939     }
940
941     /**
942      * @return the attributes for a Stateful
943      */

944     public JStateful getJStateful() {
945         return jStateful;
946     }
947
948     /**
949      * Sets the attributes for a Stateful.
950      * @param jStateful the attributes
951      */

952     public void setJStateful(final JStateful jStateful) {
953         this.jStateful = jStateful;
954     }
955
956     /**
957      * @return the attributes for a Stateless
958      */

959     public JStateless getJStateless() {
960         return jStateless;
961     }
962
963     /**
964      * Sets the attributes for a Stateless.
965      * @param jStateless the attributes
966      */

967     public void setJStateless(final JStateless jStateless) {
968         this.jStateless = jStateless;
969     }
970
971     /**
972      * @return true if the class has been modified.
973      */

974     public boolean wasModified() {
975         return modified;
976     }
977
978     /**
979      * Defines that this class has been modified.
980      */

981     public void setModified() {
982         this.modified = true;
983     }
984
985     /**
986      * Sets the list of roles declared on this class.
987      * @param declareRoles the list of roles.
988      */

989     public void setDeclareRoles(final List JavaDoc<String JavaDoc> declareRoles) {
990         this.declareRoles = declareRoles;
991     }
992
993     /**
994      * @return the list of roles declared on this class.
995      */

996     public List JavaDoc<String JavaDoc> getDeclareRoles() {
997         return declareRoles;
998     }
999
1000    /**
1001     * Set the list of roles allowed on this class/method.
1002     * @param rolesAllowed the list of roles.
1003     */

1004    public void setRolesAllowed(final List JavaDoc<String JavaDoc> rolesAllowed) {
1005        this.rolesAllowed = rolesAllowed;
1006    }
1007
1008    /**
1009     * @return the list of roles allowed on this class/method.
1010     */

1011    public List JavaDoc<String JavaDoc> getRolesAllowed() {
1012        return rolesAllowed;
1013    }
1014
1015    /**
1016     * This class has PermitAll annotation.
1017     * @param permitAll the boolean value.
1018     */

1019    public void setPermitAll(final boolean permitAll) {
1020        this.permitAll = permitAll;
1021    }
1022
1023    /**
1024     * @return true if PermitAll annotation.
1025     */

1026    public boolean hasPermitAll() {
1027        return permitAll;
1028    }
1029
1030    /**
1031     * Set the value of the run-as property.
1032     * @param runAs the run-as property.
1033     */

1034    public void setRunAs(final String JavaDoc runAs) {
1035        this.runAs = runAs;
1036    }
1037
1038    /**
1039     * @return the name of the security-role of the run-as element.
1040     */

1041    public String JavaDoc getRunAs() {
1042        return runAs;
1043    }
1044}
1045
Popular Tags