KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsp > el > JspApplicationContextImpl


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  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jsp.el;
31
32 import com.caucho.jsp.TaglibManager;
33 import com.caucho.server.webapp.WebApp;
34 import com.caucho.util.L10N;
35
36 import javax.el.ELContextListener;
37 import javax.el.ELResolver;
38 import javax.el.ExpressionFactory;
39 import javax.servlet.jsp.JspApplicationContext JavaDoc;
40
41 public class JspApplicationContextImpl implements JspApplicationContext JavaDoc
42 {
43   private static final L10N L = new L10N(JspApplicationContextImpl.class);
44   
45   private final WebApp _webApp;
46   
47   private final ExpressionFactory _expressionFactory;
48
49   private TaglibManager _taglibManager;
50
51   private ELResolver []_resolverArray = new ELResolver[0];
52   private ELContextListener []_listenerArray = new ELContextListener[0];
53
54   private boolean _hasRequest;
55
56   public JspApplicationContextImpl(WebApp webApp)
57   {
58     _webApp = webApp;
59
60     _expressionFactory = new JspExpressionFactoryImpl(this);
61   }
62
63   //
64
// properties
65
//
66

67   WebApp getWebApp()
68   {
69     return _webApp;
70   }
71
72   public TaglibManager getTaglibManager()
73   {
74     return _taglibManager;
75   }
76
77   public void setTaglibManager(TaglibManager taglibManager)
78   {
79     _taglibManager = taglibManager;
80   }
81
82   //
83
// JspApplicationContext API methods
84
//
85

86   /**
87    * Adds an ELContextListener.
88    */

89   public void addELContextListener(ELContextListener listener)
90   {
91     if (_hasRequest)
92       throw new IllegalStateException JavaDoc(L.l("Cannot add ELContextListener after requests have started."));
93     
94     ELContextListener []listenerArray
95       = new ELContextListener[_listenerArray.length + 1];
96     System.arraycopy(_listenerArray, 0,
97              listenerArray, 0,
98              _listenerArray.length);
99
100     listenerArray[_listenerArray.length] = listener;
101     
102     _listenerArray = listenerArray;
103   }
104
105   public ELContextListener []getELListenerArray()
106   {
107     _hasRequest = true;
108     
109     return _listenerArray;
110   }
111   
112   /**
113    * Adds an ELResolver
114    */

115   public void addELResolver(ELResolver resolver)
116   {
117     if (_hasRequest)
118       throw new IllegalStateException JavaDoc(L.l("Can't add ELResolver after starting request."));
119     
120     ELResolver []resolverArray = new ELResolver[_resolverArray.length + 1];
121     System.arraycopy(_resolverArray, 0,
122              resolverArray, 0,
123              _resolverArray.length);
124
125     resolverArray[_resolverArray.length] = resolver;
126     
127     _resolverArray = resolverArray;
128   }
129
130   public ELResolver []getELResolverArray()
131   {
132     return _resolverArray;
133   }
134   
135   /**
136    * Gets the expression factory
137    */

138   public ExpressionFactory getExpressionFactory()
139   {
140     return _expressionFactory;
141   }
142
143   public String JavaDoc toString()
144   {
145     return "JspApplicationContextImpl[" + _webApp + "]";
146   }
147 }
148
Popular Tags