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