org/objectweb/proactive/core/component/Utils.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;
00032 
00033 import java.lang.reflect.Method;
00034 import java.util.Arrays;
00035 import java.util.Iterator;
00036 
00037 import org.objectweb.fractal.api.Component;
00038 import org.objectweb.fractal.api.Interface;
00039 import org.objectweb.fractal.api.NoSuchInterfaceException;
00040 import org.objectweb.fractal.api.type.ComponentType;
00041 import org.objectweb.fractal.api.type.InterfaceType;
00042 import org.objectweb.proactive.core.component.type.ProActiveInterfaceType;
00043 import org.objectweb.proactive.core.component.type.ProActiveTypeFactory;
00044 
00051 public class Utils {
00052 
00057     public static String pertainsToACollectionInterface(String clientItfName,
00058         Component owner) {
00059         InterfaceType[] itfTypes = (((ComponentType) owner.getFcType()).getFcInterfaceTypes());
00060         for (int i = 0; i < itfTypes.length; i++) {
00061             if (itfTypes[i].isFcCollectionItf()) {
00062                 if (clientItfName.startsWith(itfTypes[i].getFcItfName())) {
00063                     return itfTypes[i].getFcItfName();
00064                 }
00065             }
00066         }
00067         return null;
00068     }
00069 
00070     public static InterfaceType getItfType(String itfName, Component owner) throws NoSuchInterfaceException {
00071         InterfaceType[] itfTypes = (((ComponentType) owner.getFcType()).getFcInterfaceTypes());
00072         for (int i = 0; i < itfTypes.length; i++) {
00073             if (itfTypes[i].isFcCollectionItf()) {
00074                 if (itfName.startsWith(itfTypes[i].getFcItfName()) &&
00075                         !itfName.equals(itfTypes[i].getFcItfName())) {
00076                     return itfTypes[i];
00077                 }
00078             } else {
00079                 if (itfName.equals(itfTypes[i].getFcItfName())) {
00080                     return itfTypes[i];
00081                 }
00082             }
00083         }
00084         return null;
00085     }
00086 
00087     public static boolean hasSingleCardinality(String itfName, Component owner) {
00088         Iterator it = Arrays.asList(owner.getFcInterfaces()).iterator();
00089         while (it.hasNext()) {
00090             ProActiveInterfaceType itfType = ((ProActiveInterfaceType) ((Interface) it.next()).getFcItfType());
00091             if (itfType.getFcItfName().equals(itfName) &&
00092                     itfType.isFcSingletonItf()) {
00093                 return true;
00094             }
00095         }
00096         return false;
00097     }
00098 
00099     public static boolean isMulticastItf(String itfName, Component owner) {
00100         try {
00101             return ProActiveTypeFactory.MULTICAST_CARDINALITY.equals(getCardinality(
00102                     itfName, owner));
00103         } catch (NoSuchInterfaceException e) {
00104             return false;
00105         }
00106     }
00107 
00108     public static boolean isGathercastItf(Interface itf) {
00109         if (!(itf instanceof ProActiveInterface)) {
00110             return false;
00111         }
00112         return ((ProActiveInterfaceType) itf.getFcItfType()).isFcGathercastItf();
00113     }
00114 
00115     public static boolean isSingletonItf(String itfName, Component owner) {
00116         try {
00117             return ProActiveTypeFactory.SINGLETON_CARDINALITY.equals(getCardinality(
00118                     itfName, owner));
00119         } catch (NoSuchInterfaceException e) {
00120             return false;
00121         }
00122     }
00123 
00124     public static String getCardinality(String itfName, Component owner)
00125         throws NoSuchInterfaceException {
00126         InterfaceType[] itfTypes = ((ComponentType) owner.getFcType()).getFcInterfaceTypes();
00127 
00128         for (InterfaceType type : itfTypes) {
00129             if (type.getFcItfName().equals(itfName)) {
00130                 return ((ProActiveInterfaceType) type).getFcCardinality();
00131             }
00132         }
00133         throw new NoSuchInterfaceException(itfName);
00134     }
00135 
00136     public static String getMethodSignatureWithoutReturnTypeAndModifiers(
00137         Method m) {
00138         String result = m.toString();
00139         result = result.substring(result.indexOf(m.getName()));
00140         return result;
00141     }
00142 
00143 }

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