001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@objectweb.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: InterfaceAnnotatedHelper.java 266 2006-03-24 12:58:05Z benoitf $
023: * --------------------------------------------------------------------------
024: */package com.bm.ejb3metadata.annotations.helper.bean;
025:
026: import com.bm.ejb3metadata.annotations.exceptions.ResolverException;
027: import com.bm.ejb3metadata.annotations.impl.JLocal;
028: import com.bm.ejb3metadata.annotations.impl.JRemote;
029: import com.bm.ejb3metadata.annotations.metadata.ClassAnnotationMetadata;
030: import com.bm.ejb3metadata.annotations.metadata.EjbJarAnnotationMetadata;
031:
032: /**
033: * Lookup the annotated interfaces of a class and report it to the class
034: * metadata.
035: *
036: * @author Florent Benoit
037: */
038: public final class InterfaceAnnotatedHelper {
039:
040: /**
041: * Helper class, no public constructor.
042: */
043: private InterfaceAnnotatedHelper() {
044: }
045:
046: /**
047: * Gets interface of a bean and report their types to the bean metadata.
048: *
049: * @param sessionBean
050: * Session bean to analyze
051: * @throws ResolverException
052: * if there is a failure in a resolver
053: */
054: public static void resolve(final ClassAnnotationMetadata sessionBean)
055: throws ResolverException {
056: // root metadata
057: EjbJarAnnotationMetadata ejbJarAnnotationMetadata = sessionBean
058: .getEjbJarAnnotationMetadata();
059:
060: // Local and remote interfaces of the bean.
061: JLocal currentLocalInterfaces = sessionBean
062: .getLocalInterfaces();
063: JRemote currentRemoteInterfaces = sessionBean
064: .getRemoteInterfaces();
065:
066: // Get all interfaces of the bean
067: String[] interfaces = sessionBean.getInterfaces();
068: for (String itf : interfaces) {
069: ClassAnnotationMetadata itfAnnotationMetadata = ejbJarAnnotationMetadata
070: .getClassAnnotationMetadata(itf);
071:
072: // Interface was analyzed, try to see the type of the interface
073: if (itfAnnotationMetadata != null) {
074: // Report type of interface in the bean
075: JLocal jLocal = itfAnnotationMetadata
076: .getLocalInterfaces();
077: if (jLocal != null) {
078: if (currentLocalInterfaces == null) {
079: currentLocalInterfaces = new JLocal();
080: sessionBean
081: .setLocalInterfaces(currentLocalInterfaces);
082: }
083: String itfName = itfAnnotationMetadata
084: .getClassName();
085: if (!currentLocalInterfaces.getInterfaces()
086: .contains(itfName)) {
087: currentLocalInterfaces.addInterface(itfName);
088: }
089: }
090:
091: // Report type of interface in the bean
092: JRemote jRemote = itfAnnotationMetadata
093: .getRemoteInterfaces();
094: if (jRemote != null) {
095: if (currentRemoteInterfaces == null) {
096: currentRemoteInterfaces = new JRemote();
097: sessionBean
098: .setRemoteInterfaces(currentRemoteInterfaces);
099: }
100: String itfName = itfAnnotationMetadata
101: .getClassName();
102: if (!currentRemoteInterfaces.getInterfaces()
103: .contains(itfName)) {
104: currentRemoteInterfaces.addInterface(itfName);
105: }
106: }
107: }
108: }
109: }
110:
111: }
|