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