01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jasper.compiler;
18:
19: import java.util.HashMap;
20:
21: import org.apache.jasper.JasperException;
22:
23: /**
24: * Repository of {page, request, session, application}-scoped beans
25: *
26: * @author Mandar Raje
27: * @author Remy Maucherat
28: */
29: public class BeanRepository {
30:
31: protected HashMap<String, String> beanTypes;
32: protected ClassLoader loader;
33: protected ErrorDispatcher errDispatcher;
34:
35: /**
36: * Constructor.
37: */
38: public BeanRepository(ClassLoader loader, ErrorDispatcher err) {
39: this .loader = loader;
40: this .errDispatcher = err;
41: beanTypes = new HashMap<String, String>();
42: }
43:
44: public void addBean(Node.UseBean n, String s, String type,
45: String scope) throws JasperException {
46:
47: if (!(scope == null || scope.equals("page")
48: || scope.equals("request") || scope.equals("session") || scope
49: .equals("application"))) {
50: errDispatcher.jspError(n, "jsp.error.usebean.badScope");
51: }
52:
53: beanTypes.put(s, type);
54: }
55:
56: public Class getBeanType(String bean) throws JasperException {
57: Class clazz = null;
58: try {
59: clazz = loader.loadClass(beanTypes.get(bean));
60: } catch (ClassNotFoundException ex) {
61: throw new JasperException(ex);
62: }
63: return clazz;
64: }
65:
66: public boolean checkVariable(String bean) {
67: return beanTypes.containsKey(bean);
68: }
69:
70: }
|