View Javadoc

1   /*
2    * Copyright 2004-2009 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.servlet;
17  
18  import java.io.IOException;
19  
20  import javax.servlet.GenericServlet;
21  import javax.servlet.ServletConfig;
22  import javax.servlet.ServletException;
23  import javax.servlet.ServletRequest;
24  import javax.servlet.ServletResponse;
25  
26  import org.seasar.cubby.internal.plugin.PluginManager;
27  import org.seasar.cubby.plugin.PluginRegistry;
28  
29  /**
30   * プラグインの初期化などを行う <code>Servlet</code> です。
31   * 
32   * @author baba
33   */
34  public class CubbyServlet extends GenericServlet {
35  
36  	/** シリアルバージョン UID。 */
37  	private static final long serialVersionUID = 1L;
38  
39  	/** プラグインマネージャ。 */
40  	private transient PluginManager pluginManager;
41  
42  	/**
43  	 * サーブレットをインスタンス化します。
44  	 */
45  	public CubbyServlet() {
46  		super();
47  	}
48  
49  	/**
50  	 * {@inheritDoc}
51  	 * <p>
52  	 * プラグインの初期化とレジストリへの登録を行います。
53  	 * </p>
54  	 */
55  	@Override
56  	public void init(final ServletConfig config) throws ServletException {
57  		super.init(config);
58  		pluginManager = buildPluginManager();
59  		try {
60  			pluginManager.init(config.getServletContext());
61  		} catch (final Exception e) {
62  			throw new ServletException(e);
63  		}
64  	}
65  
66  	/**
67  	 * {@inheritDoc}
68  	 * <p>
69  	 * プラグインの破棄を行います。
70  	 * </p>
71  	 * 
72  	 * @see PluginManager#destroy()
73  	 */
74  	@Override
75  	public void destroy() {
76  		super.destroy();
77  		pluginManager.destroy();
78  	}
79  
80  	/**
81  	 * {@inheritDoc}
82  	 */
83  	@Override
84  	public void service(final ServletRequest req, final ServletResponse res)
85  			throws ServletException, IOException {
86  		// do nothing
87  	}
88  
89  	/**
90  	 * プラグインマネージャを構築します。
91  	 * 
92  	 * @return プラグインマネージャ
93  	 */
94  	protected PluginManager buildPluginManager() {
95  		return new PluginManager(PluginRegistry.getInstance());
96  	}
97  
98  }