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.ContentController; 31 import org.objectweb.fractal.api.control.IllegalBindingException; 32 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 33 import org.objectweb.fractal.api.type.InterfaceType; 34 35 45 46 public abstract class AutoBindingMixin { 47 48 52 private AutoBindingMixin () { 53 } 54 55 59 75 76 public void bindFc ( 77 final InterfaceType clientItfType, 78 final String clientItfName, 79 final Object serverItf) 80 throws 81 NoSuchInterfaceException, 82 IllegalBindingException, 83 IllegalLifeCycleException 84 { 85 _super_bindFc(clientItfType, clientItfName, serverItf); 86 if (clientItfType.isFcCollectionItf()) { 87 String sItfName = clientItfType.getFcItfName(); 88 ContentController cc; 89 try { 90 cc = (ContentController)_this_weaveableC.getFcInterface("content-controller"); 91 } catch (NoSuchInterfaceException e) { 92 cc = null; 93 } 94 if (cc != null && !clientItfName.equals(sItfName)) { 95 Object sItf = cc.getFcInternalInterface(sItfName); 96 Object itf = cc.getFcInternalInterface(clientItfName); 97 try { 98 Object [] itfs = Util.getFcClientItfsBoundTo((Interface)sItf).toArray(); 99 for (int i = 0; i < itfs.length; ++i) { 100 Interface cItf = (Interface)itfs[i]; 101 InterfaceType cItfType = (InterfaceType)cItf.getFcItfType(); 102 if (cItfType.isFcCollectionItf()) { 103 Component c = cItf.getFcItfOwner(); 104 BindingController bc = 105 (BindingController)c.getFcInterface("binding-controller"); 106 String s = 107 cItfType.getFcItfName() + clientItfName.substring(sItfName.length()); 108 bc.bindFc(s, itf); 109 } 110 } 111 } catch (Exception e) { 112 throw new ChainedIllegalBindingException( 113 e, _this_weaveableC, null, clientItfName, null, 114 "Error during automatic creation of bindings from the model binding"); 115 } 116 } 117 if (clientItfName.equals(sItfName)) { 118 Interface sItf = (Interface)serverItf; 119 InterfaceType sItfType = (InterfaceType)sItf.getFcItfType(); 120 if (sItf.isFcInternalItf() && 121 sItfType.isFcCollectionItf() && 122 sItf.getFcItfName().equals(sItfType.getFcItfName())) 123 { 124 Component sComp = sItf.getFcItfOwner(); 125 try { 126 BindingController bc = 127 (BindingController)sComp.getFcInterface("binding-controller"); 128 cc = 129 (ContentController)sComp.getFcInterface("content-controller"); 130 String s = sItf.getFcItfName(); 131 String [] itfs = bc.listFc(); 132 for (int i = 0; i < itfs.length; ++i) { 133 if (itfs[i].length() > s.length() && itfs[i].startsWith(s)) { 134 _this_bindFc( 135 clientItfName + itfs[i].substring(s.length()), 136 cc.getFcInternalInterface(itfs[i])); 137 } 138 } 139 } catch (Exception e) { 140 throw new ChainedIllegalBindingException( 141 e, _this_weaveableC, null, clientItfName, null, 142 "Error during automatic creation of bindings from the model binding"); 143 } 144 } 145 } 146 } 147 } 148 149 163 164 public void unbindFc ( 165 final InterfaceType clientItfType, 166 final String clientItfName) 167 throws 168 NoSuchInterfaceException, 169 IllegalBindingException, 170 IllegalLifeCycleException 171 { 172 _super_unbindFc(clientItfType, clientItfName); 173 if (clientItfType.isFcCollectionItf()) { 174 ContentController cc; 175 try { 176 cc = (ContentController)_this_weaveableC.getFcInterface("content-controller"); 177 } catch (NoSuchInterfaceException e) { 178 return; 179 } 180 String sItfName = clientItfType.getFcItfName(); 181 Object sItf = cc.getFcInternalInterface(sItfName); 182 try { 183 Object [] itfs = Util.getFcClientItfsBoundTo((Interface)sItf).toArray(); 184 for (int i = 0; i < itfs.length; ++i) { 185 Interface cItf = (Interface)itfs[i]; 186 InterfaceType cItfType = (InterfaceType)cItf.getFcItfType(); 187 if (cItfType.isFcCollectionItf()) { 188 Component c = cItf.getFcItfOwner(); 189 BindingController bc = 190 (BindingController)c.getFcInterface("binding-controller"); 191 String s = 192 cItfType.getFcItfName() + clientItfName.substring(sItfName.length()); 193 bc.unbindFc(s); 194 } 195 } 196 } catch (Exception e) { 197 throw new ChainedIllegalBindingException( 198 e, _this_weaveableC, null, clientItfName, null, 199 "Error during automatic destruction of bindings from the model binding"); 200 } 201 } 202 } 203 204 208 213 214 public Component _this_weaveableC; 215 216 228 229 public abstract void _this_bindFc (String clientItfName, Object serverItf) throws 230 NoSuchInterfaceException, 231 IllegalBindingException, 232 IllegalLifeCycleException; 233 234 248 249 public abstract void _super_bindFc ( 250 InterfaceType clientItfType, 251 String clientItfName, 252 Object serverItf) 253 throws 254 NoSuchInterfaceException, 255 IllegalBindingException, 256 IllegalLifeCycleException; 257 258 271 272 public abstract void _super_unbindFc ( 273 InterfaceType clientItfType, 274 String clientItfName) 275 throws 276 NoSuchInterfaceException, 277 IllegalBindingException, 278 IllegalLifeCycleException; 279 } 280 | Popular Tags |