Source Code Cross Referenced for TranslationUtils.java in  » UML » AndroMDA-3.2 » org » andromda » core » translation » 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 » UML » AndroMDA 3.2 » org.andromda.core.translation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.core.translation;
002:
003:        import org.andromda.core.common.ExceptionUtils;
004:        import org.andromda.core.common.Introspector;
005:        import org.apache.commons.lang.ObjectUtils;
006:        import org.apache.commons.lang.StringUtils;
007:
008:        /**
009:         * Contains translation utilities.
010:         *
011:         * @author Chad Brandon
012:         */
013:        public class TranslationUtils {
014:            /**
015:             * <p/>
016:             * <code>TranslationUtils</code> instances should NOT be constructed in standard programming. Instead, the class
017:             * should be used as <code>TranslationUtils.replacePattern(" some pattern ");</code>. </p>
018:             * <p/>
019:             * This constructor is public to permit tools that require a JavaBean instance to operate. </p>
020:             */
021:            public TranslationUtils() {
022:                // Here for documentation purposes
023:            }
024:
025:            /**
026:             * Searches for and replaces the specified pattern with braces around it, like so --> "{pattern}" every time it
027:             * occurs in the string.
028:             *
029:             * @param string      the string to to perform replacement on.
030:             * @param pattern     the pattern to find
031:             * @param replaceWith the pattern to place the existing one with.
032:             * @return String the string will all replacements
033:             */
034:            public static String replacePattern(String string,
035:                    final String pattern, final String replaceWith) {
036:                if (string != null) {
037:                    ExceptionUtils.checkNull("pattern", pattern);
038:                    ExceptionUtils.checkNull("replaceWith", replaceWith);
039:                    string = StringUtils.replace(string, "{" + pattern + "}",
040:                            replaceWith);
041:                }
042:                return string;
043:            }
044:
045:            /**
046:             * Searches for and replaces the specified pattern with braces around it, like so --> "{pattern}" the first time it
047:             * occurs in the string
048:             *
049:             * @param string      the string to to perform replacement on.
050:             * @param pattern     the pattern to find
051:             * @param replaceWith the pattern to place the existing one with.
052:             * @return String the string will all replacements
053:             */
054:            public static String replaceFirstPattern(String string,
055:                    final String pattern, final String replaceWith) {
056:                if (string != null) {
057:                    ExceptionUtils.checkNull("pattern", pattern);
058:                    ExceptionUtils.checkNull("replaceWith", replaceWith);
059:                    string = StringUtils.replaceOnce(string, "{" + pattern
060:                            + "}", replaceWith);
061:                }
062:                return string;
063:            }
064:
065:            /**
066:             * Returns true if the specified pattern with braces around it, like so --> "{pattern}" exists in the string.
067:             *
068:             * @param string  the string to to perform replacement on.
069:             * @param pattern the pattern to find
070:             * @return boolean true if the string contains the pattern, false otherwise
071:             */
072:            public static boolean containsPattern(final String string,
073:                    final String pattern) {
074:                boolean containsPattern = string != null && pattern != null;
075:                if (containsPattern) {
076:                    containsPattern = StringUtils.contains(string, "{"
077:                            + pattern + "}");
078:                }
079:                return containsPattern;
080:            }
081:
082:            /**
083:             * Calls the object's toString method and trims the value. Returns and empty string if null is given.
084:             *
085:             * @param object the object to use.
086:             * @return String
087:             */
088:            public static String trimToEmpty(final Object object) {
089:                return StringUtils.trimToEmpty(ObjectUtils.toString(object));
090:            }
091:
092:            /**
093:             * Calls the object's toString method and deletes any whitespace from the value. Returns and empty string if null is
094:             * given.
095:             *
096:             * @param object the object to deleteWhite space from.
097:             * @return String
098:             */
099:            public static String deleteWhitespace(final Object object) {
100:                return StringUtils.deleteWhitespace(ObjectUtils
101:                        .toString(object));
102:            }
103:
104:            /**
105:             * Retrieves the "starting" property name from one that is nested, for example, will return ' <name1>' from the
106:             * string --> <name1>. <name2>. <name3>. If the property isn't nested, then just return the name that is passed in.
107:             *
108:             * @param property the property.
109:             * @return String
110:             */
111:            public static String getStartingProperty(String property) {
112:                StringUtils.trimToEmpty(property);
113:                int dotIndex = property.indexOf('.');
114:                if (dotIndex != -1) {
115:                    property = property.substring(0, dotIndex);
116:                }
117:                return property;
118:            }
119:
120:            /**
121:             * Removes any extra whitepace --> does not remove the spaces between the words. Only removes tabs and newline
122:             * characters. This is to allow everything to be on one line while keeping the spaces between words.
123:             *
124:             * @param string
125:             * @return String the string with the removed extra spaces.
126:             */
127:            public static String removeExtraWhitespace(final String string) {
128:                return string == null ? "" : string.replaceAll("[$\\s]+", " ")
129:                        .trim();
130:            }
131:
132:            /**
133:             * Just retriieves properties from a bean, but gives a more informational error when the property can't be
134:             * retrieved, it also cleans the resulting property from any excess white space
135:             *
136:             * @param bean     the bean from which to retrieve the property
137:             * @param property the property name
138:             * @return Object the value of the property
139:             */
140:            public static Object getProperty(final Object bean,
141:                    final String property) {
142:                final String methodName = "TranslationUtils.getProperty";
143:                try {
144:                    return Introspector.instance().getProperty(bean, property);
145:                } catch (final Exception exception) {
146:                    throw new TranslatorException("Error performing "
147:                            + methodName + " with bean '" + bean
148:                            + "' and property '" + property + "'", exception);
149:                }
150:            }
151:
152:            /**
153:             * Just retriieves properties from a bean, but gives a more informational error when the property can't be
154:             * retrieved, it also cleans the resulting property from any excess white space
155:             *
156:             * @param bean     the bean from which to retrieve the property
157:             * @param property the property name
158:             * @return Object the value of the property
159:             */
160:            public static String getPropertyAsString(final Object bean,
161:                    final String property) {
162:                return TranslationUtils.trimToEmpty(TranslationUtils
163:                        .getProperty(bean, property));
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.