KickJava   Java API By Example, From Geeks To Geeks.

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


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: InterfaceAnnotatedHelper.java 266 2006-03-24 12:58:05Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.helper.bean;
27
28 import org.objectweb.easybeans.deployment.annotations.exceptions.ResolverException;
29 import org.objectweb.easybeans.deployment.annotations.impl.JLocal;
30 import org.objectweb.easybeans.deployment.annotations.impl.JRemote;
31 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
32 import org.objectweb.easybeans.deployment.annotations.metadata.EjbJarAnnotationMetadata;
33
34 /**
35  * Lookup the annotated interfaces of a class and report it to the class
36  * metadata.
37  * @author Florent Benoit
38  */

39 public final class InterfaceAnnotatedHelper {
40
41     /**
42      * Helper class, no public constructor.
43      */

44     private InterfaceAnnotatedHelper() {
45     }
46
47     /**
48      * Gets interface of a bean and report their types to the bean metadata.
49      * @param sessionBean Session bean to analyze
50      * @throws ResolverException if there is a failure in a resolver
51      */

52     public static void resolve(final ClassAnnotationMetadata sessionBean) throws ResolverException {
53         // root metadata
54
EjbJarAnnotationMetadata ejbJarAnnotationMetadata = sessionBean.getEjbJarAnnotationMetadata();
55
56         // Local and remote interfaces of the bean.
57
JLocal currentLocalInterfaces = sessionBean.getLocalInterfaces();
58         JRemote currentRemoteInterfaces = sessionBean.getRemoteInterfaces();
59
60         // Get all interfaces of the bean
61
String JavaDoc[] interfaces = sessionBean.getInterfaces();
62         for (String JavaDoc itf : interfaces) {
63             ClassAnnotationMetadata itfAnnotationMetadata = ejbJarAnnotationMetadata.getClassAnnotationMetadata(itf);
64
65             // Interface was analyzed, try to see the type of the interface
66
if (itfAnnotationMetadata != null) {
67                 // Report type of interface in the bean
68
JLocal jLocal = itfAnnotationMetadata.getLocalInterfaces();
69                 if (jLocal != null) {
70                     if (currentLocalInterfaces == null) {
71                         currentLocalInterfaces = new JLocal();
72                         sessionBean.setLocalInterfaces(currentLocalInterfaces);
73                     }
74                     String JavaDoc itfName = itfAnnotationMetadata.getClassName();
75                     if (!currentLocalInterfaces.getInterfaces().contains(itfName)) {
76                         currentLocalInterfaces.addInterface(itfName);
77                     }
78                 }
79
80                 // Report type of interface in the bean
81
JRemote jRemote = itfAnnotationMetadata.getRemoteInterfaces();
82                 if (jRemote != null) {
83                     if (currentRemoteInterfaces == null) {
84                         currentRemoteInterfaces = new JRemote();
85                         sessionBean.setRemoteInterfaces(currentRemoteInterfaces);
86                     }
87                     String JavaDoc itfName = itfAnnotationMetadata.getClassName();
88                     if (!currentRemoteInterfaces.getInterfaces().contains(itfName)) {
89                         currentRemoteInterfaces.addInterface(itfName);
90                     }
91                 }
92             }
93         }
94     }
95
96 }
97
Popular Tags