1 19 package org.netbeans.modules.j2ee.sun.ide.j2ee.ui; 20 21 import java.awt.Component ; 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.IOException ; 25 import java.util.Enumeration ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.Properties ; 29 import java.util.Set ; 30 import javax.swing.event.ChangeEvent ; 31 import javax.swing.event.ChangeListener ; 32 import org.netbeans.modules.j2ee.sun.api.ServerLocationManager; 33 import org.openide.ErrorManager; 34 import org.openide.WizardDescriptor; 35 import org.openide.util.HelpCtx; 36 import org.openide.util.NbBundle; 37 38 41 class AddDomainPlatformPanel implements WizardDescriptor.FinishablePanel, 42 ChangeListener { 43 44 48 private AddInstanceVisualPlatformPanel component; 49 private WizardDescriptor wiz; 50 51 56 public Component getComponent() { 57 if (component == null) { 58 File f = ServerLocationManager.getLatestPlatformLocation(); 59 File defaultLoc = null; 60 if (null == f || !f.exists()) { 61 String prop = System.getProperty(ServerLocationManager.INSTALL_ROOT_PROP_NAME); 62 if (null != prop && prop.length() > 0) { 63 File installRoot = new File (prop); 65 if (ServerLocationManager.isGoodAppServerLocation(installRoot)) { 66 defaultLoc = installRoot; 67 } 68 } 69 if (null == defaultLoc) { 70 defaultLoc = new File (System.getProperty("user.home")); } 72 } else { 73 defaultLoc = f; 74 } 75 component = new AddInstanceVisualPlatformPanel(defaultLoc); 76 component.addChangeListener(this); 77 } 78 return component; 79 } 80 81 public HelpCtx getHelp() { 82 return new HelpCtx("AS_RegServ_EnterPlatformDir"); } 84 85 97 public boolean isValid() { 98 boolean retVal = true; 99 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, null); 100 String instLoc = component.getInstallLocation(); 101 if (instLoc.startsWith("\\\\")) { 102 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 103 NbBundle.getMessage(AddDomainPlatformPanel.class, 104 "Msg_NoAuthorityComponent")); retVal = false; 106 } 107 File location = new File (component.getInstallLocation()); 108 if (retVal && !ServerLocationManager.isGoodAppServerLocation(location)) { 109 Object selectedType = component.getSelectedType(); 110 if (selectedType == AddDomainWizardIterator.REMOTE){ 111 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 112 NbBundle.getMessage(AddDomainPlatformPanel.class, 113 "Msg_NeedValidInstallEvenForRemote")); 114 }else{ 115 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 117 NbBundle.getMessage(AddDomainPlatformPanel.class, 118 "Msg_InValidInstall")); } 120 component.setDomainsList(new Object [0]); 121 retVal = false; 122 } else if (retVal) { 123 Object oldPlatformLoc = wiz.getProperty(AddDomainWizardIterator.PLATFORM_LOCATION); 124 if (!location.equals(oldPlatformLoc) || component.getDomainsListModel().getSize() < 1) { 125 Object [] domainsList = getDomainList(Util.getRegisterableDefaultDomains(location)); 126 component.setDomainsList(domainsList); 127 } 128 if (ServerLocationManager.isGlassFish(location)) { 130 String javaClassVersion = 131 System.getProperty("java.class.version"); double jcv = Double.parseDouble(javaClassVersion); 133 if (jcv < 49.0) { 134 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 136 NbBundle.getMessage(AddDomainPlatformPanel.class, 137 "Msg_RequireJ2SE5")); retVal = false; 139 } 140 } 141 } 142 if (retVal) { 143 wiz.putProperty(AddDomainWizardIterator.PLATFORM_LOCATION,location); 144 wiz.putProperty(AddDomainWizardIterator.USER_NAME, 145 AddDomainWizardIterator.BLANK); 146 wiz.putProperty(AddDomainWizardIterator.PASSWORD, 147 AddDomainWizardIterator.BLANK); 148 Object selectedType = component.getSelectedType(); 149 if (selectedType == AddDomainWizardIterator.DEFAULT) { 150 File [] usableDomains = Util.getRegisterableDefaultDomains(location); 151 if (usableDomains.length == 0) { 152 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 153 NbBundle.getMessage(AddDomainPlatformPanel.class, 154 "Msg_NoDefaultDomainsAvailable")); retVal = false; 156 } 157 wiz.putProperty(AddDomainWizardIterator.TYPE, selectedType); 158 String dirCandidate = component.getDomainDir(); 159 if (null != dirCandidate) { 160 File domainDir = new File (dirCandidate); 161 if (!Util.rootOfUsableDomain(domainDir)) { 164 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 165 NbBundle.getMessage(AddDomainPlatformPanel.class, 166 "Msg_InValidDomainDir", component.getDomainDir())); 168 retVal = false; 169 } else { 170 Util.fillDescriptorFromDomainXml(wiz, domainDir); 172 String username = "admin"; 174 String password = null; 175 File f = new File (System.getProperty("user.home")+"/.asadminprefs"); if (f.exists()){ 177 FileInputStream fis = null; 178 try{ 179 180 fis = new FileInputStream (f); 181 Properties p = new Properties (); 182 p.load(fis); 183 fis.close(); 184 185 Enumeration e = p.propertyNames() ; 186 for ( ; e.hasMoreElements() ;) { 187 String v = (String )e.nextElement(); 188 if (v.equals("AS_ADMIN_USER")) username = p.getProperty(v ); 190 else if (v.equals("AS_ADMIN_PASSWORD")){ password = p.getProperty(v ); 192 } 193 } 194 195 } catch (Exception e){ 196 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 197 e); 198 } finally { 199 if (null != fis) { 200 try { 201 fis.close(); 202 } catch (IOException ex) { 203 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 204 ex); 205 } 206 } 207 } 208 } 209 wiz.putProperty(AddDomainWizardIterator.PASSWORD, password); 210 wiz.putProperty(AddDomainWizardIterator.USER_NAME,username); 211 } 212 } else { 213 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 214 NbBundle.getMessage(AddDomainPlatformPanel.class, 215 "Msg_NoDefaultDomainsAvailable")); retVal = false; 217 } 218 } else if (selectedType == AddDomainWizardIterator.REMOTE) { 219 wiz.putProperty(AddDomainWizardIterator.TYPE, selectedType); 220 wiz.putProperty(AddDomainWizardIterator.INSTALL_LOCATION,""); 221 wiz.putProperty(AddDomainWizardIterator.DOMAIN,""); 222 } else if (selectedType == AddDomainWizardIterator.LOCAL) { 223 wiz.putProperty(AddDomainWizardIterator.TYPE, selectedType); 224 } else if (selectedType == AddDomainWizardIterator.PERSONAL) { 225 wiz.putProperty(AddDomainWizardIterator.TYPE, selectedType); 226 } else { 227 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, 228 NbBundle.getMessage(AddDomainPlatformPanel.class, 229 "Msg_UnsupportedType")); retVal = false; 231 } 232 } 233 return retVal; 234 } 235 236 private Object [] getDomainList(File [] dirs){ 237 return getServerList(dirs); 238 } 239 240 private Object [] getServerList(File [] dirs){ 241 java.util.List xmlList = new java.util.ArrayList (); 242 Object retVal[] = null; 243 File platformDir = (File ) wiz.getProperty(AddDomainWizardIterator.PLATFORM_LOCATION); 244 for(int i=0; platformDir != null && i<dirs.length; i++){ 245 String hostPort = Util.getHostPort(dirs[i],platformDir); 246 if(hostPort != null) { 247 xmlList.add( 248 NbBundle.getMessage(AddDomainPlatformPanel.class, 249 "LBL_domainListEntry", new Object [] {hostPort,dirs[i].toString()})); 250 } 251 } if(xmlList != null) { 253 retVal = xmlList.toArray(); 254 } 255 return retVal; 256 } 257 258 private final Set listeners = new HashSet (1); 260 public final void addChangeListener(ChangeListener l) { 261 synchronized (listeners) { 262 listeners.add(l); 263 } 264 } 265 public final void removeChangeListener(ChangeListener l) { 266 synchronized (listeners) { 267 listeners.remove(l); 268 } 269 } 270 protected final void fireChangeEvent() { 271 Iterator it; 272 synchronized (listeners) { 273 it = new HashSet (listeners).iterator(); 274 } 275 ChangeEvent ev = new ChangeEvent (this); 276 while (it.hasNext()) { 278 ChangeListener l = (ChangeListener ) it.next(); 279 l.stateChanged(ev); 281 } 282 } 283 284 285 public void readSettings(Object settings) { 290 wiz = (WizardDescriptor) settings; 291 } 292 public void storeSettings(Object settings) { 293 } 295 296 public void stateChanged(ChangeEvent e) { 297 wiz.putProperty(AddDomainWizardIterator.TYPE, component.getSelectedType()); 299 fireChangeEvent(); } 301 302 public boolean isFinishPanel() { 303 Object selectedType = component.getSelectedType(); 304 return selectedType == AddDomainWizardIterator.DEFAULT; 305 } 306 } 307 308 | Popular Tags |