1 12 13 package org.eclipse.equinox.http.servlet.internal; 14 15 import java.util.*; 16 import javax.servlet.Servlet ; 17 import javax.servlet.ServletException ; 18 import org.osgi.framework.Bundle; 19 import org.osgi.service.http.*; 20 21 public class HttpServiceImpl implements HttpService { 22 23 private Bundle bundle; 25 private ProxyServlet proxy; 27 Set aliases = new HashSet(); 29 public HttpServiceImpl(Bundle bundle, ProxyServlet proxy) { 30 this.bundle = bundle; 31 this.proxy = proxy; 32 } 33 34 public synchronized void unregisterAliases() { 36 for (Iterator it = aliases.iterator(); it.hasNext();) { 37 String alias = (String ) it.next(); 38 proxy.unregister(alias, false); 39 } 40 aliases.clear(); 41 } 42 43 46 public synchronized void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context) throws ServletException , NamespaceException { 47 if (context == null) { 48 context = createDefaultHttpContext(); 49 } 50 proxy.registerServlet(alias, servlet, initparams, context, bundle); 51 aliases.add(alias); 52 } 53 54 57 public synchronized void registerResources(String alias, String 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 68 public synchronized void unregister(String alias) { 69 if (aliases.remove(alias)) { 70 proxy.unregister(alias, true); 71 } else { 72 throw new IllegalArgumentException ("Alias not found."); } 75 } 76 77 80 public HttpContext createDefaultHttpContext() { 81 return new DefaultHttpContext(bundle); 82 } 83 } 84 | Popular Tags |