KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsp > WrapperPage


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jsp;
30
31 import com.caucho.vfs.Path;
32
33 import javax.servlet.ServletConfig JavaDoc;
34 import javax.servlet.ServletException JavaDoc;
35 import javax.servlet.ServletRequest JavaDoc;
36 import javax.servlet.ServletResponse JavaDoc;
37 import javax.servlet.jsp.HttpJspPage JavaDoc;
38 import java.io.IOException JavaDoc;
39
40 /**
41  * Wraps Java JSP files using 'extends' in a page. Since a JSP file which
42  * uses 'extends' does not subclass from Page, we need to wrap it with
43  * a Page-compatible class.
44  *
45  * <p>Because it inherits from Page, the wrapped page still be recompiled
46  * when the underlying page changes.
47  */

48 class WrapperPage extends Page {
49   private HttpJspPage JavaDoc _child;
50   private CauchoPage _childPage;
51
52   WrapperPage(HttpJspPage JavaDoc child)
53     throws IOException JavaDoc
54   {
55     _child = child;
56     
57     if (_child instanceof CauchoPage)
58       _childPage = (CauchoPage) child;
59   }
60
61   public void init(Path path)
62     throws ServletException JavaDoc
63   {
64     if (_childPage != null)
65       _childPage.init(path);
66   }
67
68   /**
69    * Forward the initialization to the wrapped page.
70    */

71   final public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc
72   {
73     super.init(config);
74     
75     _child.init(config);
76   }
77
78   /**
79    * Returns the underlying page.
80    */

81   public HttpJspPage JavaDoc getWrappedPage()
82   {
83     return _child;
84   }
85
86   public boolean _caucho_isModified()
87   {
88     if (_childPage != null)
89       return _childPage._caucho_isModified();
90     else
91       return false;
92   }
93
94   public long _caucho_lastModified()
95   {
96     if (_childPage != null)
97       return _childPage._caucho_lastModified();
98     else
99       return 0;
100   }
101
102   /**
103    * Forwards the request to the child page.
104    */

105   public void service(ServletRequest JavaDoc request, ServletResponse JavaDoc response)
106     throws IOException JavaDoc, ServletException JavaDoc
107   {
108     _child.service(request, response);
109   }
110
111   /**
112    * Forward the destruction to the wrapped page.
113    */

114   final public void destroy()
115   {
116     try {
117       setDead();
118       
119       _child.destroy();
120     } catch (Exception JavaDoc e) {
121     }
122   }
123 }
124
Popular Tags