1 23 24 package org.objectweb.fractal.gui.model; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import java.util.Map ; 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 32 39 40 public class DerivedConfiguration implements 41 Configuration, 42 ConfigurationListener, 43 BindingController 44 { 45 46 49 50 public final static String CONFIGURATION_BINDING = "configuration"; 51 52 56 57 public final static String CONFIGURATION_LISTENERS_BINDING = 58 "configuration-listeners"; 59 60 63 64 private Configuration configuration; 65 66 69 70 private Map listeners; 71 72 76 77 private Component root; 78 79 82 83 private long changeCount; 84 85 88 89 public DerivedConfiguration () { 90 root = new BasicComponent(null); listeners = new HashMap (); 92 } 93 94 98 public String [] listFc () { 99 int size = listeners.size(); 100 String [] names = new String [size + 1]; 101 listeners.keySet().toArray(names); 102 names[size] = CONFIGURATION_BINDING; 103 return names; 104 } 105 106 public Object lookupFc (final String clientItfName) { 107 if (CONFIGURATION_BINDING.equals(clientItfName)) { 108 return configuration; 109 } else if (clientItfName.startsWith(CONFIGURATION_LISTENERS_BINDING)) { 110 return listeners.get(clientItfName); 111 } 112 return null; 113 } 114 115 public void bindFc ( 116 final String clientItfName, 117 final Object serverItf) 118 { 119 if (CONFIGURATION_BINDING.equals(clientItfName)) { 120 configuration = (Configuration)serverItf; 121 } else if (clientItfName.startsWith(CONFIGURATION_LISTENERS_BINDING)) { 122 listeners.put(clientItfName, serverItf); 123 } 124 } 125 126 public void unbindFc (final String clientItfName) { 127 if (CONFIGURATION_BINDING.equals(clientItfName)) { 128 configuration = null; 129 } else if (clientItfName.startsWith(CONFIGURATION_LISTENERS_BINDING)) { 130 listeners.remove(clientItfName); 131 } 132 } 133 134 138 public Component getRootComponent () { 139 return root; 140 } 141 142 public void setRootComponent (final Component root) { 143 Component oldRoot = this.root; 144 if (root != oldRoot) { 145 this.root = root; 146 Iterator i = listeners.values().iterator(); 147 while (i.hasNext()) { 148 ConfigurationListener l = (ConfigurationListener)i.next(); 149 l.rootComponentChanged(oldRoot); 150 } 151 } 152 } 153 154 public long getChangeCount () { 155 return changeCount; 156 } 157 158 public void setChangeCount (long changeCount) { 159 this.changeCount = changeCount; 160 Iterator i = listeners.values().iterator(); 161 while (i.hasNext()) { 162 ConfigurationListener l = (ConfigurationListener)i.next(); 163 l.changeCountChanged(getRootComponent(), changeCount); 164 } 165 } 166 167 168 public String getStorage () { 169 return configuration.getStorage(); 170 } 171 172 public void setStorage (String storage) { 173 configuration.setStorage(storage); 174 } 175 176 180 public void changeCountChanged (Component component, long changeCount) 181 { 182 } 184 185 public void rootComponentChanged (final Component oldValue) { 186 root = configuration.getRootComponent(); 187 Iterator i = listeners.values().iterator(); 188 while (i.hasNext()) { 189 ConfigurationListener l = (ConfigurationListener)i.next(); 190 l.rootComponentChanged(oldValue); 191 } 192 } 193 194 public void nameChanged (final Component component, final String oldValue) { 195 if (root.contains(component)) { 196 Iterator i = listeners.values().iterator(); 197 while (i.hasNext()) { 198 ConfigurationListener l = (ConfigurationListener)i.next(); 199 l.nameChanged(component, oldValue); 200 } 201 } 202 } 203 204 public void typeChanged (final Component component, final String oldValue) { 205 if (root.contains(component)) { 206 Iterator i = listeners.values().iterator(); 207 while (i.hasNext()) { 208 ConfigurationListener l = (ConfigurationListener)i.next(); 209 l.typeChanged(component, oldValue); 210 } 211 } 212 } 213 214 public void implementationChanged ( 215 final Component component, 216 final String oldValue) 217 { 218 if (root.contains(component)) { 219 Iterator i = listeners.values().iterator(); 220 while (i.hasNext()) { 221 ConfigurationListener l = (ConfigurationListener)i.next(); 222 l.implementationChanged(component, oldValue); 223 } 224 } 225 } 226 227 public void interfaceNameChanged (final Interface i, final String oldValue) { 228 if (root.contains(i.getOwner())) { 229 Iterator j = listeners.values().iterator(); 230 while (j.hasNext()) { 231 ConfigurationListener l = (ConfigurationListener)j.next(); 232 l.interfaceNameChanged(i, oldValue); 233 } 234 } 235 } 236 237 public void interfaceSignatureChanged ( 238 final Interface i, 239 final String oldValue) 240 { 241 if (root.contains(i.getOwner())) { 242 Iterator j = listeners.values().iterator(); 243 while (j.hasNext()) { 244 ConfigurationListener l = (ConfigurationListener)j.next(); 245 l.interfaceSignatureChanged(i, oldValue); 246 } 247 } 248 } 249 250 public void interfaceContingencyChanged ( 251 final Interface i, final boolean oldValue) 252 { 253 if (root.contains(i.getOwner())) { 254 Iterator j = listeners.values().iterator(); 255 while (j.hasNext()) { 256 ConfigurationListener l = (ConfigurationListener)j.next(); 257 l.interfaceContingencyChanged(i, oldValue); 258 } 259 } 260 } 261 262 public void interfaceCardinalityChanged ( 263 final Interface i, 264 final boolean oldValue) 265 { 266 if (root.contains(i.getOwner())) { 267 Iterator j = listeners.values().iterator(); 268 while (j.hasNext()) { 269 ConfigurationListener l = (ConfigurationListener)j.next(); 270 l.interfaceCardinalityChanged(i, oldValue); 271 } 272 } 273 } 274 275 public void clientInterfaceAdded ( 276 final Component component, 277 final ClientInterface i, 278 final int index) 279 { 280 if (root.contains(component)) { 281 Iterator j = listeners.values().iterator(); 282 while (j.hasNext()) { 283 ConfigurationListener l = (ConfigurationListener)j.next(); 284 l.clientInterfaceAdded(component, i, index); 285 } 286 } 287 } 288 289 public void clientInterfaceRemoved ( 290 final Component component, 291 final ClientInterface i, 292 final int index) 293 { 294 if (root.contains(component)) { 295 Iterator j = listeners.values().iterator(); 296 while (j.hasNext()) { 297 ConfigurationListener l = (ConfigurationListener)j.next(); 298 l.clientInterfaceRemoved(component, i, index); 299 } 300 } 301 } 302 303 public void serverInterfaceAdded ( 304 final Component component, 305 final ServerInterface i, 306 final int index) 307 { 308 if (root.contains(component)) { 309 Iterator j = listeners.values().iterator(); 310 while (j.hasNext()) { 311 ConfigurationListener l = (ConfigurationListener)j.next(); 312 l.serverInterfaceAdded(component, i, index); 313 } 314 } 315 } 316 317 public void serverInterfaceRemoved ( 318 final Component component, 319 final ServerInterface i, 320 final int index) 321 { 322 if (root.contains(component)) { 323 Iterator j = listeners.values().iterator(); 324 while (j.hasNext()) { 325 ConfigurationListener l = (ConfigurationListener)j.next(); 326 l.serverInterfaceRemoved(component, i, index); 327 } 328 } 329 } 330 331 public void interfaceBound ( 332 final ClientInterface citf, 333 final ServerInterface sitf) 334 { 335 if (root.contains(citf.getOwner())) { 336 Iterator i = listeners.values().iterator(); 337 while (i.hasNext()) { 338 ConfigurationListener l = (ConfigurationListener)i.next(); 339 l.interfaceBound(citf, sitf); 340 } 341 } 342 } 343 344 public void interfaceRebound ( 345 final ClientInterface citf, 346 final ServerInterface oldSitf) 347 { 348 if (root.contains(citf.getOwner())) { 349 Iterator i = listeners.values().iterator(); 350 while (i.hasNext()) { 351 ConfigurationListener l = (ConfigurationListener)i.next(); 352 l.interfaceRebound(citf, oldSitf); 353 } 354 } 355 } 356 357 public void interfaceUnbound ( 358 final ClientInterface citf, 359 final ServerInterface sitf) 360 { 361 if (root.contains(citf.getOwner())) { 362 Iterator i = listeners.values().iterator(); 363 while (i.hasNext()) { 364 ConfigurationListener l = (ConfigurationListener)i.next(); 365 l.interfaceUnbound(citf, sitf); 366 } 367 } 368 } 369 370 public void attributeControllerChanged ( 371 final Component component, 372 final String oldValue) 373 { 374 if (root.contains(component)) { 375 Iterator i = listeners.values().iterator(); 376 while (i.hasNext()) { 377 ConfigurationListener l = (ConfigurationListener)i.next(); 378 l.attributeControllerChanged(component, oldValue); 379 } 380 } 381 } 382 383 public void attributeChanged ( 384 final Component component, 385 final String attributeName, 386 final String oldValue) 387 { 388 if (root.contains(component)) { 389 Iterator i = listeners.values().iterator(); 390 while (i.hasNext()) { 391 ConfigurationListener l = (ConfigurationListener)i.next(); 392 l.attributeChanged(component, attributeName, oldValue); 393 } 394 } 395 } 396 397 public void templateControllerDescriptorChanged ( 398 final Component component, 399 final String oldValue) 400 { 401 if (root.contains(component)) { 402 Iterator i = listeners.values().iterator(); 403 while (i.hasNext()) { 404 ConfigurationListener l = (ConfigurationListener)i.next(); 405 l.templateControllerDescriptorChanged(component, oldValue); 406 } 407 } 408 } 409 410 public void componentControllerDescriptorChanged ( 411 final Component component, 412 final String oldValue) 413 { 414 if (root.contains(component)) { 415 Iterator i = listeners.values().iterator(); 416 while (i.hasNext()) { 417 ConfigurationListener l = (ConfigurationListener)i.next(); 418 l.componentControllerDescriptorChanged(component, oldValue); 419 } 420 } 421 } 422 423 public void subComponentAdded ( 424 final Component parent, 425 final Component child, 426 final int index) 427 { 428 if (root.contains(parent)) { 429 Iterator i = listeners.values().iterator(); 430 while (i.hasNext()) { 431 ConfigurationListener l = (ConfigurationListener)i.next(); 432 l.subComponentAdded(parent, child, index); 433 } 434 } 435 } 436 437 public void subComponentRemoved ( 438 final Component parent, 439 final Component child, 440 final int index) 441 { 442 if (root.contains(parent)) { 443 Iterator i = listeners.values().iterator(); 444 while (i.hasNext()) { 445 ConfigurationListener l = (ConfigurationListener)i.next(); 446 l.subComponentRemoved(parent, child, index); 447 } 448 } 449 } 450 } 451 | Popular Tags |