1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * 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
20 import java.util.HashMap;
21
22 import org.apache.jasper.JasperException;
23
24 /**
25 * Repository of {page, request, session, application}-scoped beans
26 *
27 * @author Mandar Raje
28 * @author Remy Maucherat
29 */
30 public class BeanRepository {
31
32 protected HashMap<String, String> beanTypes;
33 protected ClassLoader loader;
34 protected ErrorDispatcher errDispatcher;
35
36 /**
37 * Constructor.
38 */
39 public BeanRepository(ClassLoader loader, ErrorDispatcher err) {
40 this.loader = loader;
41 this.errDispatcher = err;
42 beanTypes = new HashMap<String, String>();
43 }
44
45 public void addBean(Node.UseBean n, String s, String type, String scope)
46 throws JasperException {
47
48 if (!(scope == null || scope.equals("page") || scope.equals("request")
49 || scope.equals("session") || scope.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)
57 throws JasperException {
58 Class clazz = null;
59 try {
60 clazz = loader.loadClass(beanTypes.get(bean));
61 } catch (ClassNotFoundException ex) {
62 throw new JasperException (ex);
63 }
64 return clazz;
65 }
66
67 public boolean checkVariable(String bean) {
68 return beanTypes.containsKey(bean);
69 }
70
71 }
72
73
74
75