KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > webapp > http > servlet > ServletContextConfiguration


1 package com.icesoft.faces.webapp.http.servlet;
2
3 import com.icesoft.faces.webapp.http.common.Configuration;
4 import com.icesoft.faces.webapp.http.common.ConfigurationException;
5
6 import javax.servlet.ServletContext JavaDoc;
7
8 public class ServletContextConfiguration extends Configuration {
9     private final String JavaDoc name;
10     private ServletContext JavaDoc context;
11
12     public ServletContextConfiguration(String JavaDoc prefix, ServletContext JavaDoc context) {
13         this.name = prefix;
14         this.context = context;
15     }
16
17     public String JavaDoc getName() {
18         return name;
19     }
20
21     public Configuration getChild(String JavaDoc child) throws ConfigurationException {
22         String JavaDoc childName = postfixWith(child);
23         String JavaDoc value = context.getInitParameter(childName);
24         if (value == null) {
25             throw new ConfigurationException("Cannot find parameter: " + childName);
26         } else {
27             return new ServletContextConfiguration(childName, context);
28         }
29     }
30
31     public Configuration[] getChildren(String JavaDoc name) throws ConfigurationException {
32         return new Configuration[]{getChild(name)};
33     }
34
35     public String JavaDoc getAttribute(String JavaDoc paramName) throws ConfigurationException {
36         String JavaDoc attributeName = postfixWith(paramName);
37         String JavaDoc value = context.getInitParameter(attributeName);
38         if (value == null) {
39             throw new ConfigurationException("Cannot find parameter: " + attributeName);
40         } else {
41             return value;
42         }
43     }
44
45     public String JavaDoc getValue() throws ConfigurationException {
46         String JavaDoc value = context.getInitParameter(name);
47         if (value == null) {
48             throw new ConfigurationException("Cannot find parameter: " + name);
49         } else {
50             return value;
51         }
52     }
53
54     private String JavaDoc postfixWith(String JavaDoc child) {
55         return name + '.' + child;
56     }
57 }
58
Popular Tags