1 19 package org.netbeans.modules.j2ee.websphere6.ui.wizard; 20 21 import java.util.*; 22 import java.io.*; 23 import java.net.*; 24 import javax.swing.*; 25 import javax.swing.event.*; 26 27 import org.openide.*; 28 import org.openide.util.*; 29 import org.netbeans.modules.j2ee.deployment.plugins.api.*; 30 31 import org.netbeans.modules.j2ee.websphere6.*; 32 33 40 public class WSInstantiatingIterator 41 implements WizardDescriptor.InstantiatingIterator { 42 46 private static final String PROP_DISPLAY_NAME = 47 "ServInstWizard_displayName"; 49 53 private static final String DEFAULT_DEBUGGER_PORT = "8787"; 54 55 58 private WizardDescriptor wizardDescriptor; 59 60 65 public void uninitialize(WizardDescriptor wizardDescriptor) { 66 } 68 69 75 public void initialize(WizardDescriptor wizardDescriptor) { 76 this.wizardDescriptor = wizardDescriptor; 77 } 78 79 85 public String name() { 86 return ""; } 88 89 97 public Set instantiate() throws IOException { 98 Set result = new HashSet(); 100 101 String url = WSURIManager.WSURI + this.host + ":" + this.port; 104 105 String displayName = getDisplayName() + " [" + this.host + ":" + this.port +"]"; 109 if (validate()) { 112 InstanceProperties ip = InstanceProperties. 113 createInstanceProperties(url, username, password, 114 displayName); 115 ip.setProperty(WSDeploymentFactory.SERVER_ROOT_ATTR, serverRoot); 116 ip.setProperty(WSDeploymentFactory.DOMAIN_ROOT_ATTR, domainRoot); 117 ip.setProperty(WSDeploymentFactory.IS_LOCAL_ATTR, isLocal); 118 ip.setProperty(WSDeploymentFactory.SERVER_NAME_ATTR, serverName); 119 ip.setProperty(WSDeploymentFactory.DEBUGGER_PORT_ATTR, 120 DEFAULT_DEBUGGER_PORT); 121 ip.setProperty(WSDeploymentFactory.CONFIG_XML_PATH, configXmlPath); 122 ip.setProperty(WSDeploymentFactory.ADMIN_PORT_ATTR, adminPort); 123 ip.setProperty(WSDeploymentFactory.DEFAULT_HOST_PORT_ATTR, defaultHostPort); 124 125 result.add(ip); 127 128 return result; 130 } else { 131 return null; 132 } 133 } 134 135 141 private boolean validate() { 142 try { 146 new Socket(getHost(), new Integer (getPort()).intValue()); 147 } catch (UnknownHostException e) { 148 JOptionPane.showMessageDialog(serverPropertiesPanel, 149 NbBundle.getMessage(WSInstantiatingIterator.class, 150 "MSG_unknownHost", getHost()), 151 NbBundle.getMessage(WSInstantiatingIterator.class, 152 "MSG_instanceCreationFailed"), JOptionPane.ERROR_MESSAGE); 153 return false; 154 } catch (IOException e) { 155 } 158 159 return true; 161 } 162 163 168 private String getDisplayName() { 169 return (String ) wizardDescriptor.getProperty(PROP_DISPLAY_NAME); 170 } 171 172 private String serverRoot; 174 private String domainRoot; 175 private String isLocal; 176 private String host; 177 private String port; 178 private String username; 179 private String password; 180 private String serverName; 181 private String configXmlPath; 182 private String adminPort; 183 private String defaultHostPort; 184 189 public void setServerRoot(String serverRoot) { 190 this.serverRoot = serverRoot; 191 192 serverPropertiesPanel.getWizardServerProperties(). 194 updateInstancesList(serverRoot); 195 } 196 197 202 public String getServerRoot() { 203 return this.serverRoot; 204 } 205 206 211 public void setDomainRoot(String domainRoot) { 212 this.domainRoot = domainRoot; 213 } 214 215 220 public String getDomainRoot() { 221 return domainRoot; 222 } 223 224 229 public String getHost() { 230 return host; 231 } 232 233 238 public void setHost(String host) { 239 this.host = host; 240 } 241 242 247 public String getPort() { 248 return port; 249 } 250 251 256 public void setPort(String port) { 257 this.port = port; 258 } 259 260 265 public String getUsername() { 266 return username; 267 } 268 269 274 public void setUsername(String username) { 275 this.username = username; 276 } 277 278 283 public String getPassword() { 284 return password; 285 } 286 287 292 public void setPassword(String password) { 293 this.password = password; 294 } 295 296 301 public String getIsLocal() { 302 return this.isLocal; 303 } 304 305 310 public void setIsLocal(String isLocal) { 311 this.isLocal = isLocal; 312 } 313 314 319 public String getServerName() { 320 return this.serverName; 321 } 322 323 328 public void setServerName(String serverName) { 329 this.serverName = serverName; 330 } 331 332 337 public String getConfigXmlPath() { 338 return this.configXmlPath; 339 } 340 341 346 public void setConfigXmlPath(String configXmlPath) { 347 this.configXmlPath = configXmlPath; 348 } 349 350 public String getAdminPort() { 351 return adminPort; 352 } 353 354 public void setAdminPort(String adminPort) { 355 this.adminPort = adminPort; 356 } 357 358 public String getDefaultHostPort() { 359 return defaultHostPort; 360 } 361 362 public void setDefaultHostPort(String defaultHostPort) { 363 this.defaultHostPort = defaultHostPort; 364 } 365 366 372 private Vector steps = new Vector(); 373 { 374 steps.add(NbBundle.getMessage(ServerPropertiesPanel.class, 375 "SERVER_LOCATION_STEP")); steps.add(NbBundle.getMessage(ServerPropertiesPanel.class, 377 "SERVER_PROPERTIES_STEP")); } 379 380 383 private Vector panels = new Vector(); 384 private ServerLocationPanel serverLocationPanel = 385 new ServerLocationPanel( 386 (String []) steps.toArray(new String [steps.size()]), 387 0, 388 new IteratorListener(), this); 389 private ServerPropertiesPanel serverPropertiesPanel = 390 new ServerPropertiesPanel( 391 (String []) steps.toArray(new String [steps.size()]), 392 1, 393 new IteratorListener(), this); 394 { 395 panels.add(serverLocationPanel); 396 panels.add(serverPropertiesPanel); 397 } 398 399 402 private int index; 403 404 408 public boolean hasPrevious() { 409 return index > 0; 410 } 411 412 417 public void previousPanel() { 418 419 if (!hasPrevious()) { 420 throw new NoSuchElementException(); 421 } 422 index--; 423 } 424 425 429 public boolean hasNext() { 430 return index < panels.size() - 1; 431 } 432 433 438 public void nextPanel() { 439 if (!hasNext()) { 440 throw new NoSuchElementException(); 441 } 442 index++; 443 } 444 445 450 public WizardDescriptor.Panel current() { 451 return (WizardDescriptor.Panel) panels.get(index); 452 } 453 454 460 private Vector listeners = new Vector(); 461 462 467 public void removeChangeListener(ChangeListener listener) { 468 if (listeners != null) { 469 synchronized (listeners) { 470 listeners.remove(listener); 471 } 472 } 473 } 474 475 480 public void addChangeListener(ChangeListener listener) { 481 synchronized (listeners) { 482 listeners.add(listener); 483 } 484 } 485 486 491 private void fireChangeEvent(ChangeEvent event) { 492 Vector targetListeners; 495 synchronized (listeners) { 496 targetListeners = (Vector) listeners.clone(); 497 } 498 499 for (int i = 0; i < targetListeners.size(); i++) { 501 ChangeListener listener = 502 (ChangeListener) targetListeners.elementAt(i); 503 listener.stateChanged(event); 504 } 505 } 506 507 513 private class IteratorListener implements ChangeListener { 514 519 public void stateChanged(ChangeEvent event) { 520 fireChangeEvent(event); 521 } 522 } 523 } 524 | Popular Tags |