Clover coverage report -
Coverage timestamp: Thu Jun 22 2006 14:24:50 CEST
file stats: LOC: 150   Methods: 3
NCLOC: 77   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InheritanceInterfacesHelper.java 38.5% 64.1% 66.7% 54.4%
coverage coverage
 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: InheritanceInterfacesHelper.java 268 2006-03-24 15:09:48Z benoitf $
 23    * --------------------------------------------------------------------------
 24    */
 25   
 26    package org.objectweb.easybeans.deployment.annotations.helper.bean;
 27   
 28    import java.util.ArrayList;
 29    import java.util.List;
 30   
 31    import org.objectweb.easybeans.deployment.annotations.exceptions.ResolverException;
 32    import org.objectweb.easybeans.deployment.annotations.impl.JLocal;
 33    import org.objectweb.easybeans.deployment.annotations.impl.JRemote;
 34    import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
 35    import org.objectweb.easybeans.deployment.annotations.metadata.EjbJarAnnotationMetadata;
 36   
 37    /**
 38    * Analyze classes and if there are super classes, set all super interfaces to
 39    * the current class.
 40    * @author Florent Benoit
 41    */
 42    public final class InheritanceInterfacesHelper {
 43   
 44    /**
 45    * Defines java.lang.Object class.
 46    */
 47    public static final String JAVA_LANG_OBJECT = "java/lang/Object";
 48   
 49    /**
 50    * Helper class, no public constructor.
 51    */
 52  0 private InheritanceInterfacesHelper() {
 53   
 54    }
 55   
 56    /**
 57    * Found all method meta data of the super class and adds them to the bean's class.
 58    * Delegates to loop method.
 59    * @param classAnnotationMetadata bean' class to analyze.
 60    * @throws ResolverException if the super class in not in the given ejb-jar
 61    */
 62  31 public static void resolve(final ClassAnnotationMetadata classAnnotationMetadata) throws ResolverException {
 63  31 loop(classAnnotationMetadata, classAnnotationMetadata);
 64   
 65    }
 66   
 67    /**
 68    * Found all method meta data of the super class and adds them to the bean's class.
 69    * @param beanClassAnnotationMetadata class where to report interfaces
 70    * @param visitingClassAnnotationMetadata class to analyze
 71    * @throws ResolverException if the super class in not in the given ejb-jar
 72    */
 73  37 public static void loop(final ClassAnnotationMetadata beanClassAnnotationMetadata,
 74    final ClassAnnotationMetadata visitingClassAnnotationMetadata) throws ResolverException {
 75  37 String superClass = visitingClassAnnotationMetadata.getSuperName();
 76  37 if (superClass != null) {
 77    // try to see if it was analyzed (and not java.lang.Object)
 78  37 if (!superClass.equals(JAVA_LANG_OBJECT)) {
 79  6 EjbJarAnnotationMetadata ejbJarAnnotationMetadata = beanClassAnnotationMetadata
 80    .getEjbJarAnnotationMetadata();
 81  6 ClassAnnotationMetadata superMetadata = ejbJarAnnotationMetadata.getClassAnnotationMetadata(superClass);
 82   
 83  6 if (superMetadata == null) {
 84  0 throw new IllegalStateException("No super class named '" + superClass
 85    + "' was analyzed. But it is referenced from '" + visitingClassAnnotationMetadata.getClassName()
 86    + "'.");
 87    }
 88   
 89    // Add in a new list the existing interfaces
 90  6 List<String> newInterfacesLst = new ArrayList<String>();
 91  6 String[] currentInterfaces = beanClassAnnotationMetadata.getInterfaces();
 92  6 if (currentInterfaces != null) {
 93  6 for (String itf : currentInterfaces) {
 94  6 newInterfacesLst.add(itf);
 95    }
 96    }
 97   
 98    // Add the interfaces of the super class only if there aren't
 99    // yet present
 100  6 String[] superInterfaces = superMetadata.getInterfaces();
 101  6 if (superInterfaces != null) {
 102  6 for (String itf : superInterfaces) {
 103  6 if (!newInterfacesLst.contains(itf)) {
 104  0 newInterfacesLst.add(itf);
 105    }
 106    }
 107    }
 108   
 109    // Set the updated list.
 110  6 beanClassAnnotationMetadata.setInterfaces(newInterfacesLst.toArray(new String[newInterfacesLst.size()]));
 111   
 112    // The local and remote interfaces need to be reported from the superclass to the current class.
 113    // Start with the local interfaces.
 114  6 JLocal currentLocalInterfaces = beanClassAnnotationMetadata.getLocalInterfaces();
 115  6 JLocal superLocalInterfaces = superMetadata.getLocalInterfaces();
 116  6 if (superLocalInterfaces != null) {
 117  0 if (currentLocalInterfaces == null) {
 118  0 currentLocalInterfaces = new JLocal();
 119  0 beanClassAnnotationMetadata.setLocalInterfaces(currentLocalInterfaces);
 120    }
 121  0 for (String itf : superLocalInterfaces.getInterfaces()) {
 122  0 if (!currentLocalInterfaces.getInterfaces().contains(itf)) {
 123  0 currentLocalInterfaces.addInterface(itf);
 124    }
 125    }
 126    }
 127   
 128    // And then, with the remote interfaces
 129  6 JRemote currentRemoteInterfaces = beanClassAnnotationMetadata.getRemoteInterfaces();
 130  6 JRemote superRemoteInterfaces = superMetadata.getRemoteInterfaces();
 131  6 if (superRemoteInterfaces != null) {
 132  0 if (currentRemoteInterfaces == null) {
 133  0 currentRemoteInterfaces = new JRemote();
 134  0 beanClassAnnotationMetadata.setRemoteInterfaces(currentRemoteInterfaces);
 135    }
 136  0 for (String itf : superRemoteInterfaces.getInterfaces()) {
 137  0 if (!currentRemoteInterfaces.getInterfaces().contains(itf)) {
 138  0 currentRemoteInterfaces.addInterface(itf);
 139    }
 140    }
 141    }
 142   
 143    // Loop again until java.lang.Object super class is found
 144  6 if (!superMetadata.getClassName().equals(JAVA_LANG_OBJECT)) {
 145  6 loop(beanClassAnnotationMetadata, superMetadata);
 146    }
 147    }
 148    }
 149    }
 150    }