001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jsp.el;
031:
032: import com.caucho.jsp.TaglibManager;
033: import com.caucho.server.webapp.WebApp;
034: import com.caucho.util.L10N;
035:
036: import javax.el.ELContextListener;
037: import javax.el.ELResolver;
038: import javax.el.ExpressionFactory;
039: import javax.servlet.jsp.JspApplicationContext;
040:
041: public class JspApplicationContextImpl implements JspApplicationContext {
042: private static final L10N L = new L10N(
043: JspApplicationContextImpl.class);
044:
045: private final WebApp _webApp;
046:
047: private final ExpressionFactory _expressionFactory;
048:
049: private TaglibManager _taglibManager;
050:
051: private ELResolver[] _resolverArray = new ELResolver[0];
052: private ELContextListener[] _listenerArray = new ELContextListener[0];
053:
054: private boolean _hasRequest;
055:
056: public JspApplicationContextImpl(WebApp webApp) {
057: _webApp = webApp;
058:
059: _expressionFactory = new JspExpressionFactoryImpl(this );
060: }
061:
062: //
063: // properties
064: //
065:
066: WebApp getWebApp() {
067: return _webApp;
068: }
069:
070: public TaglibManager getTaglibManager() {
071: return _taglibManager;
072: }
073:
074: public void setTaglibManager(TaglibManager taglibManager) {
075: _taglibManager = taglibManager;
076: }
077:
078: //
079: // JspApplicationContext API methods
080: //
081:
082: /**
083: * Adds an ELContextListener.
084: */
085: public void addELContextListener(ELContextListener listener) {
086: if (_hasRequest)
087: throw new IllegalStateException(
088: L
089: .l("Cannot add ELContextListener after requests have started."));
090:
091: ELContextListener[] listenerArray = new ELContextListener[_listenerArray.length + 1];
092: System.arraycopy(_listenerArray, 0, listenerArray, 0,
093: _listenerArray.length);
094:
095: listenerArray[_listenerArray.length] = listener;
096:
097: _listenerArray = listenerArray;
098: }
099:
100: public ELContextListener[] getELListenerArray() {
101: _hasRequest = true;
102:
103: return _listenerArray;
104: }
105:
106: /**
107: * Adds an ELResolver
108: */
109: public void addELResolver(ELResolver resolver) {
110: if (_hasRequest)
111: throw new IllegalStateException(L
112: .l("Can't add ELResolver after starting request."));
113:
114: ELResolver[] resolverArray = new ELResolver[_resolverArray.length + 1];
115: System.arraycopy(_resolverArray, 0, resolverArray, 0,
116: _resolverArray.length);
117:
118: resolverArray[_resolverArray.length] = resolver;
119:
120: _resolverArray = resolverArray;
121: }
122:
123: public ELResolver[] getELResolverArray() {
124: return _resolverArray;
125: }
126:
127: /**
128: * Gets the expression factory
129: */
130: public ExpressionFactory getExpressionFactory() {
131: return _expressionFactory;
132: }
133:
134: public String toString() {
135: return "JspApplicationContextImpl[" + _webApp + "]";
136: }
137: }
|