1 //
2 // ========================================================================
3 // Copyright (c) 1995-2015 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
23 import org.eclipse.jetty.plus.annotation.ContainerInitializer;
24 import org.eclipse.jetty.servlet.ServletContextHandler;
25 import org.eclipse.jetty.util.component.AbstractLifeCycle;
26 import org.eclipse.jetty.util.log.Log;
27 import org.eclipse.jetty.util.log.Logger;
28 import org.eclipse.jetty.webapp.WebAppContext;
29
30
31 /**
32 * ServletContainerInitializersStarter
33 *
34 * Call the onStartup() method on all ServletContainerInitializers, after having
35 * found all applicable classes (if any) to pass in as args.
36 */
37 public class ServletContainerInitializersStarter extends AbstractLifeCycle implements ServletContextHandler.ServletContainerInitializerCaller
38 {
39 private static final Logger LOG = Log.getLogger(ServletContainerInitializersStarter.class);
40 WebAppContext _context;
41
42 public ServletContainerInitializersStarter(WebAppContext context)
43 {
44 _context = context;
45 }
46
47 /**
48 * Call the doStart method of the ServletContainerInitializers
49 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
50 */
51 public void doStart()
52 {
53 List<ContainerInitializer> initializers = (List<ContainerInitializer>)_context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS);
54 if (initializers == null)
55 return;
56
57 for (ContainerInitializer i : initializers)
58 {
59 try
60 {
61 if (LOG.isDebugEnabled())
62 LOG.debug("Calling ServletContainerInitializer "+i.getTarget().getClass().getName());
63 i.callStartup(_context);
64 }
65 catch (Exception e)
66 {
67 LOG.warn(e);
68 throw new RuntimeException(e);
69 }
70 }
71 }
72 }