1 23 24 package org.objectweb.fractal.adl.bindings; 25 26 import org.objectweb.fractal.adl.bindings.BindingLoader; 27 import org.objectweb.fractal.adl.interfaces.Interface; 28 import org.objectweb.fractal.adl.ADLException; 29 import org.objectweb.fractal.adl.Node; 30 import org.objectweb.fractal.adl.types.TypeInterface; 31 32 import java.util.Iterator ; 33 import java.util.Map ; 34 35 42 43 public class TypeBindingLoader extends BindingLoader { 44 45 49 void checkBinding ( 50 final Binding binding, 51 final Interface fromItf, 52 final Interface toItf, 53 final Map context) throws ADLException 54 { 55 if (fromItf instanceof TypeInterface && toItf instanceof TypeInterface) { 56 TypeInterface cItf = (TypeInterface)fromItf; 57 TypeInterface sItf = (TypeInterface)toItf; 58 if (binding.getFrom().startsWith("this.")) { 59 if (!TypeInterface.SERVER_ROLE.equals(cItf.getRole())) { 60 throw new ADLException( 61 "Invalid binding: 'from' interface is not an internal client interface", (Node)binding); 62 } 63 } else { 64 if (!TypeInterface.CLIENT_ROLE.equals(cItf.getRole())) { 65 throw new ADLException( 66 "Invalid binding: 'from' interface is not a client interface", (Node)binding); 67 } 68 } 69 if (binding.getTo().startsWith("this.")) { 70 if (!TypeInterface.CLIENT_ROLE.equals(sItf.getRole())) { 71 throw new ADLException( 72 "Invalid binding: 'to' interface is not an internal server interface", (Node)binding); 73 } 74 } else { 75 if (!TypeInterface.SERVER_ROLE.equals(sItf.getRole())) { 76 throw new ADLException( 77 "Invalid binding: 'to' interface is not a server interface", (Node)binding); 78 } 79 } 80 81 boolean cIsMandatory = true; 82 if (TypeInterface.OPTIONAL_CONTINGENCY.equals(cItf.getContingency())) { 83 cIsMandatory = false; 84 } 85 boolean sIsMandatory = true; 86 if (TypeInterface.OPTIONAL_CONTINGENCY.equals(sItf.getContingency())) { 87 sIsMandatory = false; 88 } 89 if (cIsMandatory && !sIsMandatory) { 90 throw new ADLException( 91 "Invalid binding: binding from mandatory to optional interface", (Node)binding); 92 } 93 94 try { 95 ClassLoader cl = getClassLoader(context); 96 Class cClass = cl.loadClass(cItf.getSignature()); 97 Class sClass = cl.loadClass(sItf.getSignature()); 98 if (!cClass.isAssignableFrom(sClass)) { 99 throw new ADLException( 100 "Invalid binding: incompatible signatures", (Node)binding); 101 } 102 } catch (ClassNotFoundException e) { 103 } 104 } 105 } 106 107 Interface getInterface (final String name, final Map itfs) { 108 Interface itf = super.getInterface(name, itfs); 109 if (itf == null) { 110 Iterator i = itfs.keySet().iterator(); 111 while (i.hasNext()) { 112 String n = (String )i.next(); 113 itf = (Interface)itfs.get(n); 114 if (itf instanceof TypeInterface) { 115 TypeInterface typeItf = (TypeInterface)itf; 116 String cardinality = typeItf.getCardinality(); 117 if (TypeInterface.COLLECTION_CARDINALITY.equals(cardinality)) { 118 if (name.startsWith(n)) { 119 return itf; 120 } 121 } 122 } 123 } 124 return null; 125 } else { 126 return itf; 127 } 128 } 129 } 130 | Popular Tags |