001: package com.bm.ejb3metadata.annotations.metadata;
002:
003: import java.util.List;
004: import java.util.Map;
005:
006: import javax.ejb.Remove;
007: import javax.ejb.TransactionAttributeType;
008:
009: import com.bm.ejb3metadata.annotations.InterceptorType;
010: import com.bm.ejb3metadata.annotations.JClassInterceptor;
011: import com.bm.ejb3metadata.annotations.JMethod;
012: import com.bm.ejb3metadata.annotations.impl.JInterceptors;
013: import com.bm.ejb3metadata.annotations.metadata.interfaces.IEJBInterceptors;
014: import com.bm.ejb3metadata.annotations.metadata.interfaces.ITransactionAttribute;
015:
016: /**
017: * This class represents the annotation metadata of a method.
018: * @author Daniel Wiese
019: */
020: public class MethodAnnotationMetadata extends CommonAnnotationMetadata
021: implements Cloneable, ITransactionAttribute, IEJBInterceptors {
022:
023: /**
024: * Logger.
025: */
026: //private static JLog logger = JLogFactory.getLog(MethodAnnotationMetadata.class);
027: /**
028: * Method on which we got metadata.
029: */
030: private JMethod jMethod = null;
031:
032: /**
033: * Parent metadata.
034: */
035: private ClassAnnotationMetadata classAnnotationMetadata = null;
036:
037: /**
038: * Original parent metadata (if method is inherited).
039: */
040: private ClassAnnotationMetadata originalClassAnnotationMetadata = null;
041:
042: /**
043: * Type of transaction.
044: */
045: private TransactionAttributeType transactionAttributeType = null;
046:
047: /**
048: * @{@link javax.ejb.Remove} annotation.
049: */
050: private Remove remove = null;
051:
052: /**
053: * This method is a business method ?
054: */
055: private boolean businessMethod = false;
056:
057: /**
058: * PostConstruct method ?
059: */
060: private boolean postConstruct = false;
061:
062: /**
063: * PreDestroy method ?
064: */
065: private boolean preDestroy = false;
066:
067: /**
068: * PostActivate method ?
069: */
070: private boolean postActivate = false;
071:
072: /**
073: * PrePassivate method ?
074: */
075: private boolean prePassivate = false;
076:
077: /**
078: * @{@link javax.interceptor.AroundInvoke} method used by interceptors ?
079: */
080: private boolean aroundInvoke = false;
081:
082: /**
083: *This method is a method from a super class ?<br>
084: * This flag is used by enhancers
085: */
086: private boolean inherited = false;
087:
088: /**
089: * @{@link javax.interceptor.ExcludeClassInterceptors} method ?
090: */
091: private boolean excludeClassInterceptors = false;
092:
093: /**
094: * @{@link javax.ejb.Timeout} method ?
095: */
096: private boolean timeout = false;
097:
098: /**
099: * EasyBeans global interceptors.<br>
100: * These interceptors correspond to a list of interceptors
101: * that need to be present first on this current method.
102: */
103: private List<JClassInterceptor> globalEasyBeansInterceptors = null;
104:
105: /**
106: * EasyBeans method interceptors. These interceptors correspond to a list of Interceptors like security or transaction.
107: */
108: private List<JClassInterceptor> interceptors = null;
109:
110: /**
111: * List of annotation interceptors.
112: */
113: private JInterceptors annotationInterceptors = null;
114:
115: /**
116: * User interceptors. These interceptors correspond to a list of Interceptor that user has specified in its bean class.
117: * Map<interceptor type <--> List of methods/class corresponding to the interceptor>
118: */
119: private Map<InterceptorType, List<JClassInterceptor>> userInterceptors = null;
120:
121: /**
122: * Constructor.
123: * @param jMethod the method on which we will set/add metadata
124: * @param classAnnotationMetadata the parent metadata.
125: */
126: public MethodAnnotationMetadata(final JMethod jMethod,
127: final ClassAnnotationMetadata classAnnotationMetadata) {
128: this .jMethod = jMethod;
129: this .classAnnotationMetadata = classAnnotationMetadata;
130: }
131:
132: /**
133: * @return name of the method
134: */
135: public String getMethodName() {
136: return this .jMethod.getName();
137: }
138:
139: /**
140: * @return JMethod object
141: */
142: public JMethod getJMethod() {
143: return this .jMethod;
144: }
145:
146: /**
147: * @return transaction Attribute type.
148: * @see javax.ejb.TransactionAttributeType
149: */
150: public TransactionAttributeType getTransactionAttributeType() {
151: return transactionAttributeType;
152: }
153:
154: /**
155: * Sets Transaction Attribute Type.
156: * @see javax.ejb.TransactionAttributeType
157: * @param transactionAttributeType the type of transaction.
158: */
159: public void setTransactionAttributeType(
160: final TransactionAttributeType transactionAttributeType) {
161: this .transactionAttributeType = transactionAttributeType;
162: }
163:
164: /**
165: * @return true if the method is a business method.
166: */
167: public boolean isBusinessMethod() {
168: return businessMethod;
169: }
170:
171: /**
172: * This method is a business method.
173: * @param flag true/false if method is a business method.
174: */
175: public void setBusinessMethod(final boolean flag) {
176: this .businessMethod = flag;
177: }
178:
179: /**
180: * @return true if the method is a lifecycle method.
181: */
182: public boolean isLifeCycleMethod() {
183: return isPostActivate() || isPostConstruct() || isPreDestroy()
184: || isPrePassivate();
185: }
186:
187: /**
188: * @return remove attributes @{@link javax.ejb.Remove} attributes
189: */
190: public Remove getJRemove() {
191: return this .remove;
192: }
193:
194: /**
195: * Sets @{@link javax.ejb.Remove} attribute.
196: * @param remove contains the attribute with retainIfException.
197: */
198: public void setRemove(final Remove remove) {
199: this .remove = remove;
200: }
201:
202: /**
203: * @return string representation
204: */
205: @Override
206: public String toString() {
207: StringBuilder sb = new StringBuilder();
208: String titleIndent = " ";
209:
210: // classname
211: sb.append(titleIndent);
212: sb.append(this .getClass().getName().substring(
213: this .getClass().getPackage().getName().length() + 1));
214: sb.append("[\n");
215:
216: // Add super class toString()
217: sb.append(super .toString());
218:
219: // Method
220: concatStringBuilder("jMethod", jMethod, sb);
221:
222: // inherited
223: concatStringBuilder("inherited", Boolean.valueOf(inherited), sb);
224:
225: // transactionAttributeType
226: concatStringBuilder("transactionAttributeType",
227: transactionAttributeType, sb);
228:
229: // remove
230: concatStringBuilder("remove", remove, sb);
231:
232: // businessMethod
233: concatStringBuilder("businessMethod", Boolean
234: .valueOf(businessMethod), sb);
235:
236: // aroundInvoke
237: concatStringBuilder("aroundInvoke", Boolean
238: .valueOf(aroundInvoke), sb);
239:
240: // postConstruct
241: concatStringBuilder("postConstruct", Boolean
242: .valueOf(postConstruct), sb);
243:
244: // preDestroy
245: concatStringBuilder("preDestroy", Boolean.valueOf(preDestroy),
246: sb);
247:
248: // postActivate
249: concatStringBuilder("postActivate", Boolean
250: .valueOf(postActivate), sb);
251:
252: // prePassivate
253: concatStringBuilder("prePassivate", Boolean
254: .valueOf(prePassivate), sb);
255:
256: // timeout
257: concatStringBuilder("timeout", Boolean.valueOf(timeout), sb);
258:
259: // annotation Interceptors
260: concatStringBuilder("annotationInterceptors",
261: annotationInterceptors, sb);
262:
263: // interceptors
264: concatStringBuilder("interceptors", interceptors, sb);
265:
266: sb.append(titleIndent);
267: sb.append("]\n");
268: return sb.toString();
269: }
270:
271: /**
272: * @return true if method has @{@link javax.ejb.PostActivate}
273: */
274: public boolean isPostActivate() {
275: return postActivate;
276: }
277:
278: /**
279: * Sets true if method has @{@link javax.ejb.PostActivate}.
280: * @param postActivate true/false.
281: */
282: public void setPostActivate(final boolean postActivate) {
283: this .postActivate = postActivate;
284: }
285:
286: /**
287: * @return true if method has @{@link javax.annotation.PostConstruct}.
288: */
289: public boolean isPostConstruct() {
290: return postConstruct;
291: }
292:
293: /**
294: * Sets true if method has @{@link javax.annotation.PostConstruct}.
295: * @param postConstruct true/false.
296: */
297: public void setPostConstruct(final boolean postConstruct) {
298: this .postConstruct = postConstruct;
299: }
300:
301: /**
302: * @return true if method has @{@link javax.annotation.PreDestroy}.
303: */
304:
305: public boolean isPreDestroy() {
306: return preDestroy;
307: }
308:
309: /**
310: * Sets true if method has @{@link javax.annotation.PreDestroy}.
311: * @param preDestroy true/false.
312: */
313: public void setPreDestroy(final boolean preDestroy) {
314: this .preDestroy = preDestroy;
315: }
316:
317: /**
318: * @return true if method has @{@link javax.ejb.PrePassivate}.
319: */
320:
321: public boolean isPrePassivate() {
322: return prePassivate;
323: }
324:
325: /**
326: * Sets true if method has @{@link javax.ejb.PrePassivate}.
327: * @param prePassivate true/false.
328: */
329: public void setPrePassivate(final boolean prePassivate) {
330: this .prePassivate = prePassivate;
331: }
332:
333: /**
334: * @return true if method has @{@link javax.ejb.Timeout}.
335: */
336: public boolean isTimeout() {
337: return timeout;
338: }
339:
340: /**
341: * Sets true if method has @{@link javax.ejb.Timeout}.
342: * @param timeout true/false.
343: */
344: public void setTimeout(final boolean timeout) {
345: this .timeout = timeout;
346: }
347:
348: /**
349: * @return true if method has @{@link javax.interceptor.AroundInvoke}.
350: */
351: public boolean isAroundInvoke() {
352: return aroundInvoke;
353: }
354:
355: /**
356: * Sets true if method has @{@link javax.interceptor.AroundInvoke}.
357: * @param aroundInvoke true/false
358: */
359: public void setAroundInvoke(final boolean aroundInvoke) {
360: this .aroundInvoke = aroundInvoke;
361: }
362:
363: /**
364: * @return true if this method is inherited from a super class
365: */
366: public boolean isInherited() {
367: return inherited;
368: }
369:
370: /**
371: * Sets the inheritance of this method.
372: * @param inherited true if method is from a super class
373: * @param originalClassAnnotationMetadata the metadata of the original class (not inherited)
374: */
375: public void setInherited(
376: final boolean inherited,
377: final ClassAnnotationMetadata originalClassAnnotationMetadata) {
378: this .inherited = inherited;
379: this .originalClassAnnotationMetadata = originalClassAnnotationMetadata;
380: }
381:
382: /**
383: * @return true if this method won't use user interceptors.
384: */
385: public boolean isExcludedClassInterceptors() {
386: return excludeClassInterceptors;
387: }
388:
389: /**
390: * Flag this method as a method which exclude user interceptors.
391: * @param excludeClassInterceptors true if this method is a method which exclude user interceptors.
392: */
393: public void setExcludeClassInterceptors(
394: final boolean excludeClassInterceptors) {
395: this .excludeClassInterceptors = excludeClassInterceptors;
396: }
397:
398: /**
399: * @return parent metadata (class)
400: */
401: public ClassAnnotationMetadata getClassAnnotationMetadata() {
402: return classAnnotationMetadata;
403: }
404:
405: /**
406: * @return original parent metadata (class) if inherited.
407: */
408: public ClassAnnotationMetadata getOriginalClassAnnotationMetadata() {
409: return originalClassAnnotationMetadata;
410: }
411:
412: /**
413: * @return list of interceptors that enhancer will use. (ie : security/transaction)
414: */
415: public List<JClassInterceptor> getInterceptors() {
416: return interceptors;
417: }
418:
419: /**
420: * Sets the list of interceptors(tx, security, etc) that enhancers will use.<br>
421: * These interceptors are defined per methods.
422: * @param interceptors list of interceptors that enhancer will use.
423: */
424: public void setInterceptors(
425: final List<JClassInterceptor> interceptors) {
426: this .interceptors = interceptors;
427: }
428:
429: /**
430: * @return object representing list of @{@link javax.interceptor.Interceptors}.
431: */
432: public JInterceptors getAnnotationInterceptors() {
433: return annotationInterceptors;
434: }
435:
436: /**
437: * Sets the object representing the @{@link javax.interceptor.Interceptors} annotation.
438: * @param annotationInterceptors list of classes
439: */
440: public void setAnnotationsInterceptors(
441: final JInterceptors annotationInterceptors) {
442: this .annotationInterceptors = annotationInterceptors;
443: }
444:
445: /**
446: * @return Map<interceptor type <--> List of methods/class corresponding to the interceptor>
447: * of user interceptors that enhancer will use.
448: */
449: public Map<InterceptorType, List<JClassInterceptor>> getUserEasyBeansInterceptors() {
450: return userInterceptors;
451: }
452:
453: /**
454: * Sets the list of user interceptors that enhancers will use.<br>
455: * These interceptors are defined in bean class.
456: * @param userInterceptors list of interceptors that enhancer will use.
457: */
458: public void setUserInterceptors(
459: final Map<InterceptorType, List<JClassInterceptor>> userInterceptors) {
460: this .userInterceptors = userInterceptors;
461: }
462:
463: /**
464: * @return list of global interceptors that enhancer will use. (ie : Remove interceptor)
465: */
466: public List<JClassInterceptor> getGlobalEasyBeansInterceptors() {
467: return globalEasyBeansInterceptors;
468: }
469:
470: /**
471: * Sets the list of global interceptors that enhancers will use.
472: * @param globalEasyBeansInterceptors list of interceptors that enhancer will use.
473: */
474: public void setGlobalEasyBeansInterceptors(
475: final List<JClassInterceptor> globalEasyBeansInterceptors) {
476: this .globalEasyBeansInterceptors = globalEasyBeansInterceptors;
477: }
478:
479: /**
480: * @return a clone object.
481: */
482: @Override
483: public Object clone() {
484: MethodAnnotationMetadata newMethodAnnotationMetadata = new MethodAnnotationMetadata(
485: jMethod, classAnnotationMetadata);
486: newMethodAnnotationMetadata
487: .setAnnotationsInterceptors(annotationInterceptors);
488: newMethodAnnotationMetadata.setAroundInvoke(aroundInvoke);
489: newMethodAnnotationMetadata.setBusinessMethod(businessMethod);
490: newMethodAnnotationMetadata
491: .setExcludeClassInterceptors(excludeClassInterceptors);
492: newMethodAnnotationMetadata.setInherited(inherited,
493: originalClassAnnotationMetadata);
494: newMethodAnnotationMetadata.setInterceptors(interceptors);
495: newMethodAnnotationMetadata
496: .setJAnnotationResource(getJAnnotationResource());
497: newMethodAnnotationMetadata.setJEjbEJB(getJEjbEJB());
498: newMethodAnnotationMetadata
499: .setJavaxPersistenceContext(getJavaxPersistenceContext());
500: newMethodAnnotationMetadata
501: .setJavaxPersistenceUnit(getJavaxPersistenceUnit());
502: newMethodAnnotationMetadata.setPostActivate(postActivate);
503: newMethodAnnotationMetadata.setPostConstruct(postConstruct);
504: newMethodAnnotationMetadata.setPreDestroy(preDestroy);
505: newMethodAnnotationMetadata.setPrePassivate(prePassivate);
506: newMethodAnnotationMetadata.setRemove(remove);
507: newMethodAnnotationMetadata.setTimeout(timeout);
508: newMethodAnnotationMetadata
509: .setTransactionAttributeType(transactionAttributeType);
510: newMethodAnnotationMetadata
511: .setUserInterceptors(userInterceptors);
512: newMethodAnnotationMetadata
513: .setGlobalEasyBeansInterceptors(globalEasyBeansInterceptors);
514: return newMethodAnnotationMetadata;
515: }
516:
517: /**
518: * Replace the link to the classannotation metadata.
519: * @param classAnnotationMetadata new object for the link.
520: */
521: public void setClassAnnotationMetadata(
522: final ClassAnnotationMetadata classAnnotationMetadata) {
523: this.classAnnotationMetadata = classAnnotationMetadata;
524: }
525: }
|