KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jasper > compiler > BeanRepository


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 JavaDoc;
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 JavaDoc<String JavaDoc, String JavaDoc> beanTypes;
33     protected ClassLoader JavaDoc loader;
34     protected ErrorDispatcher errDispatcher;
35
36     /**
37      * Constructor.
38      */

39     public BeanRepository(ClassLoader JavaDoc loader, ErrorDispatcher err) {
40         this.loader = loader;
41         this.errDispatcher = err;
42         beanTypes = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
43     }
44
45     public void addBean(Node.UseBean n, String JavaDoc s, String JavaDoc type, String JavaDoc 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 JavaDoc getBeanType(String JavaDoc bean)
57         throws JasperException {
58         Class JavaDoc clazz = null;
59         try {
60             clazz = loader.loadClass(beanTypes.get(bean));
61         } catch (ClassNotFoundException JavaDoc ex) {
62             throw new JasperException (ex);
63         }
64         return clazz;
65     }
66       
67     public boolean checkVariable(String JavaDoc bean) {
68         return beanTypes.containsKey(bean);
69     }
70
71 }
72
73
74
75
76
Popular Tags