Source Code Cross Referenced for ReplacementTable.java in  » Testing » DbUnit » org » dbunit » dataset » 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 » Testing » DbUnit » org.dbunit.dataset 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * The DbUnit Database Testing Framework
004:         * Copyright (C)2002-2004, DbUnit.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         */
021:        package org.dbunit.dataset;
022:
023:        import org.slf4j.Logger;
024:        import org.slf4j.LoggerFactory;
025:
026:        import java.util.HashMap;
027:        import java.util.Iterator;
028:        import java.util.Map;
029:
030:        /**
031:         * Decorator that replace configured values from the decorated table
032:         * with replacement values.
033:         *
034:         * @author Manuel Laflamme
035:         * @since Mar 17, 2003
036:         * @version $Revision: 581 $
037:         */
038:        public class ReplacementTable implements  ITable {
039:
040:            /**
041:             * Logger for this class
042:             */
043:            private static final Logger logger = LoggerFactory
044:                    .getLogger(ReplacementTable.class);
045:
046:            private final ITable _table;
047:            private final Map _objectMap;
048:            private final Map _substringMap;
049:            private String _startDelim;
050:            private String _endDelim;
051:
052:            /**
053:             * Create a new ReplacementTable object that decorates the specified table.
054:             *
055:             * @param table the decorated table
056:             */
057:            public ReplacementTable(ITable table) {
058:                this (table, new HashMap(), new HashMap(), null, null);
059:            }
060:
061:            public ReplacementTable(ITable table, Map objectMap,
062:                    Map substringMap, String startDelimiter, String endDelimiter) {
063:                _table = table;
064:                _objectMap = objectMap;
065:                _substringMap = substringMap;
066:                _startDelim = startDelimiter;
067:                _endDelim = endDelimiter;
068:            }
069:
070:            /**
071:             * Add a new Object replacement mapping.
072:             *
073:             * @param originalObject the object to replace
074:             * @param replacementObject the replacement object
075:             */
076:            public void addReplacementObject(Object originalObject,
077:                    Object replacementObject) {
078:                logger.debug("addReplacementObject(originalObject="
079:                        + originalObject + ", replacementObject="
080:                        + replacementObject + ") - start");
081:
082:                _objectMap.put(originalObject, replacementObject);
083:            }
084:
085:            /**
086:             * Add a new substring replacement mapping.
087:             *
088:             * @param originalSubstring the substring to replace
089:             * @param replacementSubstring the replacement substring
090:             */
091:            public void addReplacementSubstring(String originalSubstring,
092:                    String replacementSubstring) {
093:                logger.debug("addReplacementSubstring(originalSubstring="
094:                        + originalSubstring + ", replacementSubstring="
095:                        + replacementSubstring + ") - start");
096:
097:                if (originalSubstring == null || replacementSubstring == null) {
098:                    throw new NullPointerException();
099:                }
100:
101:                _substringMap.put(originalSubstring, replacementSubstring);
102:            }
103:
104:            /**
105:             * Sets substring delimiters.
106:             */
107:            public void setSubstringDelimiters(String startDelimiter,
108:                    String endDelimiter) {
109:                logger.debug("setSubstringDelimiters(startDelimiter="
110:                        + startDelimiter + ", endDelimiter=" + endDelimiter
111:                        + ") - start");
112:
113:                if (startDelimiter == null || endDelimiter == null) {
114:                    throw new NullPointerException();
115:                }
116:
117:                _startDelim = startDelimiter;
118:                _endDelim = endDelimiter;
119:            }
120:
121:            /**
122:             * Replace occurrences of source in text with target. Operates directly on text.
123:             */
124:            private void replaceAll(StringBuffer text, String source,
125:                    String target) {
126:                int index = 0;
127:                while ((index = text.toString().indexOf(source, index)) != -1) {
128:                    text.replace(index, index + source.length(), target);
129:                    index += target.length();
130:                }
131:            }
132:
133:            private String replaceStrings(String value, String lDelim,
134:                    String rDelim) {
135:                StringBuffer buffer = new StringBuffer(value);
136:
137:                for (Iterator it = _substringMap.entrySet().iterator(); it
138:                        .hasNext();) {
139:                    Map.Entry entry = (Map.Entry) it.next();
140:                    String original = (String) entry.getKey();
141:                    String replacement = (String) entry.getValue();
142:                    replaceAll(buffer, lDelim + original + rDelim, replacement);
143:                }
144:
145:                return buffer == null ? value : buffer.toString();
146:            }
147:
148:            private String replaceSubstrings(String value) {
149:                return replaceStrings(value, "", "");
150:            }
151:
152:            private String replaceDelimitedSubstrings(String value) {
153:                return replaceStrings(value, _startDelim, _endDelim);
154:            }
155:
156:            ////////////////////////////////////////////////////////////////////////
157:            // ITable interface
158:
159:            public ITableMetaData getTableMetaData() {
160:                logger.debug("getTableMetaData() - start");
161:
162:                return _table.getTableMetaData();
163:            }
164:
165:            public int getRowCount() {
166:                logger.debug("getRowCount() - start");
167:
168:                return _table.getRowCount();
169:            }
170:
171:            public Object getValue(int row, String column)
172:                    throws DataSetException {
173:                logger.debug("getValue(row=" + row + ", column=" + column
174:                        + ") - start");
175:
176:                Object value = _table.getValue(row, column);
177:
178:                // Object replacement
179:                if (_objectMap.containsKey(value)) {
180:                    return _objectMap.get(value);
181:                }
182:
183:                // Stop here if substring replacement not applicable
184:                if (_substringMap.size() == 0 || !(value instanceof  String)) {
185:                    return value;
186:                }
187:
188:                // Substring replacement
189:                if (_startDelim != null && _endDelim != null) {
190:                    return replaceDelimitedSubstrings((String) value);
191:                }
192:                return replaceSubstrings((String) value);
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.