KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > configuration > web > ServletFilterConfiguration


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.configuration.web;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import javax.servlet.FilterConfig JavaDoc;
22
23 import org.apache.commons.collections.iterators.EnumerationIterator;
24 import org.apache.commons.configuration.AbstractConfiguration;
25 import org.apache.commons.configuration.PropertyConverter;
26
27 /**
28  * A configuration wrapper around a {@link FilterConfig}. This configuration is
29  * read only, adding or removing a property will throw an
30  * UnsupportedOperationException.
31  *
32  * @author <a HREF="mailto:ebourg@apache.org">Emmanuel Bourg</a>
33  * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $
34  * @since 1.1
35  */

36 public class ServletFilterConfiguration extends AbstractConfiguration
37 {
38     protected FilterConfig JavaDoc config;
39
40     /**
41      * Create a ServletFilterConfiguration using the filter initialization parameters.
42      */

43     public ServletFilterConfiguration(FilterConfig JavaDoc config)
44     {
45         this.config = config;
46     }
47
48     public Object JavaDoc getProperty(String JavaDoc key)
49     {
50         Object JavaDoc value = config.getInitParameter(key);
51         List JavaDoc list = PropertyConverter.split((String JavaDoc) value, getDelimiter());
52
53         return list.size() > 1 ? list : value;
54     }
55
56     /**
57      * <p><strong>This operation is not supported and will throw an
58      * UnsupportedOperationException.</strong></p>
59      *
60      * @throws UnsupportedOperationException
61      */

62     protected void addPropertyDirect(String JavaDoc key, Object JavaDoc obj)
63     {
64         throw new UnsupportedOperationException JavaDoc("Read only configuration");
65     }
66
67     public boolean isEmpty()
68     {
69         return !getKeys().hasNext();
70     }
71
72     public boolean containsKey(String JavaDoc key)
73     {
74         return getProperty(key) != null;
75     }
76
77     /**
78      * <p><strong>This operation is not supported and will throw an
79      * UnsupportedOperationException.</strong></p>
80      *
81      * @throws UnsupportedOperationException
82      */

83     public void clearProperty(String JavaDoc key)
84     {
85         throw new UnsupportedOperationException JavaDoc("Read only configuration");
86     }
87
88     public Iterator JavaDoc getKeys()
89     {
90         return new EnumerationIterator(config.getInitParameterNames());
91     }
92 }
93
Popular Tags