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.SuperController; 32 import org.objectweb.fractal.api.type.InterfaceType; 33 34 import java.util.ArrayList ; 35 import java.util.HashSet ; 36 import java.util.List ; 37 import java.util.Set ; 38 39 42 43 public class Util { 44 45 49 private Util () { 50 } 51 52 56 63 64 public static Set getFcClientItfsBoundTo (final Interface serverItf) 65 throws Exception 66 { 67 Set result = new HashSet (); 68 Object [] comps = getFcPotentialClientsOf(serverItf).toArray(); 69 for (int i = 0; i < comps.length; ++i) { 70 Component comp = (Component)comps[i]; 71 List clientItfs = getFcClientItfsBoundTo(comp, serverItf); 72 for (int j = 0; j < clientItfs.size(); ++j) { 73 result.add(clientItfs.get(j)); 74 } 75 } 76 return result; 77 } 78 79 86 87 public static Set getFcPotentialClientsOf (final Interface serverItf) 88 throws Exception 89 { 90 Set compSet = new HashSet (); 91 Component serverComp = serverItf.getFcItfOwner(); 92 if (serverItf.isFcInternalItf()) { 93 ContentController cc; 94 try { 95 cc = (ContentController)serverComp.getFcInterface("content-controller"); 96 } catch (NoSuchInterfaceException e) { 97 throw new Exception ("Cannot create shortcuts"); 98 } 99 Component[] comps = cc.getFcSubComponents(); 100 for (int i = 0; i < comps.length; ++i) { 101 compSet.add(comps[i]); 102 } 103 compSet.add(serverComp); 104 } else { 105 SuperController sc; 106 try { 107 sc = (SuperController)serverComp.getFcInterface("super-controller"); 108 } catch (NoSuchInterfaceException e) { 109 throw new Exception ("Cannot create shortcuts"); 110 } 111 Component[] superComps = sc.getFcSuperComponents(); 112 for (int i = 0; i < superComps.length; ++i) { 113 compSet.add(superComps[i]); 114 ContentController cc; 115 try { 116 cc = (ContentController)superComps[i]. 117 getFcInterface("content-controller"); 118 } catch (NoSuchInterfaceException e) { 119 throw new Exception ("Cannot create shortcuts"); 120 } 121 Component[] subComps = cc.getFcSubComponents(); 122 for (int j = 0; j < subComps.length; ++j) { 123 compSet.add(subComps[j]); 124 } 125 } 126 } 127 return compSet; 128 } 129 130 140 141 public static List getFcClientItfsBoundTo ( 142 final Component component, 143 final Interface serverItf) throws Exception 144 { 145 List itfList = new ArrayList (); 146 BindingController bc; 147 try { 148 bc = (BindingController)component.getFcInterface("binding-controller"); 149 } catch (NoSuchInterfaceException e) { 150 return itfList; 151 } 152 153 Object [] itfs = component.getFcInterfaces(); 155 for (int i = 0; i < itfs.length; ++i) { 156 Interface itf; 157 InterfaceType itfType; 158 try { 159 itf = (Interface)itfs[i]; 160 itfType = (InterfaceType)itf.getFcItfType(); 161 } catch (ClassCastException e) { 162 throw new Exception ("Cannot create shortcuts"); 163 } 164 if (!itfType.isFcClientItf()) { 165 continue; 166 } 167 Object sItf; 168 try { 169 sItf = bc.lookupFc(itf.getFcItfName()); 170 } catch (NoSuchInterfaceException e) { 171 continue; 172 } 173 if (serverItf.equals(sItf)) { 174 itfList.add(itf); 175 } 176 } 177 178 ContentController cc; 179 try { 180 cc = (ContentController)component.getFcInterface("content-controller"); 181 } catch (NoSuchInterfaceException e) { 182 return itfList; 183 } 184 185 itfs = cc.getFcInternalInterfaces(); 187 for (int i = 0; i < itfs.length; ++i) { 188 Interface itf; 189 InterfaceType itfType; 190 try { 191 itf = (Interface)itfs[i]; 192 itfType = (InterfaceType)itf.getFcItfType(); 193 } catch (ClassCastException e) { 194 throw new Exception ("Cannot create shortcuts"); 195 } 196 if (!itfType.isFcClientItf()) { 197 continue; 198 } 199 Object sItf; 200 try { 201 sItf = bc.lookupFc(itf.getFcItfName()); 202 } catch (NoSuchInterfaceException e) { 203 continue; 204 } 205 if (serverItf.equals(sItf)) { 206 itfList.add(itf); 207 } 208 } 209 return itfList; 210 } 211 } 212 | Popular Tags |