[376506] New Server wizard doesn't block user from creating server with
existing name
diff --git a/features/org.eclipse.wst.server_ui.feature/feature.xml b/features/org.eclipse.wst.server_ui.feature/feature.xml
index da77fba..f426f9c 100644
--- a/features/org.eclipse.wst.server_ui.feature/feature.xml
+++ b/features/org.eclipse.wst.server_ui.feature/feature.xml
@@ -1,58 +1,58 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<feature
-      id="org.eclipse.wst.server_ui.feature"
-      label="%featureName"
-      version="3.3.100.qualifier"
-      provider-name="%providerName"
-      license-feature="org.eclipse.license"
-      license-feature-version="1.0.0.qualifier">
-
-   <description>
-      %description
-   </description>
-
-   <copyright>
-      %copyright
-   </copyright>
-
-   <license url="%licenseURL">
-      %license
-   </license>
-
-   <includes
-         id="org.eclipse.wst.server_userdoc.feature"
-         version="0.0.0"/>
-
-   <includes
-         id="org.eclipse.wst.server_core.feature"
-         version="0.0.0"/>
-
-   <plugin
-         id="org.eclipse.wst.internet.monitor.ui"
-         download-size="0"
-         install-size="0"
-         version="0.0.0"
-         unpack="false"/>
-
-   <plugin
-         id="org.eclipse.wst.server.ui.infopop"
-         download-size="0"
-         install-size="0"
-         version="0.0.0"
-         unpack="false"/>
-
-   <plugin
-         id="org.eclipse.wst.server.ui"
-         download-size="0"
-         install-size="0"
-         version="0.0.0"
-         unpack="false"/>
-
-   <plugin
-         id="org.eclipse.wst.server.discovery"
-         download-size="0"
-         install-size="0"
-         version="0.0.0"
-         unpack="false"/>
-
-</feature>
+<?xml version="1.0" encoding="UTF-8"?>

+<feature

+      id="org.eclipse.wst.server_ui.feature"

+      label="%featureName"

+      version="3.3.101.qualifier"

+      provider-name="%providerName"

+      license-feature="org.eclipse.license"

+      license-feature-version="1.0.0.qualifier">

+

+   <description>

+      %description

+   </description>

+

+   <copyright>

+      %copyright

+   </copyright>

+

+   <license url="%licenseURL">

+      %license

+   </license>

+

+   <includes

+         id="org.eclipse.wst.server_userdoc.feature"

+         version="0.0.0"/>

+

+   <includes

+         id="org.eclipse.wst.server_core.feature"

+         version="0.0.0"/>

+

+   <plugin

+         id="org.eclipse.wst.internet.monitor.ui"

+         download-size="0"

+         install-size="0"

+         version="0.0.0"

+         unpack="false"/>

+

+   <plugin

+         id="org.eclipse.wst.server.ui.infopop"

+         download-size="0"

+         install-size="0"

+         version="0.0.0"

+         unpack="false"/>

+

+   <plugin

+         id="org.eclipse.wst.server.ui"

+         download-size="0"

+         install-size="0"

+         version="0.0.0"

+         unpack="false"/>

+

+   <plugin

+         id="org.eclipse.wst.server.discovery"

+         download-size="0"

+         install-size="0"

+         version="0.0.0"

+         unpack="false"/>

+

+</feature>

diff --git a/plugins/org.eclipse.wst.server.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.wst.server.ui/META-INF/MANIFEST.MF
index 0448804..4127d5b 100644
--- a/plugins/org.eclipse.wst.server.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.wst.server.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.wst.server.ui; singleton:=true
-Bundle-Version: 1.4.0.qualifier
+Bundle-Version: 1.4.1.qualifier
 Bundle-Activator: org.eclipse.wst.server.ui.internal.ServerUIPlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.java
index af8285e..a48ac33 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.java
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -268,6 +268,7 @@
 	public static String editorRenameFiles;
 	public static String errorEditorCantSave;
 	public static String errorDuplicateName;
+	public static String errorDuplicateServerName;
 	public static String editorReadOnly;
 	public static String editorWritable;
 	public static String editorResourceModifiedTitle;
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.properties b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.properties
index cb9ff0b..7304db5 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.properties
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2004, 2011 IBM Corporation and others.
+# Copyright (c) 2004, 2012 IBM Corporation and others.
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License v1.0
 # which accompanies this distribution, and is available at
@@ -401,6 +401,7 @@
 errorConfigurationNotAccessible=The server configuration is not accessible. The {0} project is closed.
 errorRootModule=Could not find a valid parent module to add to the server.
 errorDuplicateName=The name is already in use. Specify a different name.
