org/objectweb/proactive/core/component/gen/AbstractInterfaceClassGenerator.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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         // try to fetch the class from the default class loader
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); // resizable list
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 }

Generated on Mon Jan 22 15:16:06 2007 for ProActive by  doxygen 1.5.1