Source Code Cross Referenced for PropertyResourceBundle.java in  » 6.0-JDK-Core » Collections-Jar-Zip-Logging-regex » java » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
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
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » Collections Jar Zip Logging regex » java.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1996-2006 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        /*
027         * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
028         * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
029         *
030         * The original version of this source code and documentation
031         * is copyrighted and owned by Taligent, Inc., a wholly-owned
032         * subsidiary of IBM. These materials are provided under terms
033         * of a License Agreement between Taligent and Sun. This technology
034         * is protected by multiple US and International patents.
035         *
036         * This notice and attribution to Taligent may not be removed.
037         * Taligent is a registered trademark of Taligent, Inc.
038         */
039
040        package java.util;
041
042        import java.io.InputStream;
043        import java.io.Reader;
044        import java.io.IOException;
045        import sun.util.ResourceBundleEnumeration;
046
047        /**
048         * <code>PropertyResourceBundle</code> is a concrete subclass of
049         * <code>ResourceBundle</code> that manages resources for a locale
050         * using a set of static strings from a property file. See
051         * {@link ResourceBundle ResourceBundle} for more information about resource
052         * bundles. 
053         *
054         * <p>
055         * Unlike other types of resource bundle, you don't subclass
056         * <code>PropertyResourceBundle</code>.  Instead, you supply properties
057         * files containing the resource data.  <code>ResourceBundle.getBundle</code>
058         * will automatically look for the appropriate properties file and create a
059         * <code>PropertyResourceBundle</code> that refers to it. See
060         * {@link ResourceBundle#getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader) ResourceBundle.getBundle}
061         * for a complete description of the search and instantiation strategy.
062         *
063         * <p>
064         * The following <a name="sample">example</a> shows a member of a resource
065         * bundle family with the base name "MyResources".
066         * The text defines the bundle "MyResources_de",
067         * the German member of the bundle family.
068         * This member is based on <code>PropertyResourceBundle</code>, and the text
069         * therefore is the content of the file "MyResources_de.properties"
070         * (a related <a href="ListResourceBundle.html#sample">example</a> shows
071         * how you can add bundles to this family that are implemented as subclasses
072         * of <code>ListResourceBundle</code>).
073         * The keys in this example are of the form "s1" etc. The actual
074         * keys are entirely up to your choice, so long as they are the same as
075         * the keys you use in your program to retrieve the objects from the bundle.
076         * Keys are case-sensitive.
077         * <blockquote>
078         * <pre>
079         * # MessageFormat pattern
080         * s1=Die Platte \"{1}\" enth&auml;lt {0}.
081         *
082         * # location of {0} in pattern
083         * s2=1
084         *
085         * # sample disk name
086         * s3=Meine Platte
087         *
088         * # first ChoiceFormat choice
089         * s4=keine Dateien
090         *
091         * # second ChoiceFormat choice
092         * s5=eine Datei
093         *
094         * # third ChoiceFormat choice
095         * s6={0,number} Dateien
096         *
097         * # sample date
098         * s7=3. M&auml;rz 1996
099         * </pre>
100         * </blockquote>
101         *
102         * <p>
103         * <strong>Note:</strong> PropertyResourceBundle can be constructed either 
104         * from an InputStream or a Reader, which represents a property file.  
105         * Constructing a PropertyResourceBundle instance from an InputStream requires 
106         * that the input stream be encoded in ISO-8859-1.  In that case, characters 
107         * that cannot be represented in ISO-8859-1 encoding must be represented by 
108         * <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.3">Unicode Escapes</a>, 
109         * whereas the other constructor which takes a Reader does not have that limitation.
110         *
111         * @see ResourceBundle
112         * @see ListResourceBundle
113         * @see Properties
114         * @since JDK1.1
115         */
116        public class PropertyResourceBundle extends ResourceBundle {
117            /**
118             * Creates a property resource bundle from an {@link java.io.InputStream
119             * InputStream}.  The property file read with this constructor
120             * must be encoded in ISO-8859-1.
121             *
122             * @param stream an InputStream that represents a property file
123             *        to read from.
124             * @throws IOException if an I/O error occurs
125             * @throws NullPointerException if <code>stream</code> is null
126             */
127            public PropertyResourceBundle(InputStream stream)
128                    throws IOException {
129                Properties properties = new Properties();
130                properties.load(stream);
131                lookup = new HashMap(properties);
132            }
133
134            /**
135             * Creates a property resource bundle from a {@link java.io.Reader
136             * Reader}.  Unlike the constructor
137             * {@link #PropertyResourceBundle(java.io.InputStream) PropertyResourceBundle(InputStream)}, 
138             * there is no limitation as to the encoding of the input property file.
139             *
140             * @param reader a Reader that represents a property file to
141             *        read from.
142             * @throws IOException if an I/O error occurs
143             * @throws NullPointerException if <code>reader</code> is null
144             * @since 1.6
145             */
146            public PropertyResourceBundle(Reader reader) throws IOException {
147                Properties properties = new Properties();
148                properties.load(reader);
149                lookup = new HashMap(properties);
150            }
151
152            // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
153            public Object handleGetObject(String key) {
154                if (key == null) {
155                    throw new NullPointerException();
156                }
157                return lookup.get(key);
158            }
159
160            /**
161             * Returns an <code>Enumeration</code> of the keys contained in
162             * this <code>ResourceBundle</code> and its parent bundles.
163             *
164             * @return an <code>Enumeration</code> of the keys contained in
165             *         this <code>ResourceBundle</code> and its parent bundles.
166             * @see #keySet()
167             */
168            public Enumeration<String> getKeys() {
169                ResourceBundle parent = this .parent;
170                return new ResourceBundleEnumeration(lookup.keySet(),
171                        (parent != null) ? parent.getKeys() : null);
172            }
173
174            /**
175             * Returns a <code>Set</code> of the keys contained
176             * <em>only</em> in this <code>ResourceBundle</code>.
177             *
178             * @return a <code>Set</code> of the keys contained only in this
179             *         <code>ResourceBundle</code>
180             * @since 1.6
181             * @see #keySet()
182             */
183            protected Set<String> handleKeySet() {
184                return lookup.keySet();
185            }
186
187            // ==================privates====================
188
189            private Map<String, Object> lookup;
190        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.