KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > net > Activator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * yyyymmdd bug Email and other contact information
11  * -------- -------- -----------------------------------------------------------
12  * 20070119 161112 makandre@ca.ibm.com - Andrew Mak, WSE: can't find business thru a proxy server that needs basic auth
13  * 20070201 154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base.
14  *******************************************************************************/

15
16 package org.eclipse.core.internal.net;
17
18 import java.util.Hashtable JavaDoc;
19
20 import org.eclipse.core.net.proxy.IProxyService;
21 import org.eclipse.core.runtime.*;
22 import org.eclipse.core.runtime.preferences.InstanceScope;
23 import org.osgi.framework.BundleContext;
24 import org.osgi.framework.ServiceRegistration;
25
26 public class Activator extends Plugin {
27     /**
28      * The identifier of the descriptor of this plugin in plugin.xml.
29      */

30     public static final String JavaDoc ID = "org.eclipse.core.net"; //$NON-NLS-1$
31

32     public static final String JavaDoc PT_AUTHENTICATOR = "authenticator"; //$NON-NLS-1$
33

34     private static final String JavaDoc PROP_REGISTER_SERVICE = "org.eclipse.net.core.enableProxyService"; //$NON-NLS-1$
35

36     /**
37      * The instance of this plugin.
38      */

39     private static Activator instance;
40
41     private ServiceRegistration proxyService;
42
43     /**
44      * Constructor for use by the Eclipse platform only.
45      */

46     public Activator() {
47         super();
48         instance = this;
49     }
50
51     /**
52      * Returns the instance of this plugin.
53      * @return the singleton instance of this plug-in class
54      */

55     static public Activator getInstance() {
56         return instance;
57     }
58
59     public void start(BundleContext context) throws Exception JavaDoc {
60         super.start(context);
61         if (Boolean.valueOf(System.getProperty(PROP_REGISTER_SERVICE, "true")).booleanValue()) { //$NON-NLS-1$
62
ProxyManager proxyManager = (ProxyManager)ProxyManager.getProxyManager();
63             proxyManager.initialize();
64             proxyService = getBundle().getBundleContext().registerService(IProxyService.class.getName(), proxyManager, new Hashtable JavaDoc());
65         }
66     }
67     
68     public void stop(BundleContext context) throws Exception JavaDoc {
69         if (proxyService != null) {
70             proxyService.unregister();
71             proxyService = null;
72         }
73         super.stop(context);
74     }
75     
76     public static void logError(String JavaDoc message, Throwable JavaDoc exc) {
77         IStatus status = new Status(IStatus.ERROR, ID, 0, message, exc);
78
79         getInstance().getLog().log(status);
80     }
81
82     public static void logInfo(String JavaDoc message, Throwable JavaDoc exc) {
83         IStatus status = new Status(IStatus.INFO, ID, 0, message, exc);
84
85         getInstance().getLog().log(status);
86     }
87
88     public org.osgi.service.prefs.Preferences getInstancePreferences() {
89         return new InstanceScope().getNode(getBundle().getSymbolicName());
90     }
91
92     public static void log(int severity, String JavaDoc message, Throwable JavaDoc throwable) {
93         getInstance().getLog().log(new Status(severity, ID, 0, message, throwable));
94     }
95 }
96
Popular Tags