Source Code Cross Referenced for ConfigurationMap.java in  » Library » Apache-commons-configuration-1.4-src » org » apache » commons » configuration » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons configuration 1.4 src » org.apache.commons.configuration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.configuration;
019:
020:        import java.util.AbstractMap;
021:        import java.util.AbstractSet;
022:        import java.util.Iterator;
023:        import java.util.Map;
024:        import java.util.Set;
025:
026:        /**
027:         * <p>The <code>ConfigurationMap</code> wraps a
028:         * configuration-collection
029:         * {@link org.apache.commons.configuration.Configuration}
030:         * instance to provide a <code>Map</code> interface.</p>
031:         *
032:         * <p><em>Note:</em> This implementation is incomplete.</p>
033:         *
034:         * @author <a href="mailto:ricardo.gladwell@btinternet.com">Ricardo Gladwell</a>
035:         * @version $Revision: 492216 $, $Date: 2007-01-03 17:51:24 +0100 (Mi, 03 Jan 2007) $
036:         * @since 1.0
037:         */
038:        public class ConfigurationMap extends AbstractMap {
039:            /**
040:             * The <code>Configuration</code> wrapped by this class.
041:             */
042:            private Configuration configuration;
043:
044:            /**
045:             * Creates a new instance of a <code>ConfigurationMap</code>
046:             * that wraps the specified <code>Configuration</code>
047:             * instance.
048:             * @param configuration <code>Configuration</code>
049:             * instance.
050:             */
051:            public ConfigurationMap(Configuration configuration) {
052:                this .configuration = configuration;
053:            }
054:
055:            /**
056:             * Returns the wrapped <code>Configuration</code> object.
057:             *
058:             * @return the wrapped configuration
059:             * @since 1.2
060:             */
061:            public Configuration getConfiguration() {
062:                return configuration;
063:            }
064:
065:            /**
066:             * Returns a set with the entries contained in this configuration-based map.
067:             *
068:             * @return a set with the contained entries
069:             * @see java.util.Map#entrySet()
070:             */
071:            public Set entrySet() {
072:                return new ConfigurationSet(configuration);
073:            }
074:
075:            /**
076:             * Stores the value for the specified key. The value is stored in the
077:             * underlying configuration.
078:             *
079:             * @param key the key (will be converted to a string)
080:             * @param value the value
081:             * @return the old value of this key or <b>null</b> if it is new
082:             * @see java.util.Map#put(java.lang.Object, java.lang.Object)
083:             */
084:            public Object put(Object key, Object value) {
085:                String strKey = String.valueOf(key);
086:                Object old = configuration.getProperty(strKey);
087:                configuration.setProperty(strKey, value);
088:                return old;
089:            }
090:
091:            /**
092:             * Returns the value of the specified key. The key is converted to a string
093:             * and then passed to the underlying configuration.
094:             *
095:             * @param key the key
096:             * @return the value of this key
097:             * @see java.util.Map#get(java.lang.Object)
098:             */
099:            public Object get(Object key) {
100:                return configuration.getProperty(String.valueOf(key));
101:            }
102:
103:            /**
104:             * Set of entries in the map.
105:             */
106:            static class ConfigurationSet extends AbstractSet {
107:                /** The configuration mapped to this entry set. */
108:                private Configuration configuration;
109:
110:                /**
111:                 * A Map entry in the ConfigurationMap.
112:                 */
113:                private final class Entry implements  Map.Entry {
114:                    /** The key of the map entry. */
115:                    private Object key;
116:
117:                    private Entry(Object key) {
118:                        this .key = key;
119:                    }
120:
121:                    public Object getKey() {
122:                        return key;
123:                    }
124:
125:                    public Object getValue() {
126:                        return configuration.getProperty((String) key);
127:                    }
128:
129:                    public Object setValue(Object value) {
130:                        Object old = getValue();
131:                        configuration.setProperty((String) key, value);
132:                        return old;
133:                    }
134:                }
135:
136:                /**
137:                 * Iterator over the entries in the ConfigurationMap.
138:                 */
139:                private final class ConfigurationSetIterator implements 
140:                        Iterator {
141:                    /** An iterator over the keys in the configuration. */
142:                    private Iterator keys;
143:
144:                    private ConfigurationSetIterator() {
145:                        keys = configuration.getKeys();
146:                    }
147:
148:                    public boolean hasNext() {
149:                        return keys.hasNext();
150:                    }
151:
152:                    public Object next() {
153:                        return new Entry(keys.next());
154:                    }
155:
156:                    public void remove() {
157:                        keys.remove();
158:                    }
159:                }
160:
161:                ConfigurationSet(Configuration configuration) {
162:                    this .configuration = configuration;
163:                }
164:
165:                /**
166:                 * @see java.util.Collection#size()
167:                 */
168:                public int size() {
169:                    // Ouch. Now _that_ one is expensive...
170:                    int count = 0;
171:                    for (Iterator iterator = configuration.getKeys(); iterator
172:                            .hasNext();) {
173:                        iterator.next();
174:                        count++;
175:                    }
176:                    return count;
177:                }
178:
179:                /**
180:                 * @see java.util.Collection#iterator()
181:                 */
182:                public Iterator iterator() {
183:                    return new ConfigurationSetIterator();
184:                }
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.