KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > tomcat > internal > TomcatPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  *******************************************************************************/

11 package org.eclipse.tomcat.internal;
12
13 import java.util.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.osgi.framework.*;
17 import org.osgi.service.url.*;
18 /**
19  */

20 public class TomcatPlugin extends Plugin implements BundleActivator {
21     public final static String JavaDoc PLUGIN_ID = "org.eclipse.tomcat"; //$NON-NLS-1$
22

23     // Preferences keys
24
public final static String JavaDoc PREF_ACCEPT_COUNT = "acceptCount"; //$NON-NLS-1$
25
public final static String JavaDoc PREF_MAX_PROCESSORS = "maxProcessors"; //$NON-NLS-1$
26
public final static String JavaDoc PREF_MIN_PROCESSORS = "minProcessors"; //$NON-NLS-1$
27

28     public final static String JavaDoc PREF_SSL_PORT = "sslPort"; //$NON-NLS-1$
29
public final static String JavaDoc PREF_SSL_PROTOCOL = "sslProtocol"; //$NON-NLS-1$
30
public final static String JavaDoc PREF_SSL_SCHEME = "sslScheme"; //$NON-NLS-1$
31
public final static String JavaDoc PREF_SSL_ALGORITHM = "sslAlgorithm"; //$NON-NLS-1$
32
public final static String JavaDoc PREF_KEY_STORE_FILE = "keyStoreFile"; //$NON-NLS-1$
33
public final static String JavaDoc PREF_KEY_STORE_PASSWORD = "keyStorePassword"; //$NON-NLS-1$
34

35     private static TomcatPlugin plugin;
36 // private static BundleContext bundleContext;
37

38     private ServiceRegistration jndiURLServiceRegistration;
39     
40     private TomcatAppServer appserver;
41
42     void setAppserver(TomcatAppServer appserver) {
43         this.appserver = appserver;
44     }
45
46     /**
47      */

48     public TomcatPlugin() {
49         super();
50     }
51
52     /**
53      * Logs an Error message with an exception. Note that the message should
54      * already be localized to proper locale. ie: TomcatResources.getString()
55      * should already have been called
56      */

57     public static synchronized void logError(String JavaDoc message, Throwable JavaDoc ex) {
58         if (message == null)
59             message = ""; //$NON-NLS-1$
60
Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK,
61                 message, ex);
62         TomcatPlugin.getDefault().getLog().log(errorStatus);
63     }
64
65     public static TomcatPlugin getDefault() {
66         return plugin;
67     }
68
69     public void start(BundleContext context) throws Exception JavaDoc {
70         super.start(context);
71         plugin = this;
72 // bundleContext = context;
73

74         registerJndiURL(context);
75     }
76
77     public void stop(BundleContext context) throws Exception JavaDoc {
78         if(appserver!=null){
79             try{
80                 appserver.stop();
81             }catch(Exception JavaDoc e){
82             }
83         }
84         unregisterJndiURL();
85
86         plugin = null;
87 // bundleContext = null;
88
super.stop(context);
89     }
90     private void registerJndiURL(BundleContext context) {
91         Hashtable properties = new Hashtable();
92         properties.put(URLConstants.URL_HANDLER_PROTOCOL, new String JavaDoc[]{"jndi"}); //$NON-NLS-1$
93
try {
94             jndiURLServiceRegistration = context.registerService(
95                     URLStreamHandlerService.class.getName(),
96                     new JndiURLHandler(), properties);
97         } catch (Error JavaDoc t) {
98             logError(t.getMessage(), t);
99             throw t;
100         }
101     }
102
103     private void unregisterJndiURL() {
104         if (jndiURLServiceRegistration != null) {
105             jndiURLServiceRegistration.unregister();
106         }
107     }
108
109 }
110
Popular Tags