1 23 24 package org.objectweb.fractal.julia.control.binding; 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.IllegalBindingException; 31 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 32 import org.objectweb.fractal.api.control.ContentController; 33 import org.objectweb.fractal.api.type.ComponentType; 34 import org.objectweb.fractal.api.type.InterfaceType; 35 36 import org.objectweb.fractal.julia.ChainedNoSuchInterfaceException; 37 38 50 51 public abstract class TypeBindingMixin implements BindingController { 52 53 57 private TypeBindingMixin () { 58 } 59 60 64 76 77 public Object lookupFc (final String clientItfName) 78 throws NoSuchInterfaceException 79 { 80 ComponentType compType = (ComponentType)_this_weaveableC.getFcType(); 81 InterfaceType clientItfType; 82 try { 83 clientItfType = compType.getFcInterfaceType(clientItfName); 84 } catch (NoSuchInterfaceException e) { 85 throw new ChainedNoSuchInterfaceException( 86 null, _this_weaveableC, clientItfName); 87 } 88 checkFcClientInterface(clientItfType); 89 return lookupFc(clientItfType, clientItfName); 90 } 91 92 108 109 public void bindFc (final String clientItfName, final Object serverItf) throws 110 NoSuchInterfaceException, 111 IllegalBindingException, 112 IllegalLifeCycleException 113 { 114 ComponentType compType = (ComponentType)_this_weaveableC.getFcType(); 115 InterfaceType cItfType; 116 try { 117 cItfType = compType.getFcInterfaceType(clientItfName); 118 } catch (NoSuchInterfaceException e) { 119 throw new ChainedNoSuchInterfaceException( 120 null, _this_weaveableC, clientItfName); 121 } 122 checkFcClientInterface(cItfType); 123 124 ContentController cc; 125 try { 126 cc = (ContentController)_this_weaveableC. 127 getFcInterface("content-controller"); 128 } catch (NoSuchInterfaceException e) { 129 cc = null; 130 } 131 132 if (cItfType.isFcClientItf()) { 134 _this_weaveableC.getFcInterface(clientItfName); 135 } else { 136 cc.getFcInternalInterface(clientItfName); 137 } 138 139 Interface sItf; 140 InterfaceType sItfType; 141 try { 142 sItf = (Interface)serverItf; 143 sItfType = (InterfaceType)sItf.getFcItfType(); 144 } catch (ClassCastException e) { 145 bindFc(cItfType, clientItfName, serverItf); 149 return; 150 } 151 152 if (sItfType.isFcClientItf()) { 153 throw new ChainedIllegalBindingException( 154 null, 155 _this_weaveableC, 156 sItf.getFcItfOwner(), 157 clientItfName, 158 sItf.getFcItfName(), 159 "Cannot bind two client interfaces together"); 160 } 161 162 try { 163 Class s = Class.forName(sItfType.getFcItfSignature()); 164 Class c = Class.forName(cItfType.getFcItfSignature()); 165 if (!c.isAssignableFrom(s)) { 166 throw new ChainedIllegalBindingException( 167 null, 168 _this_weaveableC, 169 sItf.getFcItfOwner(), 170 clientItfName, 171 sItf.getFcItfName(), 172 "The server interface type is not a subtype " + 173 "of the client interface type"); 174 } 175 } catch (ClassNotFoundException ignored) { 176 } 177 178 if (!cItfType.isFcOptionalItf() && sItfType.isFcOptionalItf()) { 179 throw new ChainedIllegalBindingException( 180 null, 181 _this_weaveableC, 182 ((Interface)serverItf).getFcItfOwner(), 183 clientItfName, 184 ((Interface)serverItf).getFcItfName(), 185 "A mandatory interface cannot be bound to an optional interface"); 186 } 187 188 bindFc(cItfType, clientItfName, sItf); 189 } 190 191 203 204 public void unbindFc (final String clientItfName) throws 205 NoSuchInterfaceException, 206 IllegalBindingException, 207 IllegalLifeCycleException 208 { 209 ComponentType compType = (ComponentType)_this_weaveableC.getFcType(); 210 InterfaceType clientItfType; 211 try { 212 clientItfType = compType.getFcInterfaceType(clientItfName); 213 } catch (NoSuchInterfaceException e) { 214 throw new ChainedNoSuchInterfaceException( 215 null, _this_weaveableC, clientItfName); 216 } 217 checkFcClientInterface(clientItfType); 218 unbindFc(clientItfType, clientItfName); 219 } 220 221 235 236 public Object lookupFc ( 237 final InterfaceType clientItfType, 238 final String clientItfName) 239 throws 240 NoSuchInterfaceException 241 { 242 return _super_lookupFc(clientItfName); 243 } 244 245 261 262 public void bindFc ( 263 final InterfaceType clientItfType, 264 final String clientItfName, 265 final Object serverItf) 266 throws 267 NoSuchInterfaceException, 268 IllegalBindingException, 269 IllegalLifeCycleException 270 { 271 _super_bindFc(clientItfName, serverItf); 272 } 273 274 288 289 public void unbindFc ( 290 final InterfaceType clientItfType, 291 final String clientItfName) 292 throws 293 NoSuchInterfaceException, 294 IllegalBindingException, 295 IllegalLifeCycleException 296 { 297 _super_unbindFc(clientItfName); 298 } 299 300 308 309 private void checkFcClientInterface (InterfaceType itfType) 310 throws NoSuchInterfaceException 311 { 312 try { 313 _this_weaveableC.getFcInterface("content-controller"); 314 String name = itfType.getFcItfName(); 315 if (!name.equals("component") && !name.endsWith("-controller")) { 316 return; 317 } 318 } catch (NoSuchInterfaceException e) { 319 if (itfType.isFcClientItf()) { 320 return; 321 } 322 } 323 throw new ChainedNoSuchInterfaceException( 324 null, _this_weaveableC, itfType.getFcItfName()); 325 } 326 327 331 336 337 public Component _this_weaveableC; 338 339 351 352 public abstract Object _super_lookupFc (String clientItfName) throws 353 NoSuchInterfaceException; 354 355 368 369 public abstract void _super_bindFc (String clientItfName, Object serverItf) throws 370 NoSuchInterfaceException, 371 IllegalBindingException, 372 IllegalLifeCycleException; 373 374 386 387 public abstract void _super_unbindFc (String clientItfName) throws 388 NoSuchInterfaceException, 389 IllegalBindingException, 390 IllegalLifeCycleException; 391 } 392 | Popular Tags |