01: /**
02: * EasyBeans
03: * Copyright (C) 2007 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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: TimedObjectInterface.java 2057 2007-11-21 15:35:32Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.deployment.annotations.helper.bean;
25:
26: import static org.ow2.easybeans.asm.Opcodes.ACC_PUBLIC;
27: import static org.ow2.easybeans.deployment.annotations.helper.ResolverHelper.getAllInterfacesFromClass;
28: import static org.ow2.easybeans.deployment.annotations.helper.ResolverHelper.getMethod;
29:
30: import java.util.List;
31:
32: import org.ow2.easybeans.deployment.annotations.JMethod;
33: import org.ow2.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
34: import org.ow2.easybeans.deployment.annotations.metadata.MethodAnnotationMetadata;
35:
36: /**
37: * This class analyze interfaces of the given bean. If the session bean
38: * implements javax.ejb.TimedObject interface, the ejbTimeout method is added as Timer method.
39: * @author Florent Benoit
40: */
41: public final class TimedObjectInterface {
42:
43: /**
44: * TimedObject interface.
45: */
46: private static final String TIMEDOBJECT_INTERFACE = "javax/ejb/TimedObject";
47:
48: /**
49: * ejbTimeout() method.
50: */
51: private static final JMethod EJBTIMEOUT_METHOD = new JMethod(
52: ACC_PUBLIC, "ejbTimeout", "(Ljavax/ejb/Timer;)V", null,
53: null);
54:
55: /**
56: * Helper class, no public constructor.
57: */
58: private TimedObjectInterface() {
59: }
60:
61: /**
62: * Try to see if the bean is implementing javax.ejb.TimedObject interface.
63: * @param bean the given bean to analyze
64: */
65: public static void resolve(final ClassAnnotationMetadata bean) {
66: // Make a list of interfaces
67: List<String> allInterfaces = getAllInterfacesFromClass(bean);
68:
69: // if TIMEDOBJECT_INTERFACE is contained in the list, add some metadata
70: if (allInterfaces.contains(TIMEDOBJECT_INTERFACE)) {
71:
72: // Flag the method as the timeout method
73: MethodAnnotationMetadata timeoutMethod = getMethod(bean,
74: EJBTIMEOUT_METHOD, true, TIMEDOBJECT_INTERFACE);
75: timeoutMethod.setTimeout(true);
76: }
77:
78: }
79:
80: }
|