Source Code Cross Referenced for URIParserUtil.java in  » ESB » celtix-1.0 » org » objectweb » celtix » tools » utils » 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 » ESB » celtix 1.0 » org.objectweb.celtix.tools.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.tools.utils;
002:
003:        import java.util.ArrayList;
004:        import java.util.Arrays;
005:        import java.util.HashSet;
006:        import java.util.List;
007:        import java.util.Set;
008:        import java.util.StringTokenizer;
009:
010:        public final class URIParserUtil {
011:            private static final Set<String> KEYWORDS = new HashSet<String>(
012:                    Arrays
013:                            .asList(new String[] { "abstract", "boolean",
014:                                    "break", "byte", "case", "catch", "char",
015:                                    "class", "const", "continue", "default",
016:                                    "do", "double", "else", "extends", "final",
017:                                    "finally", "float", "for", "goto", "if",
018:                                    "implements", "import", "instanceof",
019:                                    "int", "interface", "long", "native",
020:                                    "new", "package", "private", "protected",
021:                                    "public", "return", "short", "static",
022:                                    "strictfp", "super", "switch",
023:                                    "synchronized", "this", "throw", "throws",
024:                                    "transient", "try", "void", "volatile",
025:                                    "while", "true", "false", "null", "assert",
026:                                    "enum" }));
027:
028:            private URIParserUtil() {
029:                // complete
030:            }
031:
032:            public static String getPackageName(String nameSpaceURI) {
033:                int idx = nameSpaceURI.indexOf(':');
034:                String scheme = "";
035:                if (idx >= 0) {
036:                    scheme = nameSpaceURI.substring(0, idx);
037:                    if ("http".equalsIgnoreCase(scheme)
038:                            || "urn".equalsIgnoreCase(scheme)) {
039:                        nameSpaceURI = nameSpaceURI.substring(idx + 1);
040:                    }
041:                }
042:
043:                List<String> tokens = tokenize(nameSpaceURI, "/: ");
044:                if (tokens.size() == 0) {
045:                    return null;
046:                }
047:
048:                if (tokens.size() > 1) {
049:                    String lastToken = tokens.get(tokens.size() - 1);
050:                    idx = lastToken.lastIndexOf('.');
051:                    if (idx > 0) {
052:                        lastToken = lastToken.substring(0, idx);
053:                        tokens.set(tokens.size() - 1, lastToken);
054:                    }
055:                }
056:
057:                String domain = tokens.get(0);
058:                idx = domain.indexOf(':');
059:                if (idx >= 0) {
060:                    domain = domain.substring(0, idx);
061:                }
062:                List<String> r = reverse(tokenize(domain,
063:                        "urn".equals(scheme) ? ".-" : "."));
064:                if ("www".equalsIgnoreCase(r.get(r.size() - 1))) {
065:                    // remove leading www
066:                    r.remove(r.size() - 1);
067:                }
068:
069:                // replace the domain name with tokenized items
070:                tokens.addAll(1, r);
071:                tokens.remove(0);
072:
073:                // iterate through the tokens and apply xml->java name algorithm
074:                for (int i = 0; i < tokens.size(); i++) {
075:
076:                    // get the token and remove illegal chars
077:                    String token = tokens.get(i);
078:                    token = removeIllegalIdentifierChars(token);
079:
080:                    // this will check for reserved keywords
081:                    if (contiansReservedKeywords(token)) {
082:                        token = '_' + token;
083:                    }
084:
085:                    tokens.set(i, token.toLowerCase());
086:                }
087:
088:                // concat all the pieces and return it
089:                return combine(tokens, '.');
090:            }
091:
092:            public static String getNamespace(String packageName) {
093:                if (packageName == null || packageName.length() == 0) {
094:                    return null;
095:                }
096:                StringTokenizer tokenizer = new StringTokenizer(packageName,
097:                        ".");
098:                String[] tokens;
099:                if (tokenizer.countTokens() == 0) {
100:                    tokens = new String[0];
101:                } else {
102:                    tokens = new String[tokenizer.countTokens()];
103:                    for (int i = tokenizer.countTokens() - 1; i >= 0; i--) {
104:                        tokens[i] = tokenizer.nextToken();
105:                    }
106:                }
107:                StringBuffer namespace = new StringBuffer("http://");
108:                String dot = "";
109:                for (int i = 0; i < tokens.length; i++) {
110:                    if (i == 1) {
111:                        dot = ".";
112:                    }
113:                    namespace.append(dot + tokens[i]);
114:                }
115:                namespace.append('/');
116:                return namespace.toString();
117:            }
118:
119:            private static List<String> tokenize(String str, String sep) {
120:                StringTokenizer tokens = new StringTokenizer(str, sep);
121:                List<String> r = new ArrayList<String>();
122:
123:                while (tokens.hasMoreTokens()) {
124:                    r.add(tokens.nextToken());
125:                }
126:                return r;
127:            }
128:
129:            private static String removeIllegalIdentifierChars(String token) {
130:                StringBuffer newToken = new StringBuffer();
131:                for (int i = 0; i < token.length(); i++) {
132:                    char c = token.charAt(i);
133:
134:                    if (i == 0 && !Character.isJavaIdentifierStart(c)) {
135:                        // prefix an '_' if the first char is illegal
136:                        newToken.append("_" + c);
137:                    } else if (!Character.isJavaIdentifierPart(c)) {
138:                        // replace the char with an '_' if it is illegal
139:                        newToken.append('_');
140:                    } else {
141:                        // add the legal char
142:                        newToken.append(c);
143:                    }
144:                }
145:                return newToken.toString();
146:            }
147:
148:            private static String combine(List r, char sep) {
149:                StringBuilder buf = new StringBuilder(r.get(0).toString());
150:
151:                for (int i = 1; i < r.size(); i++) {
152:                    buf.append(sep);
153:                    buf.append(r.get(i));
154:                }
155:
156:                return buf.toString();
157:            }
158:
159:            private static <T> List<T> reverse(List<T> a) {
160:                List<T> r = new ArrayList<T>();
161:
162:                for (int i = a.size() - 1; i >= 0; i--) {
163:                    r.add(a.get(i));
164:                }
165:                return r;
166:            }
167:
168:            private static boolean contiansReservedKeywords(String token) {
169:                return KEYWORDS.contains(token);
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.