1 23 24 package org.objectweb.fractal.gui.model; 25 26 import java.util.List ; 27 28 32 33 public class StatusManager implements ConfigurationListener { 34 35 public void rootComponentChanged (final Component oldValue) { 36 } 38 39 public void changeCountChanged (Component component, long changeCount) { 40 } 42 43 public void nameChanged (final Component component, final String oldValue) { 44 long status = component.getStatus(); 45 String name = component.getName(); 46 if (name.equals("")) { 47 status |= Component.NAME_MISSING; 48 } else { 49 status &= ~Component.NAME_MISSING; 50 } 51 component.setStatus(status); 52 saysItsModified (component); 53 } 54 55 public void typeChanged (final Component component, final String oldValue) { 56 long status = component.getStatus(); 57 String type = component.getType(); 58 63 component.setStatus(status); 64 saysItsModified (component); 65 } 66 67 public void implementationChanged ( 68 final Component component, 69 final String oldValue) 70 { 71 long status = component.getStatus(); 72 String implementation = component.getImplementation(); 73 if (implementation.equals("")) { 74 if (!component.isComposite()) { 75 status |= Component.IMPLEMENTATION_MISSING; 76 } 77 } else { 78 status &= ~Component.IMPLEMENTATION_MISSING; 79 try { 80 Class.forName(implementation); 81 status &= ~Component.IMPLEMENTATION_CLASS_NOT_FOUND; 82 } catch (ClassNotFoundException e) { 83 status |= Component.IMPLEMENTATION_CLASS_NOT_FOUND; 84 } 85 } 86 component.setStatus(status); 87 saysItsModified (component); 88 } 89 90 public void interfaceNameChanged (final Interface i, final String oldValue) { 91 long status = i.getStatus(); 92 String name = i.getName(); 93 if (name.equals("")) { 94 status |= Interface.NAME_MISSING; 95 } else { 96 status &= ~Interface.NAME_MISSING; 97 } 98 i.setStatus(status); 99 saysItsModified (i.getOwner()); 100 } 101 102 public void interfaceSignatureChanged ( 103 final Interface i, 104 final String oldValue) 105 { 106 long status = i.getStatus(); 107 String signature = i.getSignature(); 108 if (signature.equals("")) { 109 status |= Interface.SIGNATURE_MISSING; 110 } else { 111 status &= ~Interface.SIGNATURE_MISSING; 112 try { 113 Class.forName(signature); 114 status &= ~Interface.SIGNATURE_CLASS_NOT_FOUND; 115 } catch (ClassNotFoundException e) { 116 status |= Interface.SIGNATURE_CLASS_NOT_FOUND; 117 } 118 119 if (i instanceof ClientInterface) { 120 ClientInterface citf = (ClientInterface)i; 121 Binding bd = citf.getBinding(); 122 if (bd != null) { 123 ServerInterface sitf = bd.getServerInterface(); 124 if (sitf != null) { 125 verifyCompatibility (citf, sitf); 126 } 127 } 128 } 129 else { 130 ServerInterface sitf = (ServerInterface)i; 131 List bindings = sitf.getBindings(); 132 for (int z = 0; z < bindings.size(); ++z) { 133 Binding bd = (Binding)bindings.get(z); 134 ClientInterface citf = bd.getClientInterface(); 135 if (citf != null) { 136 verifyCompatibility (citf, sitf); 137 } 138 } 139 } 140 } 141 i.setStatus(status); 142 saysItsModified (i.getOwner()); 143 } 144 145 public void interfaceContingencyChanged ( 146 final Interface i, 147 final boolean oldValue) 148 { 149 saysItsModified (i.getOwner()); } 151 152 public void interfaceCardinalityChanged ( 153 final Interface i, 154 final boolean oldValue) 155 { 156 saysItsModified (i.getOwner()); } 158 159 public void clientInterfaceAdded ( 160 final Component component, 161 final ClientInterface i, 162 final int index) 163 { 164 saysItsModified (component); } 166 167 public void clientInterfaceRemoved ( 168 final Component component, 169 final ClientInterface i, 170 final int index) 171 { 172 saysItsModified (component); } 174 175 public void serverInterfaceAdded ( 176 final Component component, 177 final ServerInterface i, 178 final int index) 179 { 180 saysItsModified (component); } 182 183 public void serverInterfaceRemoved ( 184 final Component component, 185 final ServerInterface i, 186 final int index) 187 { 188 saysItsModified (component); } 190 191 public void interfaceBound ( 192 final ClientInterface citf, 193 final ServerInterface sitf) 194 { 195 196 String tempo; 198 199 if (citf.getSignature().length() == 0) { 200 tempo = sitf.getSignature(); 201 if (tempo.length() != 0) { 202 citf.setSignature(tempo); 203 } 204 } 205 if (sitf.getSignature().length() == 0) { 206 tempo = citf.getSignature(); 207 if (tempo.length() != 0) { 208 sitf.setSignature(tempo); 209 } 210 } 211 if (citf.getName().length() == 0) { 212 tempo = sitf.getName(); 213 if (tempo.length() != 0) { 214 citf.setName(tempo); 215 } 216 } 217 if (sitf.getName().length() == 0) { 218 tempo = citf.getName(); 219 if (tempo.length() != 0) { 220 sitf.setName(tempo); 221 } 222 } 223 verifyCompatibility (citf, sitf); 224 saysItsModified (citf.getOwner()); 225 } 227 228 public void interfaceRebound ( 229 final ClientInterface citf, 230 final ServerInterface oldSitf) 231 { 232 verifyCompatibility (citf, oldSitf); 234 saysItsModified (citf.getOwner()); 235 } 236 237 public void interfaceUnbound ( 238 final ClientInterface citf, 239 final ServerInterface sitf) 240 { 241 verifyCompatibility (citf, sitf); 243 saysItsModified (citf.getOwner()); 244 } 245 246 public void attributeControllerChanged ( 247 final Component component, 248 final String oldValue) 249 { 250 long status = component.getStatus(); 251 String attributeController = component.getAttributeController(); 252 List attributes = component.getAttributeNames(); 253 if (attributeController.equals("")) { 254 if (attributes.size() > 0) { 255 status |= Component.ATTRIBUTE_CONTROLLER_MISSING; 256 } 257 } else { 258 status &= ~Component.ATTRIBUTE_CONTROLLER_MISSING; 259 try { 260 Class.forName(attributeController); 261 status &= ~Component.ATTRIBUTE_CONTROLLER_CLASS_NOT_FOUND; 262 } catch (ClassNotFoundException e) { 263 status |= Component.ATTRIBUTE_CONTROLLER_CLASS_NOT_FOUND; 264 } 265 } 266 component.setStatus(status); 267 saysItsModified (component); 268 } 269 270 public void attributeChanged ( 271 final Component component, 272 final String attributeName, 273 final String oldValue) 274 { 275 long status = component.getStatus(); 276 String attributeController = component.getAttributeController(); 277 List attributes = component.getAttributeNames(); 278 if (attributes.size() == 0) { 279 status &= ~Component.ATTRIBUTE_CONTROLLER_MISSING; 280 } else if (attributeController.equals("")) { 281 status |= Component.ATTRIBUTE_CONTROLLER_MISSING; 282 } 283 component.setStatus(status); 284 saysItsModified (component); 285 } 286 287 public void templateControllerDescriptorChanged ( 288 final Component component, 289 final String oldValue) 290 { 291 saysItsModified (component); } 293 294 public void componentControllerDescriptorChanged ( 295 final Component component, 296 final String oldValue) 297 { 298 saysItsModified (component); } 300 301 public void subComponentAdded ( 302 final Component parent, 303 final Component child, 304 final int index) 305 { 306 long status = parent.getStatus(); 307 status &= ~Component.IMPLEMENTATION_MISSING; 308 status &= ~Component.IMPLEMENTATION_CLASS_NOT_FOUND; 309 parent.setStatus(status); 310 saysItsModified (parent); 311 } 312 313 public void subComponentRemoved ( 314 final Component parent, 315 final Component child, 316 final int index) 317 { 318 long status = parent.getStatus(); 319 List subComponents = parent.getSubComponents(); 320 String implementation = parent.getImplementation(); 321 if (subComponents.size() == 0 && implementation.equals("")) { 322 status |= Component.IMPLEMENTATION_MISSING; 323 } 324 parent.setStatus(status); 325 saysItsModified (parent); 326 } 327 328 332 private void saysItsModified (Component component) { 333 Configuration cf = component.getConfiguration(); 334 if (cf.getRootComponent().contains(component)) { 335 cf.setChangeCount(cf.getChangeCount() + 1); 336 } 337 } 338 339 private void verifyCompatibility ( 340 final ClientInterface citf, 341 final ServerInterface sitf) 342 { 343 if (citf == null || sitf == null) { 344 return; 345 } 346 Binding bd = citf.getBinding(); 347 if (bd == null) { 348 return; 349 } 350 if ((citf.getSignature().length() > 0) && 351 (sitf.getSignature().length() > 0)) 352 { 353 try { 354 Class c = Class.forName(citf.getSignature()); 355 Class s = Class.forName(sitf.getSignature()); 356 if (!s.isAssignableFrom(c)) { 357 } 358 } catch (ClassNotFoundException e) { 359 bd.setStatus(Binding.INCOMPATIBLE_TYPE_INTERFACES); 360 return; 361 } 362 } 363 bd.setStatus(Binding.OK); 364 } 365 } 366 | Popular Tags |