1 //
2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.annotations;
20
21 import java.util.List;
22 import java.util.Set;
23 import java.util.concurrent.ConcurrentHashMap;
24
25 import org.eclipse.jetty.plus.annotation.ContainerInitializer;
26 import org.eclipse.jetty.servlet.ServletContextHandler;
27 import org.eclipse.jetty.util.ConcurrentHashSet;
28 import org.eclipse.jetty.util.component.AbstractLifeCycle;
29 import org.eclipse.jetty.util.log.Log;
30 import org.eclipse.jetty.util.log.Logger;
31 import org.eclipse.jetty.webapp.WebAppContext;
32
33
34 /**
35 * ServletContainerInitializersStarter
36 *
37 * Call the onStartup() method on all ServletContainerInitializers, after having
38 * found all applicable classes (if any) to pass in as args.
39 */
40 public class ServletContainerInitializersStarter extends AbstractLifeCycle implements ServletContextHandler.ServletContainerInitializerCaller
41 {
42 private static final Logger LOG = Log.getLogger(ServletContainerInitializersStarter.class);
43 WebAppContext _context;
44
45 /**
46 * @param context
47 */
48 public ServletContainerInitializersStarter(WebAppContext context)
49 {
50 _context = context;
51 }
52
53 /**
54 * Call the doStart method of the ServletContainerInitializers
55 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
56 */
57 public void doStart()
58 {
59 List<ContainerInitializer> initializers = (List<ContainerInitializer>)_context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS);
60 if (initializers == null)
61 return;
62
63 for (ContainerInitializer i : initializers)
64 {
65 try
66 {
67 if (LOG.isDebugEnabled())
68 LOG.debug("Calling ServletContainerInitializer "+i.getTarget().getClass().getName());
69 i.callStartup(_context);
70 }
71 catch (Exception e)
72 {
73 LOG.warn(e);
74 throw new RuntimeException(e);
75 }
76 }
77 }
78
79
80 }