KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > equinox > http > servlet > internal > HttpServiceImpl


1 /*******************************************************************************
2  * Copyright (c) 2005-2007 Cognos Incorporated, 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  * Cognos Incorporated - initial API and implementation
10  * IBM Corporation - bug fixes and enhancements
11  *******************************************************************************/

12
13 package org.eclipse.equinox.http.servlet.internal;
14
15 import java.util.*;
16 import javax.servlet.Servlet JavaDoc;
17 import javax.servlet.ServletException JavaDoc;
18 import org.osgi.framework.Bundle;
19 import org.osgi.service.http.*;
20
21 public class HttpServiceImpl implements HttpService {
22
23     private Bundle bundle; //The bundle associated with this instance of http service
24

25     private ProxyServlet proxy; //The proxy that does the dispatching of the incoming requests
26

27     Set aliases = new HashSet(); //Aliases registered against this particular instance of the service
28

29     public HttpServiceImpl(Bundle bundle, ProxyServlet proxy) {
30         this.bundle = bundle;
31         this.proxy = proxy;
32     }
33
34     //Clean up method
35
public synchronized void unregisterAliases() {
36         for (Iterator it = aliases.iterator(); it.hasNext();) {
37             String JavaDoc alias = (String JavaDoc) it.next();
38             proxy.unregister(alias, false);
39         }
40         aliases.clear();
41     }
42
43     /**
44      * @see HttpService#registerServlet(String, Servlet, Dictionary, HttpContext)
45      */

46     public synchronized void registerServlet(String JavaDoc alias, Servlet JavaDoc servlet, Dictionary initparams, HttpContext context) throws ServletException JavaDoc, NamespaceException {
47         if (context == null) {
48             context = createDefaultHttpContext();
49         }
50         proxy.registerServlet(alias, servlet, initparams, context, bundle);
51         aliases.add(alias);
52     }
53
54     /**
55      * @see HttpService#registerResources(String, String, HttpContext)
56      */

57     public synchronized void registerResources(String JavaDoc alias, String JavaDoc name, HttpContext context) throws NamespaceException {
58         if (context == null) {
59             context = createDefaultHttpContext();
60         }
61         proxy.registerResources(alias, name, context);
62         aliases.add(alias);
63     }
64
65     /**
66      * @see HttpService#unregister(String)
67      */

68     public synchronized void unregister(String JavaDoc alias) {
69         if (aliases.remove(alias)) {
70             proxy.unregister(alias, true);
71         } else {
72             // TODO perhaps this is too strong a reacttion ?
73
throw new IllegalArgumentException JavaDoc("Alias not found."); //$NON-NLS-1$
74
}
75     }
76
77     /**
78      * @see HttpService#createDefaultHttpContext()
79      */

80     public HttpContext createDefaultHttpContext() {
81         return new DefaultHttpContext(bundle);
82     }
83 }
84
Popular Tags