+errorDuplicateServerName=The server name is already in use. Specify a different name.
 
 # Info messages
 infoNoRuntimesFound=No new server runtime environments were found.
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/fragment/NewServerWizardFragment.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/fragment/NewServerWizardFragment.java
index 5747e58..ba6c982 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/fragment/NewServerWizardFragment.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/fragment/NewServerWizardFragment.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2011 IBM Corporation and others.
+ * Copyright (c) 2003, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -149,10 +149,15 @@
 		if(getServer().getServerType() == null)
 			return false;
 		
-		return checkHostAndServerType();
+		return checkValidInput();
 	}
 	
-	private boolean checkHostAndServerType(){
+	/*
+	 * Checks for valid host name, server type, and server name
+	 * 
+	 * @return true if input is valid, false otherwise
+	 */
+	private boolean checkValidInput(){
 		boolean isComplete = false;
 
 		boolean supportsRemote = getServer().getServerType().supportsRemoteHosts();
@@ -165,6 +170,10 @@
 					return false;
 				}
 				
+				if (manualComp.isServerNameInUse()){
+					return false;
+				}
+				
 				if (manualComp.getCurrentHostname().trim().length() == 0){
 					isComplete = false;
 				} else if(!supportsRemote && !SocketUtil.isLocalhost(manualComp.getCurrentHostname())){
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/page/NewManualServerComposite.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/page/NewManualServerComposite.java
index 9b33496..45a26d8 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/page/NewManualServerComposite.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/wizard/page/NewManualServerComposite.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2011 IBM Corporation and others.
+ * Copyright (c) 2003, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -40,6 +40,7 @@
 import org.eclipse.ui.dialogs.PreferencesUtil;
 import org.eclipse.ui.help.IWorkbenchHelpSystem;
 import org.eclipse.wst.server.core.*;
+import org.eclipse.wst.server.core.internal.ServerPlugin;
 import org.eclipse.wst.server.core.internal.ServerWorkingCopy;
 import org.eclipse.wst.server.core.util.SocketUtil;
 import org.eclipse.wst.server.ui.AbstractUIControl;
@@ -110,6 +111,10 @@
 	
 	private boolean canSupportModule=true;
 
+	// These variables deal with caching server name checks
+	private boolean isServerNameInUse=false;
+	private String cacheServerNameCheck="";
+	
 	/**
 	 * Creates a new server and server configuration.  If the initial
 	 * resource selection contains exactly one container resource then it will be
@@ -236,6 +241,13 @@
 					return;
 				
 				String name = serverName.getText();
+								
+				IServerType selectedServerType = serverTypeComposite.getSelectedServerType();
+				if (validate(selectedServerType)) {
+					// Do not set the server name if it is invalid
+					return;			
+				}
+				
 				if (server != null) {
 					server.setName(name);
 					IRuntime runtime2 = server.getRuntime();
@@ -392,7 +404,7 @@
 	protected void handleHostnameChange(IServerType serverType) {
 
 		wizard.setMessage(null, IMessageProvider.NONE);
-		if (!checkHostAndServerType(serverType)) {
+		if (!validate(serverType)) {
 			return;// Host name validation failed, so there is no need to continue handling hostname change event			
 		}
 		loadServerImpl(serverType);
@@ -438,10 +450,23 @@
 			wizard.setMessage(NLS.bind(Messages.wizCheckRemoteSupport, new Object[0]), IMessageProvider.ERROR);
 			return false;
 		}
-		
+
 		return true;
 	}
 	
+	protected boolean checkServerName(){		
+		if (isServerNameInUse()){
+			wizard.setMessage(Messages.errorDuplicateServerName, IMessageProvider.ERROR);
+			return false;			
+		}
+		return true;
+	}
+	
+	protected boolean validate(IServerType selectedServerType){
+		wizard.setMessage(null, IMessageProvider.NONE);
+		return (checkHostAndServerType(selectedServerType) & checkServerName());
+	}
+	
 	/**
 	 * Load a server of the given type.
 	 */
@@ -723,7 +748,7 @@
 		// Update the old server type value.
 		oldServerType = serverType;
 
-		checkHostAndServerType(serverType);
+		validate(serverType);
 		wizard.update();
 	}
 
@@ -883,4 +908,28 @@
 			hostName = host;
 		}
 	}
+	
+	/**
+	 * Determines if the server name is in use. The server name that is checked
+	 * is cached to increase performance on multiple calls. 
+	 * 
+	 * @return true if name is in use, false otherwise
+	 */
+	public boolean isServerNameInUse(){
+		String myServerName="";
+		if (serverName != null){
+			myServerName = serverName.getText().trim();
+			// If the server name is equal to the cached server name, then return the
+			// previously cached value. If the server name is not equal to the cached
+			// server name, check to see if the name is in use
+			if (!cacheServerNameCheck.equals(myServerName)){
+				cacheServerNameCheck = myServerName;
+				isServerNameInUse = ServerPlugin.isNameInUse(server, serverName.getText().trim());				
+			}
+			return isServerNameInUse;			
+		}
+
+		// If the widget is null, return false
+		return false;
+	}	
 }
\ No newline at end of file