001: /**
002: * EasyBeans
003: * Copyright (C) 2006-2007 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: MethodAnnotationMetadata.java 2059 2007-11-22 17:22:33Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.deployment.annotations.metadata;
025:
026: import java.util.List;
027: import java.util.Map;
028:
029: import javax.ejb.Remove;
030: import javax.ejb.TransactionAttributeType;
031:
032: import org.ow2.easybeans.deployment.annotations.InterceptorType;
033: import org.ow2.easybeans.deployment.annotations.JClassInterceptor;
034: import org.ow2.easybeans.deployment.annotations.JMethod;
035: import org.ow2.easybeans.deployment.annotations.TransactionAttributeLevel;
036: import org.ow2.easybeans.deployment.annotations.impl.JInterceptors;
037: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.IAnnotationSecurityPermitAll;
038: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.IAnnotationSecurityRolesAllowed;
039: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.IEJBInterceptors;
040: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.IInterceptorExcludeDefaultInterceptors;
041: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.ITransactionAttribute;
042:
043: /**
044: * This class represents the annotation metadata of a method.
045: * @author Florent Benoit
046: */
047: public class MethodAnnotationMetadata extends CommonAnnotationMetadata
048: implements Cloneable, ITransactionAttribute, IEJBInterceptors,
049: IAnnotationSecurityRolesAllowed, IAnnotationSecurityPermitAll,
050: IInterceptorExcludeDefaultInterceptors {
051:
052: /**
053: * Logger.
054: */
055: //private static Log logger = LogFactory.getLog(MethodAnnotationMetadata.class);
056: /**
057: * Method on which we got metadata.
058: */
059: private JMethod jMethod = null;
060:
061: /**
062: * Parent metadata.
063: */
064: private ClassAnnotationMetadata classAnnotationMetadata = null;
065:
066: /**
067: * Original parent metadata (if method is inherited).
068: */
069: private ClassAnnotationMetadata originalClassAnnotationMetadata = null;
070:
071: /**
072: * Type of transaction.
073: */
074: private TransactionAttributeType transactionAttributeType = null;
075:
076: /**
077: * Level of transaction (when overriding with XML, need to know if the level is sufficient or not).
078: */
079: private TransactionAttributeLevel transactionAttributeLevel = TransactionAttributeLevel.ANNOTATION;
080:
081: /**
082: * @{@link javax.ejb.Remove} annotation.
083: */
084: private Remove remove = null;
085:
086: /**
087: * This method is a business method ?
088: */
089: private boolean businessMethod = false;
090:
091: /**
092: * PostConstruct method ?
093: */
094: private boolean postConstruct = false;
095:
096: /**
097: * PreDestroy method ?
098: */
099: private boolean preDestroy = false;
100:
101: /**
102: * PostActivate method ?
103: */
104: private boolean postActivate = false;
105:
106: /**
107: * PrePassivate method ?
108: */
109: private boolean prePassivate = false;
110:
111: /**
112: * @{@link javax.interceptor.AroundInvoke} method used by interceptors ?
113: */
114: private boolean aroundInvoke = false;
115:
116: /**
117: *This method is a method from a super class ?<br>
118: * This flag is used by enhancers
119: */
120: private boolean inherited = false;
121:
122: /**
123: * @{@link javax.interceptor.ExcludeClassInterceptors} method ?
124: */
125: private boolean excludeClassInterceptors = false;
126:
127: /**
128: * @{@link javax.ejb.Timeout} method ?
129: */
130: private boolean timeout = false;
131:
132: /**
133: * EasyBeans global interceptors.<br>
134: * These interceptors correspond to a list of interceptors
135: * that need to be present first on this current method.
136: */
137: private List<JClassInterceptor> globalEasyBeansInterceptors = null;
138:
139: /**
140: * EasyBeans method interceptors. These interceptors correspond to a list of Interceptors like security or transaction.
141: */
142: private List<JClassInterceptor> interceptors = null;
143:
144: /**
145: * List of annotation interceptors.
146: */
147: private JInterceptors annotationInterceptors = null;
148:
149: /**
150: * User interceptors. These interceptors correspond to a list of Interceptor that user has specified in its bean class.
151: * Map<interceptor type <--> List of methods/class corresponding to the interceptor>
152: */
153: private Map<InterceptorType, List<JClassInterceptor>> userInterceptors = null;
154:
155: /**
156: * List of roles that are allowed on this class/bean.
157: */
158: private List<String> rolesAllowed = null;
159:
160: /**
161: * This class/bean has the PermitAll annotation.
162: */
163: private boolean permitAll = false;
164:
165: /**
166: * This class/bean has the DenyAll annotation.
167: */
168: private boolean denyAll = false;
169:
170: /**
171: * @{@link javax.interceptor.ExcludeDefaultInterceptors} method ?
172: */
173: private boolean excludeDefaultInterceptors = false;
174:
175: /**
176: * Constructor.
177: * @param jMethod the method on which we will set/add metadata
178: * @param classAnnotationMetadata the parent metadata.
179: */
180: public MethodAnnotationMetadata(final JMethod jMethod,
181: final ClassAnnotationMetadata classAnnotationMetadata) {
182: this .jMethod = jMethod;
183: this .classAnnotationMetadata = classAnnotationMetadata;
184: }
185:
186: /**
187: * @return name of the method
188: */
189: public String getMethodName() {
190: return this .jMethod.getName();
191: }
192:
193: /**
194: * @return JMethod object
195: */
196: public JMethod getJMethod() {
197: return this .jMethod;
198: }
199:
200: /**
201: * Sets the JMethod object (for changing some data).
202: * @param jMethod the given JMethod object
203: */
204: public void setJMethod(final JMethod jMethod) {
205: this .jMethod = jMethod;
206: }
207:
208: /**
209: * @return transaction Attribute type.
210: * @see javax.ejb.TransactionAttributeType
211: */
212: public TransactionAttributeType getTransactionAttributeType() {
213: return transactionAttributeType;
214: }
215:
216: /**
217: * Sets Transaction Attribute Level.
218: * @param transactionAttributeLevel the level of transaction.
219: */
220: public void setTransactionAttributeLevel(
221: final TransactionAttributeLevel transactionAttributeLevel) {
222: this .transactionAttributeLevel = transactionAttributeLevel;
223: }
224:
225: /**
226: * @return transaction Attribute Level.
227: */
228: public TransactionAttributeLevel getTransactionAttributeLevel() {
229: return transactionAttributeLevel;
230: }
231:
232: /**
233: * Sets Transaction Attribute Type.
234: * @see javax.ejb.TransactionAttributeType
235: * @param transactionAttributeType the type of transaction.
236: */
237: public void setTransactionAttributeType(
238: final TransactionAttributeType transactionAttributeType) {
239: this .transactionAttributeType = transactionAttributeType;
240: }
241:
242: /**
243: * @return true if the method is a business method.
244: */
245: public boolean isBusinessMethod() {
246: return businessMethod;
247: }
248:
249: /**
250: * This method is a business method.
251: * @param flag true/false if method is a business method.
252: */
253: public void setBusinessMethod(final boolean flag) {
254: this .businessMethod = flag;
255: }
256:
257: /**
258: * @return true if the method is a lifecycle method.
259: */
260: public boolean isLifeCycleMethod() {
261: return isPostActivate() || isPostConstruct() || isPreDestroy()
262: || isPrePassivate();
263: }
264:
265: /**
266: * @return remove attributes @{@link javax.ejb.Remove} attributes
267: */
268: public Remove getJRemove() {
269: return this .remove;
270: }
271:
272: /**
273: * Sets @{@link javax.ejb.Remove} attribute.
274: * @param remove contains the attribute with retainIfException.
275: */
276: public void setRemove(final Remove remove) {
277: this .remove = remove;
278: }
279:
280: /**
281: * @return string representation
282: */
283: @Override
284: public String toString() {
285: StringBuilder sb = new StringBuilder();
286: String titleIndent = " ";
287:
288: // classname
289: sb.append(titleIndent);
290: sb.append(this .getClass().getName().substring(
291: this .getClass().getPackage().getName().length() + 1));
292: sb.append("[\n");
293:
294: // Add super class toString()
295: sb.append(super .toString());
296:
297: // Method
298: concatStringBuilder("jMethod", jMethod, sb);
299:
300: // inherited
301: concatStringBuilder("inherited", Boolean.valueOf(inherited), sb);
302:
303: // transactionAttributeType
304: concatStringBuilder("transactionAttributeType",
305: transactionAttributeType, sb);
306:
307: // transactionAttributeLevel
308: concatStringBuilder("transactionAttributeLevel",
309: transactionAttributeLevel, sb);
310:
311: // remove
312: concatStringBuilder("remove", remove, sb);
313:
314: // businessMethod
315: concatStringBuilder("businessMethod", Boolean
316: .valueOf(businessMethod), sb);
317:
318: // aroundInvoke
319: concatStringBuilder("aroundInvoke", Boolean
320: .valueOf(aroundInvoke), sb);
321:
322: // postConstruct
323: concatStringBuilder("postConstruct", Boolean
324: .valueOf(postConstruct), sb);
325:
326: // preDestroy
327: concatStringBuilder("preDestroy", Boolean.valueOf(preDestroy),
328: sb);
329:
330: // postActivate
331: concatStringBuilder("postActivate", Boolean
332: .valueOf(postActivate), sb);
333:
334: // prePassivate
335: concatStringBuilder("prePassivate", Boolean
336: .valueOf(prePassivate), sb);
337:
338: // timeout
339: concatStringBuilder("timeout", Boolean.valueOf(timeout), sb);
340:
341: // annotation Interceptors
342: concatStringBuilder("annotationInterceptors",
343: annotationInterceptors, sb);
344:
345: // interceptors
346: concatStringBuilder("interceptors", interceptors, sb);
347:
348: // rolesAllowed
349: concatStringBuilder("rolesAllowed", rolesAllowed, sb);
350:
351: // permitAll
352: concatStringBuilder("permitAll", Boolean.valueOf(permitAll), sb);
353:
354: // denyAll
355: concatStringBuilder("denyAll", Boolean.valueOf(denyAll), sb);
356:
357: // denyAll
358: concatStringBuilder("excludeDefaultInterceptors", Boolean
359: .valueOf(excludeDefaultInterceptors), sb);
360:
361: sb.append(titleIndent);
362: sb.append("]\n");
363: return sb.toString();
364: }
365:
366: /**
367: * @return true if method has @{@link javax.ejb.PostActivate}
368: */
369: public boolean isPostActivate() {
370: return postActivate;
371: }
372:
373: /**
374: * Sets true if method has @{@link javax.ejb.PostActivate}.
375: * @param postActivate true/false.
376: */
377: public void setPostActivate(final boolean postActivate) {
378: this .postActivate = postActivate;
379: }
380:
381: /**
382: * @return true if method has @{@link javax.annotation.PostConstruct}.
383: */
384: public boolean isPostConstruct() {
385: return postConstruct;
386: }
387:
388: /**
389: * Sets true if method has @{@link javax.annotation.PostConstruct}.
390: * @param postConstruct true/false.
391: */
392: public void setPostConstruct(final boolean postConstruct) {
393: this .postConstruct = postConstruct;
394: }
395:
396: /**
397: * @return true if method has @{@link javax.annotation.PreDestroy}.
398: */
399:
400: public boolean isPreDestroy() {
401: return preDestroy;
402: }
403:
404: /**
405: * Sets true if method has @{@link javax.annotation.PreDestroy}.
406: * @param preDestroy true/false.
407: */
408: public void setPreDestroy(final boolean preDestroy) {
409: this .preDestroy = preDestroy;
410: }
411:
412: /**
413: * @return true if method has @{@link javax.ejb.PrePassivate}.
414: */
415:
416: public boolean isPrePassivate() {
417: return prePassivate;
418: }
419:
420: /**
421: * Sets true if method has @{@link javax.ejb.PrePassivate}.
422: * @param prePassivate true/false.
423: */
424: public void setPrePassivate(final boolean prePassivate) {
425: this .prePassivate = prePassivate;
426: }
427:
428: /**
429: * @return true if method has @{@link javax.ejb.Timeout}.
430: */
431: public boolean isTimeout() {
432: return timeout;
433: }
434:
435: /**
436: * Sets true if method has @{@link javax.ejb.Timeout}.
437: * @param timeout true/false.
438: */
439: public void setTimeout(final boolean timeout) {
440: this .timeout = timeout;
441: }
442:
443: /**
444: * @return true if method has @{@link javax.interceptor.AroundInvoke}.
445: */
446: public boolean isAroundInvoke() {
447: return aroundInvoke;
448: }
449:
450: /**
451: * Sets true if method has @{@link javax.interceptor.AroundInvoke}.
452: * @param aroundInvoke true/false
453: */
454: public void setAroundInvoke(final boolean aroundInvoke) {
455: this .aroundInvoke = aroundInvoke;
456: }
457:
458: /**
459: * @return true if this method is inherited from a super class
460: */
461: public boolean isInherited() {
462: return inherited;
463: }
464:
465: /**
466: * Sets the inheritance of this method.
467: * @param inherited true if method is from a super class
468: * @param originalClassAnnotationMetadata the metadata of the original class (not inherited)
469: */
470: public void setInherited(
471: final boolean inherited,
472: final ClassAnnotationMetadata originalClassAnnotationMetadata) {
473: this .inherited = inherited;
474: this .originalClassAnnotationMetadata = originalClassAnnotationMetadata;
475: }
476:
477: /**
478: * @return true if this method won't use user interceptors.
479: */
480: public boolean isExcludedClassInterceptors() {
481: return excludeClassInterceptors;
482: }
483:
484: /**
485: * Flag this method as a method which exclude user interceptors.
486: * @param excludeClassInterceptors true if this method is a method which exclude user interceptors.
487: */
488: public void setExcludeClassInterceptors(
489: final boolean excludeClassInterceptors) {
490: this .excludeClassInterceptors = excludeClassInterceptors;
491: }
492:
493: /**
494: * @return parent metadata (class)
495: */
496: public ClassAnnotationMetadata getClassAnnotationMetadata() {
497: return classAnnotationMetadata;
498: }
499:
500: /**
501: * @return original parent metadata (class) if inherited.
502: */
503: public ClassAnnotationMetadata getOriginalClassAnnotationMetadata() {
504: return originalClassAnnotationMetadata;
505: }
506:
507: /**
508: * @return list of interceptors that enhancer will use. (ie : security/transaction)
509: */
510: public List<JClassInterceptor> getInterceptors() {
511: return interceptors;
512: }
513:
514: /**
515: * Sets the list of interceptors(tx, security, etc) that enhancers will use.<br>
516: * These interceptors are defined per methods.
517: * @param interceptors list of interceptors that enhancer will use.
518: */
519: public void setInterceptors(
520: final List<JClassInterceptor> interceptors) {
521: this .interceptors = interceptors;
522: }
523:
524: /**
525: * @return object representing list of @{@link javax.interceptor.Interceptors}.
526: */
527: public JInterceptors getAnnotationInterceptors() {
528: return annotationInterceptors;
529: }
530:
531: /**
532: * Sets the object representing the @{@link javax.interceptor.Interceptors} annotation.
533: * @param annotationInterceptors list of classes
534: */
535: public void setAnnotationsInterceptors(
536: final JInterceptors annotationInterceptors) {
537: this .annotationInterceptors = annotationInterceptors;
538: }
539:
540: /**
541: * @return Map<interceptor type <--> List of methods/class corresponding to the interceptor>
542: * of user interceptors that enhancer will use.
543: */
544: public Map<InterceptorType, List<JClassInterceptor>> getUserEasyBeansInterceptors() {
545: return userInterceptors;
546: }
547:
548: /**
549: * Sets the list of user interceptors that enhancers will use.<br>
550: * These interceptors are defined in bean class.
551: * @param userInterceptors list of interceptors that enhancer will use.
552: */
553: public void setUserInterceptors(
554: final Map<InterceptorType, List<JClassInterceptor>> userInterceptors) {
555: this .userInterceptors = userInterceptors;
556: }
557:
558: /**
559: * @return list of global interceptors that enhancer will use. (ie : Remove interceptor)
560: */
561: public List<JClassInterceptor> getGlobalEasyBeansInterceptors() {
562: return globalEasyBeansInterceptors;
563: }
564:
565: /**
566: * Sets the list of global interceptors that enhancers will use.
567: * @param globalEasyBeansInterceptors list of interceptors that enhancer will use.
568: */
569: public void setGlobalEasyBeansInterceptors(
570: final List<JClassInterceptor> globalEasyBeansInterceptors) {
571: this .globalEasyBeansInterceptors = globalEasyBeansInterceptors;
572: }
573:
574: /**
575: * @return a clone object.
576: */
577: @Override
578: public Object clone() {
579: MethodAnnotationMetadata newMethodAnnotationMetadata = new MethodAnnotationMetadata(
580: jMethod, classAnnotationMetadata);
581: newMethodAnnotationMetadata
582: .setAnnotationsInterceptors(annotationInterceptors);
583: newMethodAnnotationMetadata.setAroundInvoke(aroundInvoke);
584: newMethodAnnotationMetadata.setBusinessMethod(businessMethod);
585: newMethodAnnotationMetadata
586: .setExcludeClassInterceptors(excludeClassInterceptors);
587: newMethodAnnotationMetadata.setInherited(inherited,
588: originalClassAnnotationMetadata);
589: newMethodAnnotationMetadata.setInterceptors(interceptors);
590: newMethodAnnotationMetadata
591: .setJAnnotationResource(getJAnnotationResource());
592: newMethodAnnotationMetadata.setJEjbEJB(getJEjbEJB());
593: newMethodAnnotationMetadata
594: .setJavaxPersistenceContext(getJavaxPersistenceContext());
595: newMethodAnnotationMetadata
596: .setJavaxPersistenceUnit(getJavaxPersistenceUnit());
597: newMethodAnnotationMetadata.setPostActivate(postActivate);
598: newMethodAnnotationMetadata.setPostConstruct(postConstruct);
599: newMethodAnnotationMetadata.setPreDestroy(preDestroy);
600: newMethodAnnotationMetadata.setPrePassivate(prePassivate);
601: newMethodAnnotationMetadata.setRemove(remove);
602: newMethodAnnotationMetadata.setTimeout(timeout);
603: newMethodAnnotationMetadata
604: .setTransactionAttributeType(transactionAttributeType);
605: newMethodAnnotationMetadata
606: .setTransactionAttributeLevel(transactionAttributeLevel);
607: newMethodAnnotationMetadata
608: .setUserInterceptors(userInterceptors);
609: newMethodAnnotationMetadata
610: .setGlobalEasyBeansInterceptors(globalEasyBeansInterceptors);
611: newMethodAnnotationMetadata.setDenyAll(denyAll);
612: newMethodAnnotationMetadata.setPermitAll(permitAll);
613: newMethodAnnotationMetadata.setRolesAllowed(rolesAllowed);
614: return newMethodAnnotationMetadata;
615: }
616:
617: /**
618: * Replace the link to the classannotation metadata.
619: * @param classAnnotationMetadata new object for the link.
620: */
621: public void setClassAnnotationMetadata(
622: final ClassAnnotationMetadata classAnnotationMetadata) {
623: this .classAnnotationMetadata = classAnnotationMetadata;
624: }
625:
626: /**
627: * Set the list of roles allowed on this class/method.
628: * @param rolesAllowed the list of roles.
629: */
630: public void setRolesAllowed(final List<String> rolesAllowed) {
631: this .rolesAllowed = rolesAllowed;
632: }
633:
634: /**
635: * @return the list of roles allowed on this class/method.
636: */
637: public List<String> getRolesAllowed() {
638: return rolesAllowed;
639: }
640:
641: /**
642: * This method has PermitAll annotation.
643: * @param permitAll the boolean value.
644: */
645: public void setPermitAll(final boolean permitAll) {
646: this .permitAll = permitAll;
647: }
648:
649: /**
650: * @return true if PermitAll annotation.
651: */
652: public boolean hasPermitAll() {
653: return permitAll;
654: }
655:
656: /**
657: * This method has DenyAll annotation.
658: * @param denyAll the boolean value.
659: */
660: public void setDenyAll(final boolean denyAll) {
661: this .denyAll = denyAll;
662: }
663:
664: /**
665: * @return true if DenyAll annotation.
666: */
667: public boolean hasDenyAll() {
668: return denyAll;
669: }
670:
671: /**
672: * @return true if this class won't use default interceptors.
673: */
674: public boolean isExcludedDefaultInterceptors() {
675: return excludeDefaultInterceptors;
676: }
677:
678: /**
679: * Flag this class as a class which exclude default interceptors.
680: * @param excludeDefaultInterceptors true if this class is a class which exclude default interceptors.
681: */
682: public void setExcludeDefaultInterceptors(
683: final boolean excludeDefaultInterceptors) {
684: this.excludeDefaultInterceptors = excludeDefaultInterceptors;
685: }
686: }
|