Bug 460967 - Use type safe service retrieving

Instead of retrieving services based on their String class name there is
newer implementation that takes the class directly and returns the
correct class preventing casts.

Change-Id: I817c47b702001b739a07a54f4fd8dd72ae9750aa
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxBundlesState.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxBundlesState.java
index 74df588..97f044a 100644
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxBundlesState.java
+++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxBundlesState.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2012 IBM Corporation and others.
+ * Copyright (c) 2007, 2015 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
@@ -7,6 +7,7 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Red Hat Inc. - Bug 460967
  *******************************************************************************/
 package org.eclipse.equinox.internal.frameworkadmin.equinox;
 
@@ -165,8 +166,8 @@
 		Properties platformProperties = new Properties();
 		// set default value
 
-		ServiceReference<?> environmentRef = context.getServiceReference(EnvironmentInfo.class);
-		EnvironmentInfo environment = environmentRef == null ? null : (EnvironmentInfo) context.getService(environmentRef);
+		ServiceReference<EnvironmentInfo> environmentRef = context.getServiceReference(EnvironmentInfo.class);
+		EnvironmentInfo environment = environmentRef == null ? null : context.getService(environmentRef);
 		if (environment != null) {
 			try {
 				String nl = Locale.getDefault().toString();
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java
index c8e646f..f850c7c 100644
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java
+++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation and others.
+ * Copyright (c) 2007, 2015 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
@@ -7,7 +7,7 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
- *     Red Hat, Inc - bug 305712
+ *     Red Hat, Inc - bug 305712, bug 460967
  *******************************************************************************/
 package org.eclipse.equinox.internal.frameworkadmin.equinox;
 
@@ -283,8 +283,8 @@
 		}
 		// 2. Create a Manipulator object fully initialized to the current running fw.
 
-		ServiceReference<?> reference = context.getServiceReference(StartLevel.class.getName());
-		StartLevel startLevel = (StartLevel) context.getService(reference);
+		ServiceReference<StartLevel> reference = context.getServiceReference(StartLevel.class);
+		StartLevel startLevel = context.getService(reference);
 		Bundle[] bundles = context.getBundles();
 		BundleInfo[] bInfos = new BundleInfo[bundles.length];
 		for (int i = 0; i < bundles.length; i++) {
diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Activator.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Activator.java
index ac9b6d3..1691d74 100644
--- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Activator.java
+++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Activator.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others.
+ * Copyright (c) 2008, 2015 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
@@ -7,6 +7,7 @@
  * 
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Red Hat Inc. - Bug 460967
  *******************************************************************************/
 package org.eclipse.equinox.internal.frameworkadmin.utils;
 
@@ -40,10 +41,10 @@
 	public static PluginConverter acquirePluginConverter() {
 		if (bundleContext == null)
 			return null;
-		ServiceReference<?> reference = bundleContext.getServiceReference(PluginConverter.class.getName());
+		ServiceReference<PluginConverter> reference = bundleContext.getServiceReference(PluginConverter.class);
 		if (reference == null)
 			return null;
-		PluginConverter result = (PluginConverter) bundleContext.getService(reference);
+		PluginConverter result = bundleContext.getService(reference);
 		bundleContext.ungetService(reference);
 		return result;
 	}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/ProvisioningAgentTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/ProvisioningAgentTest.java
index c6e58dd..10ddb70 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/ProvisioningAgentTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/core/ProvisioningAgentTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2015 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
@@ -7,6 +7,7 @@
  * 
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Red Hat Inc. - Bug 460967
  *******************************************************************************/
 package org.eclipse.equinox.p2.tests.core;
 
@@ -33,8 +34,8 @@
 		URI p2location = getTempFolder().toURI();
 		String PROFILE_ID = "testMultipleAgents";
 
-		ServiceReference providerRef = TestActivator.context.getServiceReference(IProvisioningAgentProvider.class.getName());
-		IProvisioningAgentProvider provider = (IProvisioningAgentProvider) TestActivator.context.getService(providerRef);
+		ServiceReference<IProvisioningAgentProvider> providerRef = TestActivator.context.getServiceReference(IProvisioningAgentProvider.class);
+		IProvisioningAgentProvider provider = TestActivator.context.getService(providerRef);
 
 		IProvisioningAgent firstAgent = provider.createAgent(p2location);
 		IProfileRegistry firstProfileRegistry = (IProfileRegistry) firstAgent.getService(IProfileRegistry.SERVICE_NAME);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/AbstractEnd2EndTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/AbstractEnd2EndTest.java
index c658bc4..e2cdc03 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/AbstractEnd2EndTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/AbstractEnd2EndTest.java
@@ -47,8 +47,8 @@
 	private IProvisioningAgent end2endAgent = null;
 
 	protected void setUp() throws Exception {
-		ServiceReference sr = TestActivator.context.getServiceReference(IProvisioningAgentProvider.SERVICE_NAME);
-		IProvisioningAgentProvider agentFactory = (IProvisioningAgentProvider) TestActivator.context.getService(sr);
+		ServiceReference<IProvisioningAgentProvider> sr = TestActivator.context.getServiceReference(IProvisioningAgentProvider.class);
+		IProvisioningAgentProvider agentFactory = TestActivator.context.getService(sr);
 		end2endAgent = agentFactory.createAgent(getTempFolder().toURI());
 		metadataRepoManager = (IMetadataRepositoryManager) end2endAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
 		artifactRepoManager = (IArtifactRepositoryManager) end2endAgent.getService(IArtifactRepositoryManager.SERVICE_NAME);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/DirectorTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/DirectorTest.java
index 8c1c178..24a8ed4 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/DirectorTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/full/DirectorTest.java
@@ -37,11 +37,11 @@
 public class DirectorTest extends AbstractProvisioningTest {
 
 	public void testInstallIU() {
-		ServiceReference sr = TestActivator.context.getServiceReference(IDirector.SERVICE_NAME);
+		ServiceReference<IDirector> sr = TestActivator.context.getServiceReference(IDirector.class);
 		if (sr == null) {
 			throw new RuntimeException("Director service not available");
 		}
-		IDirector director = (IDirector) TestActivator.context.getService(sr);
+		IDirector director = TestActivator.context.getService(sr);
 		if (director == null) {
 			throw new RuntimeException("Director could not be loaded");
 		}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AllServerTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AllServerTests.java
index 9e0e58f..24c0f0d 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AllServerTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/AllServerTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 Cloudsmith Inc. and others.
+ * Copyright (c) 2009, 2015 Cloudsmith Inc. 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
@@ -7,6 +7,7 @@
  *
  * Contributors:
  *     Cloudsmith Inc - initial API and implementation
+ *     Red Hat Inc. - Bug 460967
  *******************************************************************************/
 package org.eclipse.equinox.p2.tests.metadata.repository;
 
@@ -33,7 +34,7 @@
 	static UIServices hookedAuthDialog;
 	private static ServiceRegistration certificateUIRegistration;
 	private static int setUpCounter = 0;
-	private static ServiceReference packageAdminRef;
+	private static ServiceReference<PackageAdmin> packageAdminRef;
 
 	public static Test suite() throws Exception {
 		final TestSuite suite = new TestSuite("AllServerBasedTestSuite");
@@ -102,8 +103,8 @@
 
 	public static void oneTimeSetUp() throws Exception {
 		BundleContext context = TestActivator.getContext();
-		packageAdminRef = context.getServiceReference(PackageAdmin.class.getName());
-		PackageAdmin pkgAdmin = (PackageAdmin) context.getService(packageAdminRef);
+		packageAdminRef = context.getServiceReference(PackageAdmin.class);
+		PackageAdmin pkgAdmin = context.getService(packageAdminRef);
 
 		// Make sure these are not running
 		stopTransient(pkgAdmin, BUNDLE_EQUINOX_HTTP);
@@ -130,7 +131,7 @@
 	public static void oneTimeTearDown() throws Exception {
 		BundleContext context = TestActivator.getContext();
 		certificateUIRegistration.unregister();
-		PackageAdmin pkgAdmin = (PackageAdmin) context.getService(packageAdminRef);
+		PackageAdmin pkgAdmin = context.getService(packageAdminRef);
 		stopTransient(pkgAdmin, BUNDLE_TESTSERVER);
 		stopTransient(pkgAdmin, BUNDLE_EQUINOX_HTTP);
 		context.ungetService(packageAdminRef);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SynchronizeOperationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SynchronizeOperationTest.java
index 41918d3..dfbe379 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SynchronizeOperationTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SynchronizeOperationTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2011 Sonatype, Inc. and others.
+ *  Copyright (c) 2011, 2015 Sonatype, Inc. 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
@@ -8,6 +8,7 @@
  *  Contributors:
  *     Sonatype, Inc. - initial API and implementation
  *     IBM Corporation - Ongoing development
+ *     Red Hat Inc. - Bug 460967
  *******************************************************************************/
 package org.eclipse.equinox.p2.tests.planner;
 
@@ -34,8 +35,8 @@
 
 	//Directly test the operation
 	public void testSyncOperation() throws ProvisionException {
-		ServiceReference providerRef = TestActivator.context.getServiceReference(IProvisioningAgentProvider.class.getName());
-		IProvisioningAgentProvider provider = (IProvisioningAgentProvider) TestActivator.context.getService(providerRef);
+		ServiceReference<IProvisioningAgentProvider> providerRef = TestActivator.context.getServiceReference(IProvisioningAgentProvider.class);
+		IProvisioningAgentProvider provider = TestActivator.context.getService(providerRef);
 
 		URI p2location = getTestData("p2 location", "testData/synchronizeOperation/p2").toURI();
 		URI repoLocation = getTestData("p2 location", "testData/synchronizeOperation/repo").toURI();
@@ -54,8 +55,8 @@
 
 	//Test a copy of the helper code
 	public void testCopyOfHelper() throws ProvisionException {
-		ServiceReference providerRef = TestActivator.context.getServiceReference(IProvisioningAgentProvider.class.getName());
-		IProvisioningAgentProvider provider = (IProvisioningAgentProvider) TestActivator.context.getService(providerRef);
+		ServiceReference<IProvisioningAgentProvider> providerRef = TestActivator.context.getServiceReference(IProvisioningAgentProvider.class);
+		IProvisioningAgentProvider provider = TestActivator.context.getService(providerRef);
 
 		URI p2location = getTestData("p2 location", "testData/synchronizeOperation/p2").toURI();
 		URI repoLocation = getTestData("p2 location", "testData/synchronizeOperation/repo").toURI();
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/TestServerController.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/TestServerController.java
index 2e1a9e0..f42d574 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/TestServerController.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/testserver/helper/TestServerController.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2009, 2010 Cloudsmith and others.
+ *  Copyright (c) 2009, 2015 Cloudsmith 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
@@ -7,6 +7,7 @@
  * 
  *  Contributors:
  *      Cloudsmith - initial API and implementation
+ *      Red Hat Inc. - Bug 460967
  *******************************************************************************/
 package org.eclipse.equinox.p2.tests.testserver.helper;
 
@@ -34,7 +35,7 @@
 	static UIServices hookedAuthDialog;
 	private static ServiceRegistration certificateUIRegistration;
 	private static int setUpCounter = 0;
-	private static ServiceReference packageAdminRef;
+	private static ServiceReference<PackageAdmin> packageAdminRef;
 
 	private static Bundle getBundle(PackageAdmin packageAdmin, String symbolicName) {
 		Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
@@ -75,8 +76,8 @@
 
 	public static void oneTimeSetUp() throws Exception {
 		BundleContext context = TestActivator.getContext();
-		packageAdminRef = context.getServiceReference(PackageAdmin.class.getName());
-		PackageAdmin pkgAdmin = (PackageAdmin) context.getService(packageAdminRef);
+		packageAdminRef = context.getServiceReference(PackageAdmin.class);
+		PackageAdmin pkgAdmin = context.getService(packageAdminRef);
 
 		// Make sure these are not running
 		stopTransient(pkgAdmin, BUNDLE_EQUINOX_HTTP);
@@ -102,7 +103,7 @@
 	public static void oneTimeTearDown() throws Exception {
 		BundleContext context = TestActivator.getContext();
 		certificateUIRegistration.unregister();
-		PackageAdmin pkgAdmin = (PackageAdmin) context.getService(packageAdminRef);
+		PackageAdmin pkgAdmin = context.getService(packageAdminRef);
 		stopTransient(pkgAdmin, BUNDLE_TESTSERVER);
 		stopTransient(pkgAdmin, BUNDLE_EQUINOX_HTTP);
 		context.ungetService(packageAdminRef);
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java
index 7cca495..f42534d 100644
--- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java
+++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdatePlugin.java
@@ -123,10 +123,10 @@
 	}
 
 	public IProvisioningEventBus getProvisioningEventBus() {
-		ServiceReference<?> busReference = context.getServiceReference(IProvisioningEventBus.SERVICE_NAME);
+		ServiceReference<IProvisioningEventBus> busReference = context.getServiceReference(IProvisioningEventBus.class);
 		if (busReference == null)
 			return null;
-		return (IProvisioningEventBus) context.getService(busReference);
+		return context.getService(busReference);
 	}
 
 	/*
@@ -146,10 +146,10 @@
 	}
 
 	public IAgentLocation getAgentLocation() {
-		ServiceReference<?> ref = getContext().getServiceReference(IAgentLocation.SERVICE_NAME);
+		ServiceReference<IAgentLocation> ref = getContext().getServiceReference(IAgentLocation.class);
 		if (ref == null)
 			return null;
-		IAgentLocation location = (IAgentLocation) getContext().getService(ref);
+		IAgentLocation location = getContext().getService(ref);
 		getContext().ungetService(ref);
 		return location;
 	}
@@ -184,10 +184,10 @@
 	}
 
 	public IProvisioningAgentProvider getAgentProvider() {
-		ServiceReference<?> ref = getContext().getServiceReference(IProvisioningAgentProvider.SERVICE_NAME);
+		ServiceReference<IProvisioningAgentProvider> ref = getContext().getServiceReference(IProvisioningAgentProvider.class);
 		if (ref == null)
 			return null;
-		IProvisioningAgentProvider agentProvider = (IProvisioningAgentProvider) getContext().getService(ref);
+		IProvisioningAgentProvider agentProvider = getContext().getService(ref);
 		getContext().ungetService(ref);
 		return agentProvider;
 	}
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKUIActivator.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKUIActivator.java
index c6d6acd..f6cc655 100644
--- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKUIActivator.java
+++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKUIActivator.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2012 IBM Corporation and others.
+ * Copyright (c) 2007, 2015 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
@@ -8,6 +8,7 @@
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
+ *     Red Hat Inc. - Bug 460967
  *******************************************************************************/
 package org.eclipse.equinox.internal.p2.ui.sdk;
 
@@ -158,10 +159,10 @@
 	}
 
 	private IAgentLocation getAgentLocation() {
-		ServiceReference<?> ref = getContext().getServiceReference(IAgentLocation.SERVICE_NAME);
+		ServiceReference<IAgentLocation> ref = getContext().getServiceReference(IAgentLocation.class);
 		if (ref == null)
 			return null;
-		IAgentLocation location = (IAgentLocation) getContext().getService(ref);
+		IAgentLocation location = getContext().getService(ref);
 		getContext().ungetService(ref);
 		return location;
 	}
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceInitializer.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceInitializer.java
index bf3177f..151579b 100644
--- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceInitializer.java
+++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceInitializer.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2007, 2012 IBM Corporation and others.
+ *  Copyright (c) 2007, 2015 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
@@ -8,6 +8,7 @@
  *  Contributors:
  *     IBM Corporation - initial API and implementation
  *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
+ *     Red Hat Inc. - Bug 460967
  *******************************************************************************/
 package org.eclipse.equinox.internal.p2.ui.sdk.prefs;
 
@@ -63,10 +64,10 @@
 	}
 
 	private static IAgentLocation getDefaultAgentLocation() {
-		ServiceReference<?> reference = ProvSDKUIActivator.getContext().getServiceReference(IAgentLocation.SERVICE_NAME);
+		ServiceReference<IAgentLocation> reference = ProvSDKUIActivator.getContext().getServiceReference(IAgentLocation.class);
 		if (reference == null)
 			return null;
-		IAgentLocation result = (IAgentLocation) ProvSDKUIActivator.getContext().getService(reference);
+		IAgentLocation result = ProvSDKUIActivator.getContext().getService(reference);
 		ProvSDKUIActivator.getContext().ungetService(reference);
 		return result;
 	}
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUIActivator.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUIActivator.java
index 9481222..9ec5570 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUIActivator.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUIActivator.java
@@ -34,7 +34,7 @@
 public class ProvUIActivator extends AbstractUIPlugin {
 	private static BundleContext context;
 	private static PackageAdmin packageAdmin = null;
-	private static ServiceReference<?> packageAdminRef = null;
+	private static ServiceReference<PackageAdmin> packageAdminRef = null;
 	private static ProvUIActivator plugin;
 	public static final String PLUGIN_ID = "org.eclipse.equinox.p2.ui"; //$NON-NLS-1$
 
@@ -83,8 +83,8 @@
 
 		plugin = this;
 		ProvUIActivator.context = bundleContext;
-		packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
-		packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
+		packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class);
+		packageAdmin = bundleContext.getService(packageAdminRef);
 	}
 
 	public void stop(BundleContext bundleContext) throws Exception {
diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java
index f4061f1..4a3a257 100644
--- a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java
+++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2007, 2015 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 http://www.eclipse.org/legal/epl-v10.html
@@ -7,7 +7,7 @@
  * Contributors: 
  *     IBM Corporation - initial API and implementation
  *     Red Hat, Inc (Krzysztof Daniel) - Bug 421935: Extend simpleconfigurator to
- * read .info files from many locations
+ * read .info files from many locations, Bug 460967
  *******************************************************************************/
 package org.eclipse.equinox.internal.simpleconfigurator;
 
@@ -44,15 +44,15 @@
 		inDevMode = manipulatingContext.getProperty(PROP_DEVMODE) != null;
 		baseLocation = runningOnEquinox ? EquinoxUtils.getInstallLocationURI(context) : null;
 
-		ServiceReference<?> packageAdminRef = manipulatingContext.getServiceReference(PackageAdmin.class.getName());
+		ServiceReference<PackageAdmin> packageAdminRef = manipulatingContext.getServiceReference(PackageAdmin.class);
 		if (packageAdminRef == null)
 			throw new IllegalStateException("No PackageAdmin service is available."); //$NON-NLS-1$
-		packageAdminService = (PackageAdmin) manipulatingContext.getService(packageAdminRef);
+		packageAdminService = manipulatingContext.getService(packageAdminRef);
 
-		ServiceReference<?> startLevelRef = manipulatingContext.getServiceReference(StartLevel.class.getName());
+		ServiceReference<StartLevel> startLevelRef = manipulatingContext.getServiceReference(StartLevel.class);
 		if (startLevelRef == null)
 			throw new IllegalStateException("No StartLevelService service is available."); //$NON-NLS-1$
-		startLevelService = (StartLevel) manipulatingContext.getService(startLevelRef);
+		startLevelService = manipulatingContext.getService(startLevelRef);
 
 		frameworkWiring = (FrameworkWiring) manipulatingContext.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).adapt(FrameworkWiring.class);
 	}