Source Code Cross Referenced for StrLookup.java in  » Library » Apache-common-lang » org » apache » commons » lang » text » 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 common lang » org.apache.commons.lang.text 
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:        package org.apache.commons.lang.text;
018:
019:        import java.util.Map;
020:
021:        /**
022:         * Lookup a String key to a String value.
023:         * <p>
024:         * This class represents the simplest form of a string to string map.
025:         * It has a benefit over a map in that it can create the result on
026:         * demand based on the key.
027:         * <p>
028:         * This class comes complete with various factory methods.
029:         * If these do not suffice, you can subclass and implement your own matcher.
030:         * <p>
031:         * For example, it would be possible to implement a lookup that used the
032:         * key as a primary key, and looked up the value on demand from the database
033:         *
034:         * @author Stephen Colebourne
035:         * @since 2.2
036:         * @version $Id: StrLookup.java 437554 2006-08-28 06:21:41Z bayard $
037:         */
038:        public abstract class StrLookup {
039:
040:            /**
041:             * Lookup that always returns null.
042:             */
043:            private static final StrLookup NONE_LOOKUP;
044:            /**
045:             * Lookup that uses System properties.
046:             */
047:            private static final StrLookup SYSTEM_PROPERTIES_LOOKUP;
048:            static {
049:                NONE_LOOKUP = new MapStrLookup(null);
050:                StrLookup lookup = null;
051:                try {
052:                    lookup = new MapStrLookup(System.getProperties());
053:                } catch (SecurityException ex) {
054:                    lookup = NONE_LOOKUP;
055:                }
056:                SYSTEM_PROPERTIES_LOOKUP = lookup;
057:            }
058:
059:            //-----------------------------------------------------------------------
060:            /**
061:             * Returns a lookup which always returns null.
062:             *
063:             * @return a lookup that always returns null, not null
064:             */
065:            public static StrLookup noneLookup() {
066:                return NONE_LOOKUP;
067:            }
068:
069:            /**
070:             * Returns a lookup which uses {@link System#getProperties() System properties}
071:             * to lookup the key to value.
072:             * <p>
073:             * If a security manager blocked access to system properties, then null will
074:             * be returned from every lookup.
075:             * <p>
076:             * If a null key is used, this lookup will throw a NullPointerException.
077:             *
078:             * @return a lookup using system properties, not null
079:             */
080:            public static StrLookup systemPropertiesLookup() {
081:                return SYSTEM_PROPERTIES_LOOKUP;
082:            }
083:
084:            /**
085:             * Returns a lookup which looks up values using a map.
086:             * <p>
087:             * If the map is null, then null will be returned from every lookup.
088:             * The map result object is converted to a string using toString().
089:             *
090:             * @param map  the map of keys to values, may be null
091:             * @return a lookup using the map, not null
092:             */
093:            public static StrLookup mapLookup(Map map) {
094:                return new MapStrLookup(map);
095:            }
096:
097:            //-----------------------------------------------------------------------
098:            /**
099:             * Constructor.
100:             */
101:            protected StrLookup() {
102:                super ();
103:            }
104:
105:            /**
106:             * Looks up a String key to a String value.
107:             * <p>
108:             * The internal implementation may use any mechanism to return the value.
109:             * The simplest implementation is to use a Map. However, virtually any
110:             * implementation is possible.
111:             * <p>
112:             * For example, it would be possible to implement a lookup that used the
113:             * key as a primary key, and looked up the value on demand from the database
114:             * Or, a numeric based implementation could be created that treats the key
115:             * as an integer, increments the value and return the result as a string -
116:             * converting 1 to 2, 15 to 16 etc.
117:             *
118:             * @param key  the key to be looked up, may be null
119:             * @return the matching value, null if no match
120:             */
121:            public abstract String lookup(String key);
122:
123:            //-----------------------------------------------------------------------
124:            /**
125:             * Lookup imnplementation that uses a Map.
126:             */
127:            static class MapStrLookup extends StrLookup {
128:
129:                /** Map keys are variable names and value. */
130:                private final Map map;
131:
132:                /**
133:                 * Creates a new instance backed by a Map.
134:                 *
135:                 * @param map  the map of keys to values, may be null
136:                 */
137:                MapStrLookup(Map map) {
138:                    this .map = map;
139:                }
140:
141:                /**
142:                 * Looks up a String key to a String value using the map.
143:                 * <p>
144:                 * If the map is null, then null is returned.
145:                 * The map result object is converted to a string using toString().
146:                 *
147:                 * @param key  the key to be looked up, may be null
148:                 * @return the matching value, null if no match
149:                 */
150:                public String lookup(String key) {
151:                    if (map == null) {
152:                        return null;
153:                    }
154:                    Object obj = map.get(key);
155:                    if (obj == null) {
156:                        return null;
157:                    }
158:                    return obj.toString();
159:                }
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.