1 23 24 package org.objectweb.fractal.gui.model; 25 26 import java.util.ArrayList ; 27 import java.util.Collections ; 28 import java.util.HashMap ; 29 import java.util.List ; 30 import java.util.Map ; 31 32 35 36 public class SharedComponent extends AbstractComponent { 37 38 41 42 private BasicComponent masterComponent; 43 44 47 48 private long status; 49 50 53 54 private String name; 55 56 60 61 private Map interfaces; 62 63 68 69 SharedComponent (final BasicComponent masterComponent) { 70 if (masterComponent.getMasterComponent() != null) { 71 throw new RuntimeException ("Internal error"); 72 } 73 this.masterComponent = masterComponent; 74 this.status = NAME_MISSING; 75 this.name = ""; 76 this.interfaces = new HashMap (); 77 masterComponent.addSlaveComponent(this); 78 } 79 80 81 public Configuration getConfiguration () { 82 return masterComponent.getConfiguration(); 83 } 84 public long getStatus () { 85 return status | masterComponent.getStatus(); 86 } 87 88 public void setStatus (final long status) { 89 this.status = status; 90 } 91 92 96 public String getName () { 97 return name; 98 } 99 100 public void setName (final String name) { 101 if (name == null) { 102 throw new IllegalArgumentException (); 103 } 104 String oldName = this.name; 105 if (!name.equals(oldName)) { 106 List vetoableListeners = masterComponent.getOwner().getVetoableListeners(); 107 for (int i = 0; i < vetoableListeners.size(); ++i) { 108 VetoableConfigurationListener l = 109 (VetoableConfigurationListener)vetoableListeners.get(i); 110 l.canChangeName(this); 111 } 112 this.name = name; 113 if (name.equals("")) { 114 status |= NAME_MISSING; 115 } else { 116 status &= ~NAME_MISSING; 117 } 118 List listeners = masterComponent.getOwner().getListeners(); 119 for (int i = 0; i < listeners.size(); ++i) { 120 ConfigurationListener cl = (ConfigurationListener)listeners.get(i); 121 cl.nameChanged(this, oldName); 122 } 123 } 124 } 125 126 public String getType () { 127 return masterComponent.getType(); 128 } 129 130 public void setType (final String type) { 131 masterComponent.setType(type); 132 } 133 134 public String getImplementation () { 135 return masterComponent.getImplementation(); 136 } 137 138 public void setImplementation (final String implementation) { 139 masterComponent.setImplementation(implementation); 140 } 141 142 146 public List getClientInterfaces () { 147 List l = masterComponent.getClientInterfaces(); 148 List result = new ArrayList (); 149 for (int i = 0; i < l.size(); ++i) { 150 result.add(getInterface((Interface)l.get(i))); 151 } 152 return Collections.unmodifiableList(result); 153 } 154 155 public Interface getClientInterface (final String name) { 156 return getInterface(masterComponent.getClientInterface(name)); 157 } 158 159 public void addClientInterface (final ClientInterface itf) { 160 masterComponent.addClientInterface(itf); 161 } 162 163 public void removeClientInterface (ClientInterface itf) { 164 if (itf instanceof SharedInterface) { 165 itf = (ClientInterface)((SharedInterface)itf).masterInterface; 166 } 167 masterComponent.removeClientInterface(itf); 168 } 169 170 public List getServerInterfaces () { 171 List l = masterComponent.getServerInterfaces(); 172 List result = new ArrayList (); 173 for (int i = 0; i < l.size(); ++i) { 174 result.add(getInterface((Interface)l.get(i))); 175 } 176 return Collections.unmodifiableList(result); 177 } 178 179 public Interface getServerInterface (final String name) { 180 return getInterface(masterComponent.getServerInterface(name)); 181 } 182 183 public void addServerInterface (final ServerInterface itf) { 184 masterComponent.addServerInterface(itf); 185 } 186 187 public void removeServerInterface (ServerInterface itf) { 188 if (itf instanceof SharedInterface) { 189 itf = (ServerInterface)((SharedInterface)itf).masterInterface; 190 } 191 masterComponent.removeServerInterface(itf); 192 } 193 194 198 public void bind (final ClientInterface citf, final String citfName, final ServerInterface sitf) { 199 Interface itf = ((SharedInterface)citf).masterInterface; 200 masterComponent.bind((ClientInterface)itf, citfName, sitf); 201 } 202 203 public void rebind (final ClientInterface citf, final ServerInterface sitf) { 204 Interface itf = ((SharedInterface)citf).masterInterface; 205 masterComponent.rebind((ClientInterface)itf, sitf); 206 } 207 208 public void unbind (final ClientInterface citf) { 209 Interface itf = ((SharedInterface)citf).masterInterface; 210 masterComponent.unbind((ClientInterface)itf); 211 } 212 213 217 public String getAttributeController () { 218 return masterComponent.getAttributeController(); 219 } 220 221 public void setAttributeController (final String attributeController) { 222 masterComponent.setAttributeController(attributeController); 223 } 224 225 public List getAttributeNames () { 226 return masterComponent.getAttributeNames(); 227 } 228 229 public String getAttribute (final String attributeName) { 230 return masterComponent.getAttribute(attributeName); 231 } 232 233 public void setAttribute ( 234 final String attributeName, 235 final String attributeValue) 236 { 237 masterComponent.setAttribute(attributeName, attributeValue); 238 } 239 240 244 public String getTemplateControllerDescriptor () { 245 return masterComponent.getTemplateControllerDescriptor(); 246 } 247 248 public void setTemplateControllerDescriptor (final String desc) { 249 masterComponent.setTemplateControllerDescriptor(desc); 250 } 251 252 public String getComponentControllerDescriptor () { 253 return masterComponent.getComponentControllerDescriptor(); 254 } 255 256 public void setComponentControllerDescriptor (final String desc) { 257 masterComponent.setComponentControllerDescriptor(desc); 258 } 259 260 264 public boolean isShared () { 265 return true; 266 } 267 268 public Component getMasterComponent () { 269 return masterComponent; 270 } 271 272 public List getSlaveComponents () { 273 return Collections.EMPTY_LIST; 274 } 275 276 280 public boolean isComposite () { 281 return false; 282 } 283 284 public List getSubComponents () { 285 return Collections.EMPTY_LIST; 286 } 287 288 public Component getSubComponent (final String name) { 289 return null; 290 } 291 292 public void addSubComponent (final Component child) { 293 throw new IllegalOperationException( 294 "Cannot add a sub component inside a shared component"); 295 } 296 297 public void removeSubComponent (final Component child) { 298 throw new RuntimeException ("Internal error"); 299 } 300 301 305 314 315 Interface getInterface (final Interface masterInterface) { 316 if (masterInterface == null) { 317 return null; 318 } 319 Interface i = (Interface)interfaces.get(masterInterface); 320 if (i == null) { 321 if (masterInterface instanceof ClientInterface) { 322 i = new SharedClientInterface(this, masterInterface); 323 } else { 324 i = new SharedServerInterface(this, masterInterface); 325 } 326 interfaces.put(masterInterface, i); 327 } 328 return i; 329 } 330 } 331 | Popular Tags |