core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/ProxyUtils.java
changeset 421 7bf2b8a16445
equal deleted inserted replaced
420:be59a4bc0747 421:7bf2b8a16445
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 package com.nokia.cpp.internal.api.utils.core;
       
    19 
       
    20 import com.nokia.cpp.utils.core.noexport.UtilsCorePlugin;
       
    21 
       
    22 import org.eclipse.core.net.proxy.IProxyData;
       
    23 import org.eclipse.core.net.proxy.IProxyService;
       
    24 import org.osgi.framework.BundleContext;
       
    25 import org.osgi.framework.ServiceReference;
       
    26 
       
    27 import java.net.URI;
       
    28 
       
    29 public class ProxyUtils {
       
    30 
       
    31 	/**
       
    32 	 * Get a reference to the proxy service
       
    33 	 * @return IProxyService
       
    34 	 */
       
    35 	public static IProxyService getProxyService() {
       
    36 		BundleContext bc = UtilsCorePlugin.getDefault().getBundle().getBundleContext();
       
    37 		ServiceReference ref = bc.getServiceReference(IProxyService.class.getName());
       
    38 		if (ref != null)
       
    39 			return (IProxyService) bc.getService(ref);
       
    40 			
       
    41 		return null;
       
    42 	}
       
    43 	
       
    44 	
       
    45 	/**
       
    46 	 * Get proxy data for this URI. Takes into consideration native vs manual proxy setting
       
    47 	 * as well as hosts for which no proxy is required.
       
    48 	 * Returns null if no proxy data is set or needed for this URI.
       
    49 	 * @param uri URI
       
    50 	 * @return IProxyData
       
    51 	 */
       
    52 	public static IProxyData getProxyData(URI uri) {
       
    53 		IProxyService proxyService = getProxyService();
       
    54 		if (proxyService != null) {
       
    55 			IProxyData[] proxyData = proxyService.select(uri);
       
    56 			if (proxyData.length > 0)
       
    57 				return proxyData[0];
       
    58 		}
       
    59 		
       
    60 		return  null;
       
    61 	}
       
    62 }