KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > deployment > annotations > helper > bean > session > SessionBusinessInterfaceFinder


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: SessionBusinessInterfaceFinder.java 937 2006-07-26 09:03:07Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.helper.bean.session;
27
28 import org.objectweb.easybeans.deployment.annotations.impl.JLocal;
29 import org.objectweb.easybeans.deployment.annotations.impl.JRemote;
30 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
31
32 /**
33  * This class finds the business interface if there are no business interfaces
34  * specified.
35  * @author Florent Benoit
36  */

37 public final class SessionBusinessInterfaceFinder {
38
39     /**
40      * Helper class, no public constructor.
41      */

42     private SessionBusinessInterfaceFinder() {
43     }
44
45     /**
46      * Finds business interface in a session bean.
47      * @see <a HREF="http://www.jcp.org/en/jsr/detail?id=220">EJB 3.0 Spec ?4.6.6</a>
48      * @param sessionBean Session bean to analyze
49      */

50     public static void resolve(final ClassAnnotationMetadata sessionBean) {
51
52         JLocal jLocal = sessionBean.getLocalInterfaces();
53         JRemote jRemote = sessionBean.getRemoteInterfaces();
54
55         // No business interface or empty annotation (@Remote or @Local)
56
if ((jLocal == null && jRemote == null) || (jLocal == null && jRemote != null && jRemote.getInterfaces().isEmpty())
57                 ||(jRemote == null && jLocal != null && jLocal.getInterfaces().isEmpty())) {
58
59             // The following interfaces are excluded when determining whether
60
// the bean class has
61
// more than one interface: java.io.Serializable;
62
// java.io.Externalizable;
63
// any of the interfaces defined by the javax.ejb package.
64
String JavaDoc[] interfaces = sessionBean.getInterfaces();
65             int numberItfFound = 0;
66             String JavaDoc itfFound = null;
67             for (String JavaDoc itf : interfaces) {
68                 if (!itf.equals(java.io.Serializable JavaDoc.class.getName().replace(".", "/"))
69                         && !itf.equals(java.io.Externalizable JavaDoc.class.getName().replace(".", "/"))
70                         && !itf.startsWith("javax/ejb")) {
71                     itfFound = itf;
72                     numberItfFound++;
73                 }
74             }
75
76             if (numberItfFound == 0) {
77                 throw new IllegalStateException JavaDoc("No business interface found on class '" + sessionBean.getClassName() + "'.");
78             }
79
80
81             if (numberItfFound > 1) {
82                 throw new IllegalStateException JavaDoc("More than 1 itf on class '" + sessionBean.getClassName() + "'.");
83             }
84
85             // If bean class implements a single interface, that interface is
86
// assumed to be the business
87
// interface of the bean. This business interface will be a local
88
// interface unless the
89
// interface is designated as a remote business interface by use of
90
// the Remote annotation
91
// on the bean class or interface or by means of the deployment
92
// descriptor.
93

94             // Build a local interface if no @Remote annotation, else add interface in the existing object
95
if (jRemote == null) {
96                 JLocal addedJLocal = new JLocal();
97                 addedJLocal.addInterface(itfFound);
98                 sessionBean.setLocalInterfaces(addedJLocal);
99             } else {
100                 jRemote.addInterface(itfFound);
101                 sessionBean.setRemoteInterfaces(jRemote);
102             }
103
104
105         }
106     }
107 }
108
Popular Tags