[378175] Service project and service project type need to be refreshed
when web service target runtime changes
diff --git a/bundles/org.eclipse.jst.ws.consumption.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.jst.ws.consumption.ui/META-INF/MANIFEST.MF
index fda37fb..48aee70 100644
--- a/bundles/org.eclipse.jst.ws.consumption.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.jst.ws.consumption.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %PLUGIN_NAME
 Bundle-SymbolicName: org.eclipse.jst.ws.consumption.ui; singleton:=true
-Bundle-Version: 1.1.600.qualifier
+Bundle-Version: 1.1.700.qualifier
 Bundle-Activator: org.eclipse.jst.ws.internal.consumption.ui.plugin.WebServiceConsumptionUIPlugin
 Bundle-Vendor: %PLUGIN_PROVIDER
 Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.jst.ws.consumption.ui/src/org/eclipse/jst/ws/internal/consumption/ui/wsrt/FacetMatchCache.java b/bundles/org.eclipse.jst.ws.consumption.ui/src/org/eclipse/jst/ws/internal/consumption/ui/wsrt/FacetMatchCache.java
index b3f51e5..b6ee794 100644
--- a/bundles/org.eclipse.jst.ws.consumption.ui/src/org/eclipse/jst/ws/internal/consumption/ui/wsrt/FacetMatchCache.java
+++ b/bundles/org.eclipse.jst.ws.consumption.ui/src/org/eclipse/jst/ws/internal/consumption/ui/wsrt/FacetMatchCache.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * Copyright (c) 2006, 2013 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
@@ -14,6 +14,7 @@
  * 20060427   126780 rsinha@ca.ibm.com - Rupam Kuehner
  * 20080923   247525 mahutch@ca.ibm.com - Mark Hutchinson, cache not updated properly when project facet versions changed
  * 20100811   322429 mahutch@ca.ibm.com - Mark Hutchinson, Improve performance of launching the Web Services Wizard
+ * 20130225   378160 jcayne@ca.ibm.com - Joel Cayne, Return empty set for template when no service ID is provided.
  *******************************************************************************/
 package org.eclipse.jst.ws.internal.consumption.ui.wsrt;
 
