org/objectweb/proactive/core/component/type/ProActiveInterfaceTypeImpl.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.type;
00032 
00033 import java.io.Serializable;
00034 import java.lang.reflect.Method;
00035 import java.lang.reflect.ParameterizedType;
00036 
00037 import org.apache.log4j.Logger;
00038 import org.objectweb.fractal.api.Type;
00039 import org.objectweb.fractal.api.type.InterfaceType;
00040 import org.objectweb.proactive.core.ProActiveRuntimeException;
00041 import org.objectweb.proactive.core.util.log.Loggers;
00042 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00043 
00044 
00051 public class ProActiveInterfaceTypeImpl implements ProActiveInterfaceType, Serializable {
00052     protected static Logger logger = ProActiveLogger.getLogger(Loggers.COMPONENTS);
00056     private String name;
00057 
00061     private String signature;
00062     private boolean isClient;
00063     private boolean isOptional;
00064     private String cardinality;
00065 
00069     public ProActiveInterfaceTypeImpl() {
00070         super();
00071     }
00072 
00077     public ProActiveInterfaceTypeImpl(final InterfaceType itfType) {
00078         this.name = itfType.getFcItfName();
00079         this.signature = itfType.getFcItfSignature();
00080         this.isClient = itfType.isFcClientItf();
00081         this.isOptional = itfType.isFcOptionalItf();
00082         if(itfType.isFcCollectionItf()) {
00083             cardinality = ProActiveTypeFactory.COLLECTION_CARDINALITY;
00084         } else {
00085             cardinality = ProActiveTypeFactory.SINGLETON_CARDINALITY;
00086         }
00087     }
00088     
00092     public ProActiveInterfaceTypeImpl(String name, String signature,
00093         boolean isClient, boolean isOptional, String cardinality) {
00094         this.name = name;
00095         this.signature = signature;
00096         this.isClient = isClient;
00097         this.isOptional = isOptional;
00098         this.cardinality = cardinality;
00099         checkMethodsSignatures(signature, cardinality);
00100     }
00101     
00102     
00103     private boolean checkMethodsSignatures(String signature, String cardinality) {
00104         try {
00105         if (ProActiveTypeFactory.MULTICAST_CARDINALITY.equals(cardinality)) {
00106             Class c = Class.forName(signature);
00107             Method[] methods = c.getMethods();
00108             for (Method m : methods) {
00109                 if (!(m.getGenericReturnType() instanceof ParameterizedType) && !(Void.TYPE ==m.getReturnType())) {
00110                     throw new ProActiveRuntimeException("methods of a multicast interface must return parameterized types or void, " +
00111                             "which is not the case for method " + m.toString() + " in interface " + signature);
00112                 }
00113             }
00114         }
00115         } catch (ClassNotFoundException e) {
00116             throw new ProActiveRuntimeException("cannot find interface defined in component interface signature : " + e.getMessage());
00117         }
00118         return true;
00119     }
00120 
00121 
00122 
00123     // -------------------------------------------------------------------------
00124     // Implementation of the InterfaceType interface
00125     // -------------------------------------------------------------------------
00126 
00130     public String getFcItfName() {
00131         return name;
00132     }
00133 
00137     public String getFcItfSignature() {
00138         return signature;
00139     }
00140 
00144     public boolean isFcClientItf() {
00145         return isClient;
00146     }
00147 
00151     public boolean isFcOptionalItf() {
00152         return isOptional;
00153     }
00154 
00159     public boolean isFcSubTypeOf(final Type type) {
00160         throw new RuntimeException("Not yet implemented.");
00161     }
00162 
00163     public String getFcCardinality() {
00164         return cardinality;
00165     }
00166     
00167     public boolean isFcCollective() {
00168         return (ProActiveTypeFactory.GATHER_CARDINALITY.equals(cardinality)
00169                  || (ProActiveTypeFactory.MULTICAST_CARDINALITY.equals(cardinality)));
00170     }
00171 
00172     public boolean isFcGathercastItf() {
00173         return ProActiveTypeFactory.GATHER_CARDINALITY.equals(cardinality);
00174     }
00175 
00176     public boolean isFcMulticastItf() {
00177         return ProActiveTypeFactory.MULTICAST_CARDINALITY.equals(cardinality);
00178     }
00179 
00180     public boolean isFcSingletonItf() {
00181         return ProActiveTypeFactory.SINGLETON_CARDINALITY.equals(cardinality);
00182     }
00183     
00184     /*
00185      * @see org.objectweb.fractal.api.type.InterfaceType#isFcCollectionItf()
00186      */
00187     public boolean isFcCollectionItf() {
00188         return ProActiveTypeFactory.COLLECTION_CARDINALITY.equals(cardinality);
00189     }
00190 
00191 
00192 }

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