Source Code Cross Referenced for StandardNamingStrategy.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » backend » list » helper » naming » 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 » Web Framework » aranea mvc 1.1.1 » org.araneaframework.backend.list.helper.naming 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2006 Webmedia Group Ltd.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *  http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         **/package org.araneaframework.backend.list.helper.naming;
016:
017:        import org.araneaframework.uilib.util.NameUtil;
018:
019:        /**
020:         * Standard naming conventions between list fields and database columns.
021:         * <p>
022:         * Field names are transformed into database column names as following:<br/>
023:         * <ul>
024:         * <li>The full name is split into prefix and suffix (following to the last dot).
025:         * <li>All dots in the prefix and suffix are converted into underscores.
026:         * <li>Before each upper case letter followed by lower case an underscore is inserted.
027:         * </ul>
028:         * E.g:
029:         * <pre>
030:         *   firstName -> first_name
031:         *   location.address -> location.address
032:         *   client.group.id -> client_group.id
033:         * </pre>
034:         * Field names are transformed into database column aliases as following:<br/><br/>
035:         * <ul>
036:         * <li>All dots are converted into underscores.
037:         * <li>Before each upper case letter followed by lower case an underscore is inserted.
038:         * </ul>
039:         * E.g:
040:         * <pre>
041:         *   lastName -> last_name
042:         *   location.address -> location_address
043:         *   client.group.id -> client_group_id
044:         * </pre>
045:         * </p>
046:         * 
047:         * @author Rein Raudjärv
048:         * 
049:         * @since 1.1
050:         */
051:        public class StandardNamingStrategy implements  NamingStrategy {
052:
053:            // --- Column Name ---
054:
055:            public String fieldToColumnName(String fieldName) {
056:                String prefix = resolvePrefix(extractPrefix(fieldName));
057:                String suffix = resolveSuffix(extractSuffix(fieldName));
058:                return concatFullname(prefix, suffix);
059:            }
060:
061:            protected String extractPrefix(String varName) {
062:                return NameUtil.getLongestPrefix(varName);
063:            }
064:
065:            protected String extractSuffix(String varName) {
066:                return NameUtil.getShortestSuffix(varName);
067:            }
068:
069:            protected String resolvePrefix(String fieldNamePrefix) {
070:                return addUnderscores(fieldNamePrefix);
071:            }
072:
073:            protected String resolveSuffix(String fieldNameSuffix) {
074:                return addUnderscores(fieldNameSuffix);
075:            }
076:
077:            protected String concatFullname(String prefix, String suffix) {
078:                return NameUtil.getFullName(prefix, suffix);
079:            }
080:
081:            // --- Column Alias ---
082:
083:            public String fieldToColumnAlias(String fieldName) {
084:                return addUnderscores(fieldName);
085:            }
086:
087:            // --- Utils ---
088:
089:            /**
090:             * Replace all dots with underscores
091:             * and add an underscore before upper-case letters
092:             * followed by a non-upper-case letter.
093:             * <p>
094:             * E.g.
095:             * <pre>
096:             * "a" -> "a"
097:             * "a.b" -> "a_b"
098:             * "aBc" -> "a_bc"
099:             * "aB" -> "aB"
100:             * </pre>
101:             */
102:            public static String addUnderscores(String name) {
103:                if (name == null) {
104:                    return null;
105:                }
106:
107:                StringBuffer buf = new StringBuffer(name.replace('.', '_'));
108:                for (int i = 1; i < buf.length() - 1; i++) {
109:                    if ('_' != buf.charAt(i - 1)
110:                            && Character.isUpperCase(buf.charAt(i))
111:                            && !Character.isUpperCase(buf.charAt(i + 1))) {
112:                        buf.insert(i++, '_');
113:                    }
114:                }
115:                return buf.toString().toLowerCase();
116:            }
117:
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.