KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > repository > RepositoryBean


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.repository;
8
9
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11 import javax.servlet.jsp.PageContext JavaDoc;
12
13 import com.inversoft.beans.BeanException;
14 import com.inversoft.verge.repository.config.Config;
15 import com.inversoft.verge.repository.config.ItemConfig;
16 import com.inversoft.verge.util.WebBean;
17
18
19 /**
20  * <p>
21  * This class is a {@link WebBean WebBean} for a repository
22  * item
23  * </p>
24  *
25  * @author Brian Pontarelli
26  */

27 public class RepositoryBean extends WebBean {
28
29     private Config config;
30
31
32     /**
33      * Constructs a new RepositoryBean that references an item in the repository
34      *
35      * @param config The Repository config object of the item in the repository
36      */

37     public RepositoryBean(Config config) throws BeanException {
38         super(); // Does not call into initialize
39

40         assert (config != null) : "config == null";
41
42         this.config = config;
43
44         initialize(config.getID(), config.getScope());
45         setBeanClass(((ItemConfig) config).getBeanClass());
46     }
47
48     /**
49      * Constructs a new RepositoryBean that references an item in the repository
50      *
51      * @param id The id of the item in the repository
52      */

53     public RepositoryBean(String JavaDoc id, HttpServletRequest JavaDoc request)
54     throws BeanException {
55         super(); // Does not call into initialize
56

57         config = Repository.getInstance().lookupConfig(request, id);
58         if (config == null) {
59             throw new BeanException("Invalid repository id: " + id);
60         }
61
62         initialize(id, config.getScope());
63         setBeanClass(((ItemConfig) config).getBeanClass());
64     }
65
66
67     /**
68      * Returns the instance of the bean, which is retrieved from the Repository
69      *
70      * @param pageContext This is not used because repository beans currently
71      * can not reside in the PageContext
72      * @param request The HttpServletRequest used for looking up the bean if
73      * it is in the request, session or application scopes
74      * @return The instance of the bean from the correct scope or a new instance
75      * of the bean which has been added to the correct scope
76      * @throws BeanException If there was a problem during instantiation or if
77      * the scope contains an object that is not the correct class
78      */

79     public Object JavaDoc getInstance(PageContext JavaDoc pageContext, HttpServletRequest JavaDoc request)
80     throws BeanException {
81         return Repository.getInstance().lookupItem(request, config);
82     }
83 }
84
Popular Tags