@@ -444,6 +445,8 @@
    */  
   public synchronized Set getTemplatesForServiceRuntime(String serviceRuntimeId)
   {
+	if(serviceRuntimeId.length() == 0)
+		return new HashSet<String>();
     Set templates = (Set)templatesByServiceRuntimeId_.get(serviceRuntimeId);
     if (templates != null)
     {
diff --git a/bundles/org.eclipse.jst.ws.creation.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.jst.ws.creation.ui/META-INF/MANIFEST.MF
index bfe27d7..80a7d93 100644
--- a/bundles/org.eclipse.jst.ws.creation.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.jst.ws.creation.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %PLUGIN_NAME
 Bundle-SymbolicName: org.eclipse.jst.ws.creation.ui; singleton:=true
-Bundle-Version: 1.0.700.qualifier
+Bundle-Version: 1.0.800.qualifier
 Bundle-Activator: org.eclipse.jst.ws.internal.creation.ui.plugin.WebServiceCreationUIPlugin
 Bundle-Vendor: %PLUGIN_PROVIDER
 Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/widgets/ServerWizardWidget.java b/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/widgets/ServerWizardWidget.java
index 4cea165..e504b69 100644
--- a/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/widgets/ServerWizardWidget.java
+++ b/bundles/org.eclipse.jst.ws.creation.ui/src/org/eclipse/jst/ws/internal/creation/ui/widgets/ServerWizardWidget.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2013 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
@@ -64,11 +64,14 @@
  * 20090313   268567 ericdp@ca.ibm.com - Eric D. Peters, persisted wizard settings gone unless launching on object
  * 20090326   269097 kchong@ca.ibm.com - Keith Chong, [Accessibility] Web services wizard dialog should be selected after canceling the Browse for class dialog
  * 20100511   309395 mahutch@ca.ibm.com - Mark Hutchinson, WS Wizard Converting Java Project into Utility Project without any warning
+ * 20120501   378160 jenyoung@ca.ibm.com - Jennifer Young, Service project and service project type need to be refreshed when web service target runtime changes
+ * 20130225   378160 jcayne@ca.ibm.com - Joel Cayne, Updates for refreshing server project type.
  *******************************************************************************/
 package org.eclipse.jst.ws.internal.creation.ui.widgets;
 
 
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.dialogs.Dialog;
@@ -80,6 +83,7 @@
 import org.eclipse.jst.ws.internal.consumption.ui.common.DefaultingUtils;
 import org.eclipse.jst.ws.internal.consumption.ui.common.ValidationUtils;
 import org.eclipse.jst.ws.internal.consumption.ui.plugin.WebServiceConsumptionUIPlugin;
+import org.eclipse.jst.ws.internal.consumption.ui.preferences.ProjectTopologyContext;
 import org.eclipse.jst.ws.internal.consumption.ui.widgets.IObjectSelectionLaunchable;
 import org.eclipse.jst.ws.internal.consumption.ui.widgets.IPackable;
 import org.eclipse.jst.ws.internal.consumption.ui.widgets.ProjectSelectionDialog;
@@ -734,7 +738,8 @@
 			if (!currentServiceTRS.equals(newServiceTRS))
 			{
 				setServiceTypeRuntimeServer(newServiceTRS);	
-				refreshClientServerRuntimeSelection();	
+				refreshServiceProjectType();
+				refreshClientServerRuntimeSelection();
 				validationState_ = (new ValidationUtils()).getNewValidationState(validationState_, ValidationUtils.VALIDATE_SERVER_RUNTIME_CHANGES);
 				clientWidget_.setValidationState(ValidationUtils.VALIDATE_SERVER_RUNTIME_CHANGES);
 				statusListener_.handleEvent(null); //Revalidate the page since server/runtime selections changed.
@@ -743,6 +748,62 @@
 		}		
 	}	
 	
+	/**
+	 * Update the service project type
+	 */
+	private void refreshServiceProjectType(){
+			
+		IProject serviceProject = ResourcesPlugin.getWorkspace().getRoot().getProject(getServiceProjectName());
+		if (!serviceProject.exists())
+		{
+			// Set the project template
+			setServiceComponentType(getDefaultServiceProjectTemplate());
+		}
+		else
+		{
+			//Set it to an empty String
+			setServiceComponentType("");
+		}
+    }
+	
+
+	
+	/*
+	 * Computes an acceptable value for the service project type based on the 
+	 * current runtime
+	 * @return A default value for the service project type
+	*/
+	private String getDefaultServiceProjectTemplate()
+	{
+		String serviceTypeId = getServiceTypeRuntimeServer().getTypeId();  
+		String serviceRuntimeId = getServiceTypeRuntimeServer().getRuntimeId();
+		String serviceServerId = getServiceTypeRuntimeServer().getServerId();
+	    String[] templates = WebServiceRuntimeExtensionUtils2.getServiceProjectTemplates(serviceTypeId, serviceRuntimeId, serviceServerId);
+	    String oldServiceComponentType = getServiceComponentType();
+	    for(String templateId : templates) {
+	    	if(templateId.equals(oldServiceComponentType))
+	    		return templateId;
+	    }
+	    
+	    //Walk the list of service project types in the project topology preference
+	    ProjectTopologyContext ptc= WebServiceConsumptionUIPlugin.getInstance().getProjectTopologyContext();
+	    String[] preferredTemplateIds = ptc.getServiceTypes();
+	    
+	    for (int j = 0; j < preferredTemplateIds.length; j++)
+	    {
+	      for (int i = 0; i < templates.length; i++)
+	      {
+	        String templateId = templates[i];
+	        if (templateId.equals(preferredTemplateIds[j]))
+	        {
+	            return templates[i];
+	        }
+	      }
+	    }
+	    // No supported template was found that matched a runtime.
+	    return "";   
+	}
+	
 	public void setClientTypeRuntimeServer(TypeRuntimeServer ids) {
 		clientWidget_.setTypeRuntimeServer( ids );
 	}