KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > repository > config > ItemConfig


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.config;
8
9
10 import java.util.Properties JavaDoc;
11
12 import javax.servlet.http.HttpServletRequest JavaDoc;
13 import javax.servlet.jsp.PageContext JavaDoc;
14
15 import org.apache.log4j.Logger;
16
17 import com.inversoft.beans.BeanException;
18 import com.inversoft.beans.JavaBean;
19 import com.inversoft.verge.util.WebBean;
20
21
22 /**
23  * This is the basic Config for items in the repository. This
24  * contains all the pertinent information needed to construct
25  * items and populate them with initial values.
26  * <p>
27  * This class should be the base class for new types of items
28  * used in a repository.
29  *
30  * @author Brian Pontarelli
31  * @since 2.0
32  */

33 public class ItemConfig extends WebBean implements Config {
34
35     /** The logger for this class */
36     private final static Logger logger = Logger.getLogger(ItemConfig.class);
37
38     private Properties JavaDoc props;
39     private Properties JavaDoc references;
40
41
42     /**
43      * Constructs a new item configuration with the given information.
44      *
45      * @see com.inversoft.verge.util.WebBean#WebBean(String, int, Class)
46      */

47     public ItemConfig(String JavaDoc id, int scope, Class JavaDoc beanClass) throws BeanException {
48         super(id, scope, beanClass);
49         props = new Properties JavaDoc();
50         references = new Properties JavaDoc();
51     }
52
53     /**
54      * Constructs a new item configuration with the given information.
55      *
56      * @see com.inversoft.verge.util.WebBean#WebBean(String, int, String)
57      */

58     public ItemConfig(String JavaDoc id, int scope, String JavaDoc className) throws BeanException {
59         super(id, scope, className);
60         props = new Properties JavaDoc();
61         references = new Properties JavaDoc();
62     }
63
64
65     /**
66      * Returns the properties for this item. This is guarenteed never to be null
67      *
68      * @return The properties for this item
69      */

70     public Properties JavaDoc getProperties() {
71         return props;
72     }
73
74     /**
75      * Adds a new property to the bean config with the given name and initial
76      * value.
77      *
78      * @param name The name of the property
79      * @param value The initial value of the property
80      * @throws BeanException If the property does not exist in the class of this
81      * bean or if the class for this config has not been set yet
82      */

83     protected void addProperty(String JavaDoc name, String JavaDoc value) throws BeanException {
84
85         if (logger.isDebugEnabled()) {
86             logger.debug("Adding initial property named: " + name +
87                 " with value of: " + value);
88         }
89
90         getBeanProperty(name); // initialize
91
props.setProperty(name, value);
92     }
93
94     /**
95      * Returns the references for this item
96      */

97     public Properties JavaDoc getReferences() {
98         return references;
99     }
100
101     /**
102      * Adds a new reference to the bean config with the given name and initial
103      * value.
104      *
105      * @param name The name of the property
106      * @param value The initial value of the property
107      * @throws BeanException If the property does not exist in the class of this
108      * bean or if the class for this config has not been set yet
109      */

110     protected void addReference(String JavaDoc name, String JavaDoc value) throws BeanException {
111         getBeanProperty(name); // initialize
112
references.setProperty(name, value);
113     }
114
115     /**
116      * Returns true if this ItemConfig contains a property with the given name
117      *
118      * @param name The name to check
119      * @return True if the config has a property with the given name, false
120      * otherwise
121      */

122     public boolean hasProperty(String JavaDoc name) {
123         return props.containsKey(name);
124     }
125
126     /**
127      * Returns true if this ItemConfig contains a reference with the given name
128      *
129      * @param name The name to check
130      * @return True if the config has a reference with the given name, false
131      * otherwise
132      */

133     public boolean hasReference(String JavaDoc name) {
134         return references.containsKey(name);
135     }
136
137     /**
138      * Unsupported operation
139      */

140     public Object JavaDoc getInstance(PageContext JavaDoc pageContext, HttpServletRequest JavaDoc request) {
141         throw new UnsupportedOperationException JavaDoc("Not supported on configuration object");
142     }
143
144     /**
145      * Returns this.
146      */

147     public JavaBean getJavaBean() {
148         return this;
149     }
150 }
151
Popular Tags