org/objectweb/proactive/core/component/adl/bindings/ProActiveTypeBindingLoader.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.adl.bindings;
00032 
00033 import java.lang.reflect.Method;
00034 import java.util.HashSet;
00035 import java.util.Map;
00036 import java.util.Set;
00037 
00038 import org.objectweb.fractal.adl.ADLException;
00039 import org.objectweb.fractal.adl.Node;
00040 import org.objectweb.fractal.adl.bindings.Binding;
00041 import org.objectweb.fractal.adl.bindings.BindingContainer;
00042 import org.objectweb.fractal.adl.bindings.TypeBindingLoader;
00043 import org.objectweb.fractal.adl.interfaces.Interface;
00044 import org.objectweb.fractal.adl.types.TypeInterface;
00045 import org.objectweb.proactive.core.component.adl.types.ProActiveTypeInterface;
00046 
00050 public class ProActiveTypeBindingLoader extends TypeBindingLoader {
00051 
00052     protected void checkNode(final Object node, final Map context) throws ADLException {
00053         try {
00054             super.checkNode(node, context);
00055         } catch (ADLException e) {
00056             Binding[] bindings = ((BindingContainer) node).getBindings();
00057             Set fromItfs = new HashSet();
00058             for (int i = 0; i < bindings.length; i++) {
00059                 if (fromItfs.contains(bindings[i].getFrom())) {
00060                     // ignore (allows multicast bindings
00061                 }
00062 
00063             }
00064         }
00065     }
00066 
00067     protected void checkBinding(final Binding binding,
00068                                 final Interface fromItf,
00069                                 final Interface toItf,
00070                                 final Map context) throws ADLException {
00071 
00072         try {
00073             super.checkBinding(binding, fromItf, toItf, context);
00074         } catch (ADLException e) {
00075             // check if signatures are incompatible
00076             TypeInterface cItf = (TypeInterface) fromItf;
00077             TypeInterface sItf = (TypeInterface) toItf;
00078 
00079             try {
00080                 ClassLoader cl = getClassLoader(context);
00081                 Class clientSideItfClass = cl.loadClass(cItf.getSignature());
00082                 Class serverSideItfClass = cl.loadClass(sItf.getSignature());
00083 //              Class clientSideItfClass = Class.forName(cItf.getSignature());
00084 //              Class serverSideItfClass = Class.forName(sItf.getSignature());
00085                 if (!clientSideItfClass.isAssignableFrom(serverSideItfClass)) {
00086                     // check if multicast interface
00087                     if (ProActiveTypeInterface.MULTICAST_CARDINALITY.equals(cItf.getCardinality())) {
00088 
00089                         Method[] clientSideItfMethods = clientSideItfClass.getMethods();
00090                         Method[] serverSideItfMethods = serverSideItfClass.getMethods();
00091 
00092                         if (clientSideItfMethods.length != serverSideItfMethods.length) {
00093                             throw new ADLException("incompatible binding between multicast client interface " + cItf
00094                                     .getName() + " (" + cItf.getSignature()
00095                                     + ")  and server interface " + sItf.getName() + " (" + sItf
00096                                     .getSignature() + ") : there is not the same number of methods (including those inherited) " +
00097                                     "in both interfaces !", (Node) binding);
00098                         }
00099 
00100 //                        Map<Method, Method> matchingMethodsForThisItf = new HashMap<Method, Method>(clientSideItfMethods.length);
00101 //
00102 //                        for (Method method : clientSideItfMethods) {
00103 //                            try {
00106 //                                matchingMethodsForThisItf
00107 //                                .put(method, MulticastBindingChecker.searchMatchingMethod(method, serverSideItfMethods, ProActiveTypeInterface.GATHER_CARDINALITY.equals(sItf.getCardinality())));
00108 //                            } catch (ParameterDispatchException e1) {
00109 //                                throw new ADLException("incompatible binding between multicast client interface " + cItf
00110 //                                        .getName() + " (" + cItf.getSignature()
00111 //                                        + ")  and server interface " + sItf.getName() + " (" + sItf
00112 //                                        .getSignature() + ") : incompatible dispatch " +
00113 //                                        e1.getMessage(), (Node) binding);
00114 //                            } catch (NoSuchMethodException e1) {
00115 //                                throw new ADLException("incompatible binding between multicast client interface " + cItf
00116 //                                        .getName() + " (" + cItf.getSignature()
00117 //                                        + ")  and server interface " + sItf.getName() + " (" + sItf
00118 //                                        .getSignature() + ") : cannot find corresponding method " +
00119 //                                        e1.getMessage(), (Node) binding);
00120 //                            }
00121 //                        }
00122                     }
00123                 }
00124 
00125             } catch (ClassNotFoundException e1) {
00126                 throw new ADLException(
00127                         "incompatible binding between multicast client interface " + cItf
00128                                 .getName() + " (" + cItf.getSignature()
00129                                 + ")  and server interface " + sItf.getName() + " (" + sItf
00130                                 .getSignature() + ") : cannot find interface " +
00131                                 e1.getMessage(), (Node) binding);
00132             }
00133         }
00134     }
00135 }
00136 

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