1 26 package org.objectweb.ccm.filetransfer.cif; 27 28 import org.objectweb.ccm.filetransfer.*; 29 30 import org 31 .objectweb 32 .ccm 33 .filetransfer 34 .SystemManagerSessionComposition 35 .ComponentImpl; 36 37 40 public class SystemManagerImpl 41 extends ComponentImpl 42 implements java.awt.event.ActionListener , java.awt.event.ItemListener { 43 44 protected TV tv; 45 46 protected org.omg.Components.Cookie ck[] = 47 new org.omg.Components.Cookie[50]; 48 protected String named[] = new String [50]; 49 protected int rank = 0; 50 protected String selected_comp; 51 52 53 private java.awt.Frame frame_; 54 55 private java.awt.Label label_; 56 private java.awt.TextField text_; 57 58 private java.awt.TextArea textArea_; 59 60 private java.awt.Button button_tv; 61 private java.awt.Button button_tv_rem; 62 private java.awt.Choice choice_; 63 private java.awt.CheckboxGroup cbg; 64 private java.awt.Checkbox pc; 65 private java.awt.Checkbox pda; 66 67 int balancy_flag = 1; 68 69 public static final java.awt.Color white_ = java.awt.Color.white; 70 public static final java.awt.Color dark_ = java.awt.Color.darkGray; 71 72 78 79 public SystemManagerImpl() { 80 } 81 82 88 94 public void configuration_complete() 95 throws org.omg.Components.InvalidConfiguration { 96 97 99 java.awt.GridBagLayout gridbag = new java.awt.GridBagLayout (); 100 java.awt.GridBagConstraints c = new java.awt.GridBagConstraints (); 101 102 frame_ = new java.awt.Frame ("The System Manager GUI"); 104 105 frame_.setSize(400, 300); 106 107 frame_.setLayout(gridbag); 108 109 c.fill = java.awt.GridBagConstraints.BOTH; 110 c.weightx = 1.0; 111 c.gridwidth = java.awt.GridBagConstraints.REMAINDER; 112 113 textArea_ = new java.awt.TextArea (15, 60); 115 textArea_.setEditable(false); 116 textArea_.setBackground(dark_); 117 textArea_.setForeground(white_); 118 gridbag.setConstraints(textArea_, c); 119 120 c.gridwidth = 1; 122 c.fill = java.awt.GridBagConstraints.BOTH; 123 c.weighty = 0.0; 124 c.weightx = 0.0; 125 label_ = new java.awt.Label ("Name:"); 126 gridbag.setConstraints(label_, c); 127 128 c.weightx = 1.0; 130 c.gridwidth = java.awt.GridBagConstraints.REMAINDER; 131 text_ = new java.awt.TextField ("", 1); 132 gridbag.setConstraints(text_, c); 133 134 c.gridwidth = java.awt.GridBagConstraints.RELATIVE; 136 c.weighty = 0.0; 137 c.weightx = 0.0; 138 cbg = new java.awt.CheckboxGroup (); 139 pc = new java.awt.Checkbox ("on PC",cbg,true); 140 gridbag.setConstraints(pc, c); 141 142 c.gridwidth = java.awt.GridBagConstraints.REMAINDER; 143 c.weighty = 0.0; 144 c.weightx = 0.0; 145 pda = new java.awt.Checkbox ("on PDA",cbg,false); 146 gridbag.setConstraints(pda, c); 147 148 c.gridwidth = java.awt.GridBagConstraints.REMAINDER; 149 c.weighty = 0.0; 150 c.weightx = 1.0; 151 button_tv = new java.awt.Button ("Create a TV component"); 153 button_tv.addActionListener(this); 154 gridbag.setConstraints(button_tv, c); 155 156 c.gridwidth = java.awt.GridBagConstraints.RELATIVE; 157 c.weighty = 0.0; 158 c.weightx = 1.0; 159 choice_ = new java.awt.Choice (); 160 choice_.addItemListener(this); 161 choice_.disable(); 162 gridbag.setConstraints(choice_, c); 163 164 c.gridwidth = java.awt.GridBagConstraints.REMAINDER; 165 c.weighty = 0.0; 166 c.weightx = 1.0; 167 button_tv_rem = new java.awt.Button ("Remove a TV component"); 168 button_tv_rem.addActionListener(this); 169 button_tv_rem.disable(); 170 gridbag.setConstraints(button_tv_rem, c); 171 172 frame_.add(textArea_); 173 frame_.add(label_); 174 frame_.add(text_); 175 frame_.add(pc); 176 frame_.add(pda); 177 frame_.add(button_tv); 178 frame_.add(choice_); 179 frame_.add(button_tv_rem); 180 181 182 frame_.pack(); 183 frame_.show(); 184 185 } 186 187 193 198 public void ccm_remove() throws org.omg.Components.CCMException { 199 201 } 202 203 209 212 public void create_component(String component_name) { 213 214 218 219 220 try { 221 222 243 org.omg.CosNaming.NamingContextExt context= 244 org.omg.CosNaming.NamingContextExtHelper 245 .narrow(org.objectweb.openccm.corba.TheNameService 246 .getNamingContext() 247 .getNamingContext()); 248 249 org.omg.Components.HomeFinder hfinder= 250 org.omg.Components 251 .HomeFinderHelper 252 .narrow(context.resolve(context.to_name("OpenCCM/Service/HomeFinder"))); 253 254 org.omg.CORBA.Object ccmhome_obj = 256 hfinder.find_home_by_name(this.compute_home()); 257 258 TVHome tvh = TVHomeHelper.narrow(ccmhome_obj); 259 260 tv = tvh.create(); 262 263 tv.the_name(component_name); 265 266 268 org.omg.CosNaming.NameComponent [] ncomp = 269 new org.omg.CosNaming.NameComponent [1]; 270 271 274 279 ncomp[0] = new org.omg.CosNaming.NameComponent ("ChannelF2", ""); 280 281 org.omg.CORBA.Object obj_ = 282 org 283 .objectweb 284 .openccm 285 .corba 286 .TheNameService 287 .getNamingContext() 288 .getNamingContext() 289 .resolve(ncomp); 290 291 org.objectweb.ccm.filetransfer.Channel chann_ = 292 ChannelHelper.narrow(obj_); 293 294 this.ck[this.rank] = 295 chann_.subscribe_to_tvs(tv.get_consumer_from_channels()); 296 297 tv.configuration_complete(); 299 300 this.named[this.rank] = component_name; 301 this.rank = this.rank + 1; 302 303 305 org.objectweb.openccm.corba.NamingContext ns = 307 org.objectweb.openccm.corba.TheNameService.getNamingContext(); 308 309 ns.rebind("TV" + component_name, tv); 310 311 } catch (Exception e) { 312 e.printStackTrace(); 313 } 314 315 } 316 317 320 public void create_home(String home_name) { 321 323 } 324 325 public void destroy_component(String name) { 326 327 try { 328 329 331 org.omg.CosNaming.NameComponent [] ncomp = 333 new org.omg.CosNaming.NameComponent [1]; 334 335 ncomp[0] = 337 new org.omg.CosNaming.NameComponent ("Channel" + "F2", ""); 338 339 org.omg.CORBA.Object chann_obj = 340 org 341 .objectweb 342 .openccm 343 .corba 344 .TheNameService 345 .getNamingContext() 346 .getNamingContext() 347 .resolve(ncomp); 348 349 org.objectweb.ccm.filetransfer.Channel channel = 350 ChannelHelper.narrow(chann_obj); 351 352 354 int index = 0; 356 357 for (int i = 0; i < rank; i++) { 358 if (named[i].compareTo(name) == 0) { 359 360 index = i; 361 } 362 363 } 364 365 channel.unsubscribe_to_tvs(this.ck[index]); 366 367 369 ncomp[0] = new org.omg.CosNaming.NameComponent ("TV" + name, ""); 370 371 org.omg.CORBA.Object tv_obj = 372 org 373 .objectweb 374 .openccm 375 .corba 376 .TheNameService 377 .getNamingContext() 378 .getNamingContext() 379 .resolve(ncomp); 380 381 org.objectweb.ccm.filetransfer.TV the_tv = TVHelper.narrow(tv_obj); 382 383 the_tv.remove(); 385 386 } catch (Exception e) { 387 e.printStackTrace(); 388 } 389 390 } 391 392 395 public void destroy_home(String name) { 396 398 } 399 400 public String compute_home() { 401 402 407 408 if (cbg.getSelectedCheckbox().getLabel()=="on PC") balancy_flag = 1; 409 else balancy_flag = 2; 410 411 412 String the_home_name = "TVHome" + balancy_flag; 413 414 415 return the_home_name; 416 } 417 418 424 429 public void actionPerformed(java.awt.event.ActionEvent e) { 430 431 Object source = e.getSource(); 432 int flag = 0; 433 if (source == button_tv) { 434 435 String target = cbg.getSelectedCheckbox().getLabel(); 436 437 if (rank == 0) { 438 439 choice_.enable(); 440 button_tv_rem.enable(); 441 this.create_component(text_.getText()); 442 textArea_.append( 443 " <" 444 + text_.getText() 445 + ">" 446 + " TV created " 447 + target 448 + "\n"); 449 choice_.add(text_.getText()); 451 choice_.select(text_.getText()); 452 this.selected_comp = text_.getText(); 453 } else { 454 for (int i = 0; i < rank; i++) { 456 if (named[i].compareTo(text_.getText()) == 0) { 457 textArea_.append( 458 "This name <" 459 + text_.getText() 460 + "> already exists...operation cancelled" 461 + "\n"); 462 flag = 1; 463 i = rank; 464 } 465 } 466 if (flag == 0) { 467 choice_.enable(); 469 button_tv_rem.enable(); 470 this.create_component(text_.getText()); 471 472 473 textArea_.append( 474 " <" 475 + text_.getText() 476 + ">" 477 + " TV created " 478 + target 479 + "\n"); 480 481 choice_.add(text_.getText()); 483 choice_.select(text_.getText()); 484 this.selected_comp = text_.getText(); 485 } 486 487 } 488 489 } else if (source == button_tv_rem) { 490 491 if (this.selected_comp != null) { 493 494 this.destroy_component(this.selected_comp); 495 496 textArea_.append(" <"+ 498 this.selected_comp + ">" + " TV destroyed" + "\n"); 499 500 choice_.remove(this.selected_comp); 502 for (int i = 0; i < rank; i++) { 503 if (named[i].compareTo(this.selected_comp) == 0) { 504 named[i] = "DESTROYED"; 505 i = rank; 506 } 507 } 508 if (choice_.getItemCount() != 0) { 509 choice_.select(0); 510 this.selected_comp = choice_.getItem(0); 511 } else { 512 choice_.disable(); 513 button_tv_rem.disable(); 514 } 515 516 } else { 517 textArea_.append( 518 this.selected_comp 519 + " cannot be removed or does not exist..." 520 + "\n"); 521 } 522 523 } 524 text_.setText(""); 526 527 } 528 529 public void itemStateChanged(java.awt.event.ItemEvent evt) { 530 531 this.selected_comp = evt.getItem().toString(); 532 533 } 534 535 } 536 | Popular Tags |