Source Code Cross Referenced for HyphenatedNameMapper.java in  » Library » Apache-commons-betwixt-0.8-src » org » apache » commons » betwixt » strategy » 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 betwixt 0.8 src » org.apache.commons.betwixt.strategy 
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.betwixt.strategy;
018:
019:        /** 
020:         * A name mapper which converts types to a hypenated String. So
021:         * a bean type of FooBar will be converted to the element name "foo-bar".
022:         * The name mapper can be configured to convert to upper case and to
023:         * use a different separator via the <code>separator</code> and 
024:         * <code>upperCase</code> properties, so that FooBar can be converted
025:         * to FOO_BAR if needed, by calling the constructor
026:         * <code>new HyphenatedNameMapper(true, "_")</code>.
027:         * 
028:         * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
029:         * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
030:         * @version $Revision: 471234 $
031:         */
032:        public class HyphenatedNameMapper implements  NameMapper {
033:
034:            /** the separator used to seperate words, which defaults to '-' */
035:            private String separator = "-";
036:
037:            /** whether upper or lower case conversions should be performed */
038:            private boolean upperCase = false;
039:
040:            /** 
041:             * Construct a hyphenated name mapper that converts the name to lower case 
042:             * and uses the default separator. 
043:             */
044:            public HyphenatedNameMapper() {
045:            }
046:
047:            /** 
048:             * Construct a hyphenated name mapper with default separator.
049:             *
050:             * @param upperCase should the type name be converted (entirely) to upper case 
051:             */
052:            public HyphenatedNameMapper(boolean upperCase) {
053:                this .upperCase = upperCase;
054:            }
055:
056:            /** 
057:             * Construct a hyphenated name mapper.
058:             *
059:             * @param upperCase should the type name be converted (entirely) to upper case 
060:             * @param separator use this string to separate the words in the name returned. 
061:             * The words in the bean name are deduced by relying on the standard camel's hump
062:             * property naming convention.
063:             */
064:            public HyphenatedNameMapper(boolean upperCase, String separator) {
065:                this .upperCase = upperCase;
066:                this .separator = separator;
067:            }
068:
069:            /**
070:             * <p>The words within the bean name are deduced assuming the
071:             * first-letter-capital (for example camel's hump) naming convention. For
072:             * example, the words in <code>FooBar</code> are <code>foo</code>
073:             * and <code>bar</code>.</p>
074:             * 
075:             * <p>Next convert all letter in the bean name to either upper case or lower case
076:             * based on the {@link #isUpperCase} property value.</p>
077:             *
078:             * <p>Then the {@link #getSeparator} property value is inserted so that it separates
079:             * each word.</p>
080:             *
081:             * @param typeName The name string to convert.  If a JavaBean
082:             * class name, should included only the last part of the name
083:             * rather than the fully qualified name (e.g. FooBar rather than
084:             * org.example.FooBar).
085:             * @return the bean name converted to either upper or lower case with words separated 
086:             * by the separator.
087:             */
088:            public String mapTypeToElementName(String typeName) {
089:
090:                int length = typeName.length();
091:                if (length == 0) {
092:                    return "";
093:                }
094:
095:                StringBuffer sb = new StringBuffer();
096:
097:                sb.append(convertChar(typeName.charAt(0)));
098:
099:                for (int i = 1; i < length; i++) {
100:                    if (Character.isUpperCase(typeName.charAt(i))) {
101:                        sb.append(separator);
102:                        sb.append(convertChar(typeName.charAt(i)));
103:                    } else {
104:                        if (upperCase) {
105:                            sb.append(convertChar(typeName.charAt(i)));
106:                        } else {
107:                            sb.append(typeName.charAt(i));
108:                        }
109:                    }
110:                }
111:
112:                return sb.toString();
113:            }
114:
115:            // Properties
116:            //-------------------------------------------------------------------------        
117:            /** 
118:             * This separator will be inserted between the words in the bean name.
119:             *
120:             * @return the separator used to seperate words, which defaults to '-' 
121:             */
122:            public String getSeparator() {
123:                return separator;
124:            }
125:
126:            /** 
127:             * Sets the separator used to seperate words, which defaults to '-' 
128:             *
129:             * @param separator the string inserted to separate words
130:             */
131:            public void setSeparator(String separator) {
132:                this .separator = separator;
133:            }
134:
135:            /** 
136:             * <p>Should the bean name be converted to upper case?
137:             * </p>
138:             * <p>
139:             * Otherwise, it will be converted to lower case.
140:             * </p>
141:             * @return whether upper or lower case conversions should be performed, 
142:             * which defaults to false for lower case
143:             */
144:            public boolean isUpperCase() {
145:                return upperCase;
146:            }
147:
148:            /** 
149:             * Sets whether upper or lower case conversions should be performed,
150:             * which defaults to false for lower case.
151:             *
152:             * @param upperCase whether the name is to be converted to upper case
153:             */
154:            public void setUpperCase(boolean upperCase) {
155:                this .upperCase = upperCase;
156:            }
157:
158:            // Implementation methods
159:            //-------------------------------------------------------------------------        
160:
161:            /** 
162:             * Performs type conversion on the given character based on whether
163:             * upper or lower case conversions are being used
164:             *
165:             * @param ch the character to be converted
166:             * @return converted to upper case if {@link #isUpperCase} otherwise to lower case 
167:             */
168:            protected char convertChar(char ch) {
169:                if (upperCase) {
170:                    return Character.toUpperCase(ch);
171:
172:                } else {
173:                    return Character.toLowerCase(ch);
174:                }
175:            }
176:
177:            /**
178:             * Outputs brief description.
179:             * @since 0.8
180:             */
181:            public String toString() {
182:                return "Hyphenated Name Mapper";
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.