1 19 20 package org.netbeans.modules.j2ee.oc4j.ui.wizards; 21 22 import java.awt.Component ; 23 import java.net.InetAddress ; 24 import java.net.InetSocketAddress ; 25 import java.net.UnknownHostException ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.Set ; 29 import javax.swing.event.ChangeEvent ; 30 import javax.swing.event.ChangeListener ; 31 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties; 32 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginUtils; 33 import org.openide.WizardDescriptor; 34 import org.openide.util.HelpCtx; 35 import org.openide.util.NbBundle; 36 37 40 public class AddServerPropertiesPanel implements WizardDescriptor.Panel, ChangeListener { 41 42 private final static String PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; private WizardDescriptor wizard; 44 private AddServerPropertiesVisualPanel component; 45 private OC4JInstantiatingIterator instantiatingIterator; 46 private transient Set <ChangeListener > listeners = new HashSet <ChangeListener >(1); 47 48 49 public AddServerPropertiesPanel(OC4JInstantiatingIterator instantiatingIterator) { 50 this.instantiatingIterator = instantiatingIterator; 51 } 52 53 public boolean isValid() { 54 AddServerPropertiesVisualPanel panel = (AddServerPropertiesVisualPanel)getComponent(); 55 56 if (panel.getType().equals(AddServerPropertiesVisualPanel.LOCAL)) { 57 if(!OC4JPluginUtils.isUserActivated(instantiatingIterator.getOC4JHomeLocation(), "oc4jadmin")) { 58 panel.setInitialization(true); 59 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_Initialization")); 60 return false; 61 } 62 } 63 64 if(panel.getHost().length() == 0 || 65 panel.getUser().length() == 0 || 66 panel.getPassword().length() == 0 || 67 panel.getWebSite().length() == 0 ) { 68 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_MissingData")); 69 return false; 70 } 71 72 try { 73 new Integer (panel.getPort()); 74 new Integer (panel.getAdminPort()); 75 76 String host = panel.getHost(); 77 78 if(OC4JPluginProperties.isRunning(host, panel.getPort()) 79 && !OC4JPluginProperties.isRunning(host, panel.getAdminPort()) 80 || !OC4JPluginProperties.isRunning(host, panel.getPort()) 81 && OC4JPluginProperties.isRunning(host, panel.getAdminPort())) 82 throw new NumberFormatException (); 83 84 } catch(NumberFormatException ex) { 85 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, 86 "MSG_WrongPort", panel.getHost())); 87 return false; 88 } 89 90 if (panel.getType().equals(AddServerPropertiesVisualPanel.REMOTE)) { 91 try { 92 InetAddress ia = InetAddress.getByName(panel.getHost()); 93 new InetSocketAddress (ia, Integer.parseInt(panel.getAdminPort())); 94 } catch (UnknownHostException uhe) { 95 wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(AddServerPropertiesPanel.class, 96 "MSG_UnknownHost",panel.getHost())); 97 return false; 98 } catch (IllegalArgumentException iae) { 99 wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(AddServerPropertiesPanel.class, 100 "Msg_ValidPortNumber")); 101 return false; 102 } 103 } 104 105 wizard.putProperty(PROP_ERROR_MESSAGE,null); 106 instantiatingIterator.setHost(panel.getHost()); 107 instantiatingIterator.setPassword(panel.getPassword()); 108 instantiatingIterator.setUserName(panel.getUser()); 109 instantiatingIterator.setWebSite(panel.getWebSite()); 110 instantiatingIterator.setAdminPort(new Integer (panel.getAdminPort())); 111 instantiatingIterator.setHttpPort(new Integer (panel.getPort())); 112 return true; 113 } 114 115 public Component getComponent() { 116 if (component == null) { 117 component = new AddServerPropertiesVisualPanel(instantiatingIterator.getOC4JHomeLocation()); 118 component.addChangeListener(this); 119 } 120 return component; 121 } 122 123 public void stateChanged(ChangeEvent ev) { 124 fireChangeEvent(ev); 125 } 126 127 private void fireChangeEvent(ChangeEvent ev) { 128 Iterator it; 129 synchronized (listeners) { 130 it = new HashSet <ChangeListener >(listeners).iterator(); 131 } 132 while (it.hasNext()) { 133 ((ChangeListener )it.next()).stateChanged(ev); 134 } 135 } 136 137 138 public void removeChangeListener(ChangeListener l) { 139 synchronized (listeners) { 140 listeners.remove(l); 141 } 142 } 143 144 public void addChangeListener(ChangeListener l) { 145 synchronized (listeners) { 146 listeners.add(l); 147 } 148 } 149 150 public void readSettings(Object settings) { 151 if (wizard == null) 152 wizard = (WizardDescriptor)settings; 153 } 154 155 public void storeSettings(Object settings) { 156 } 157 158 public HelpCtx getHelp() { 159 return new HelpCtx("j2eeplugins_registering_app_server_oc4j_properties"); } 161 } | Popular Tags |