1 23 24 package org.objectweb.fractal.julia.control.content; 25 26 import org.objectweb.fractal.api.Component; 27 import org.objectweb.fractal.api.Interface; 28 import org.objectweb.fractal.api.NoSuchInterfaceException; 29 import org.objectweb.fractal.api.control.BindingController; 30 import org.objectweb.fractal.api.control.ContentController; 31 import org.objectweb.fractal.api.control.IllegalBindingException; 32 import org.objectweb.fractal.api.control.IllegalContentException; 33 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 34 import org.objectweb.fractal.api.control.SuperController; 35 import org.objectweb.fractal.api.type.InterfaceType; 36 37 import org.objectweb.fractal.julia.control.binding.ChainedIllegalBindingException; 38 import org.objectweb.fractal.julia.control.binding.Util; 39 40 import java.util.List ; 41 42 55 56 public abstract class BindingContentMixin implements ContentController { 57 58 62 private BindingContentMixin () { 63 } 64 65 69 80 81 public void removeFcSubComponent (final Component subComponent) 82 throws IllegalContentException, IllegalLifeCycleException 83 { 84 try { 85 checkFcRemoveSubComponent(subComponent); 86 } catch (IllegalBindingException e) { 87 throw new ChainedIllegalContentException( 88 e, 89 _this_weaveableOptC, 90 subComponent, 91 "Would create non local bindings"); 92 } 93 _super_removeFcSubComponent(subComponent); 94 } 95 96 105 106 public void checkFcRemoveSubComponent (final Component subComponent) 107 throws IllegalBindingException 108 { 109 Component parent; 110 try { 111 parent = (Component)_this_weaveableOptC.getFcInterface("component"); 112 if (parent == null) { 113 return; 114 } 115 } catch (NoSuchInterfaceException e) { 116 return; 117 } 118 BindingController bc; 119 try { 120 bc = (BindingController)subComponent.getFcInterface("binding-controller"); 121 } catch (NoSuchInterfaceException e) { 122 bc = null; 123 } 124 Object [] itfs = subComponent.getFcInterfaces(); 125 for (int i = 0; i < itfs.length; ++i) { 126 Interface itf; 127 InterfaceType itfType; 128 try { 129 itf = (Interface)itfs[i]; 130 itfType = (InterfaceType)itf.getFcItfType(); 131 } catch (ClassCastException e) { 132 continue; 133 } 134 if (itfType.isFcClientItf()) { 135 if (bc != null) { 136 Interface sItf; 137 try { 138 sItf = (Interface)bc.lookupFc(itf.getFcItfName()); 139 } catch (NoSuchInterfaceException e) { 140 continue; 141 } catch (ClassCastException e) { 142 continue; 143 } 144 if (sItf != null) { 145 checkFcLocalBinding(itf, parent, sItf, null); 146 } 147 } 148 } else { 149 Object [] potentialClients; 150 try { 151 potentialClients = Util.getFcPotentialClientsOf(itf).toArray(); 152 } catch (Exception e) { 153 continue; 154 } 155 for (int j = 0; j < potentialClients.length; ++j) { 156 Component c = (Component)potentialClients[j]; 157 List clientItfs; 158 try { 159 clientItfs = Util.getFcClientItfsBoundTo(c, itf); 160 } catch (Exception e) { 161 continue; 162 } 163 if (clientItfs.size() > 0) { 164 checkFcLocalBinding((Interface)clientItfs.get(0), null, itf, parent); 165 } 166 } 167 } 168 } 169 } 170 171 185 186 private void checkFcLocalBinding ( 187 final Interface cItf, 188 final Component cId, 189 final Interface sItf, 190 final Component sId) throws IllegalBindingException 191 { 192 Component client = cItf.getFcItfOwner(); 193 Component server = sItf.getFcItfOwner(); 194 if (client.equals(server)) { 195 return; 196 } 197 SuperController cSc = null; 198 SuperController sSc = null; 199 try { 200 cSc = (SuperController)client.getFcInterface("super-controller"); 201 } catch (NoSuchInterfaceException ignored) { 202 } 203 try { 204 sSc = (SuperController)server.getFcInterface("super-controller"); 205 } catch (NoSuchInterfaceException ignored) { 206 } 207 if (cItf.isFcInternalItf()) { 208 if (cSc != null) { 210 Component[] sP = sSc.getFcSuperComponents(); 211 for (int i = 0; i < sP.length; ++i) { 212 Component p = sP[i]; 213 if (sId == null || !p.equals(sId)) { 214 if (p.equals(client)) { 215 return; 216 } 217 } 218 } 219 } else { 220 return; 221 } 222 } else { 223 if (sItf.isFcInternalItf()) { 224 if (cSc != null) { 226 Component[] cP = cSc.getFcSuperComponents(); 227 for (int i = 0; i < cP.length; ++i) { 228 Component p = cP[i]; 229 if (cId == null || !p.equals(cId)) { 230 if (p.equals(server)) { 231 return; 232 } 233 } 234 } 235 } else { 236 return; 237 } 238 } else { 239 if (cSc != null && sSc != null) { 241 Component[] cP = cSc.getFcSuperComponents(); 242 Component[] sP = sSc.getFcSuperComponents(); 243 for (int i = 0; i < cP.length; ++i) { 244 Component p = cP[i]; 245 if (cId == null || !p.equals(cId)) { 246 for (int j = 0; j < sP.length; ++j) { 247 Component q = sP[j]; 248 if (sId == null || !q.equals(sId)) { 249 if (p.equals(q)) { 250 return; 251 } 252 } 253 } 254 } 255 } 256 } else { 257 return; 258 } 259 } 260 } 261 throw new ChainedIllegalBindingException( 262 null, 263 _this_weaveableOptC, 264 sId, 265 cItf.getFcItfName(), 266 sItf.getFcItfName(), 267 "Not a local binding"); 268 } 269 270 274 279 280 public Component _this_weaveableOptC; 281 282 293 294 public abstract void _super_removeFcSubComponent (Component subComponent) 295 throws IllegalContentException, IllegalLifeCycleException; 296 } 297 | Popular Tags |