00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030  
00031 package org.objectweb.proactive.core.component.gen;
00032 
00033 import java.util.ArrayList;
00034 import java.util.List;
00035 
00036 import javassist.ClassPool;
00037 import javassist.CtClass;
00038 import javassist.NotFoundException;
00039 
00040 import org.apache.log4j.Logger;
00041 import org.objectweb.fractal.api.Component;
00042 import org.objectweb.fractal.api.Interface;
00043 import org.objectweb.proactive.core.component.ProActiveInterface;
00044 import org.objectweb.proactive.core.component.exceptions.InterfaceGenerationFailedException;
00045 import org.objectweb.proactive.core.component.type.ProActiveInterfaceType;
00046 import org.objectweb.proactive.core.util.log.Loggers;
00047 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00048 
00055 public abstract class AbstractInterfaceClassGenerator {
00056     protected static final transient Logger logger = ProActiveLogger.getLogger(Loggers.COMPONENTS_GEN_ITFS);
00057     protected static ClassPool pool = ClassPool.getDefault();
00058 
00059 
00060     protected Class loadClass(final String className)
00061         throws ClassNotFoundException {
00062         
00063         return Thread.currentThread().getContextClassLoader().loadClass(className);
00064     }
00065 
00066     public ProActiveInterface generateControllerInterface(
00067         final String controllerInterfaceName, Component owner,
00068         ProActiveInterfaceType interfaceType) throws InterfaceGenerationFailedException {
00069         return generateInterface(controllerInterfaceName, owner, interfaceType,
00070             false, false);
00071     }
00072 
00073     public ProActiveInterface generateFunctionalInterface(
00074         final String functionalInterfaceName, Component owner,
00075         ProActiveInterfaceType interfaceType) throws InterfaceGenerationFailedException {
00076         return generateInterface(functionalInterfaceName, owner, interfaceType,
00077             false, true);
00078     }
00079 
00080     public abstract ProActiveInterface generateInterface(
00081         final String interfaceName, Component owner,
00082         ProActiveInterfaceType interfaceType, boolean isInternal,
00083         boolean isFunctionalInterface)
00084         throws InterfaceGenerationFailedException;
00085 
00091     public static void addSuperInterfaces(List interfaces)
00092         throws NotFoundException {
00093         for (int i = 0; i < interfaces.size(); i++) {
00094             CtClass[] super_itfs_table = ((CtClass) interfaces.get(i)).getInterfaces();
00095             List super_itfs = new ArrayList(super_itfs_table.length); 
00096             for (int j = 0; j < super_itfs_table.length; j++) {
00097                 super_itfs.add(super_itfs_table[j]);
00098             }
00099             addSuperInterfaces(super_itfs);
00100             CtClass super_itf;
00101             for (int j = 0; j < super_itfs.size(); j++) {
00102                 if (!interfaces.contains(super_itfs.get(j))) {
00103                     super_itf = (CtClass) super_itfs.get(j);
00104                     if (!(super_itf.equals(pool.get(
00105                                     ProActiveInterface.class.getName())) ||
00106                             super_itf.equals(pool.get(Interface.class.getName())))) {
00107                         interfaces.add(super_itfs.get(j));
00108                     }
00109                 }
00110             }
00111         }
00112     }
00113 }