Source Code Cross Referenced for JavaUtils.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » utility » 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 Services AXIS2 » jax ws » org.apache.axis2.jaxws.utility 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.axis2.jaxws.utility;
021:
022:        import java.net.MalformedURLException;
023:        import java.net.URL;
024:        import java.util.ArrayList;
025:        import java.util.StringTokenizer;
026:
027:        /** Common Java Utilites */
028:        public class JavaUtils extends org.apache.axis2.util.JavaUtils {
029:
030:            /** Private Constructor...All methods of this class are static */
031:            private JavaUtils() {
032:            }
033:
034:            /**
035:             * Namespace 2 Package algorithm as defined by the JAXB Specification
036:             *
037:             * @param Namespace
038:             * @return String represeting Namespace
039:             */
040:            public static String getPackageFromNamespace(String namespace) {
041:                // The following steps correspond to steps described in the JAXB Specification
042:
043:                // Step 1: Scan off the host name
044:                String hostname = null;
045:                String path = null;
046:                try {
047:                    URL url = new URL(namespace);
048:                    hostname = url.getHost();
049:                    path = url.getPath();
050:                } catch (MalformedURLException e) {
051:                    // No FFDC code needed
052:                    if (namespace.indexOf(":") > -1) {
053:                        // Brain-dead code to skip over the protocol
054:                        hostname = namespace
055:                                .substring(namespace.indexOf(":") + 1);
056:                    } else {
057:                        hostname = namespace;
058:                    }
059:                }
060:
061:                // Step 3: Tokenize the host name using ":" and "/"
062:                StringTokenizer st = new StringTokenizer(hostname, ":/");
063:
064:                ArrayList<String> wordList = new ArrayList<String>();
065:
066:                //Read Hostname first.
067:                for (int i = 0; st != null && i < st.countTokens(); ++i) {
068:                    wordList.add(st.nextToken());
069:                }
070:                //Read rest Of the path now
071:                if (path != null) {
072:                    StringTokenizer pathst = new StringTokenizer(path, "/");
073:                    while (pathst != null && pathst.hasMoreTokens()) {
074:                        wordList.add(pathst.nextToken());
075:                    }
076:                }
077:                String[] words = wordList.toArray(new String[0]);
078:
079:                // Now do step 2: Strip off the trailing "." (i.e. strip off .html)
080:                if (words != null && words.length > 1) {
081:                    String lastWord = words[words.length - 1];
082:                    int index = lastWord.lastIndexOf('.');
083:                    if (index > 0) {
084:                        words[words.length - 1] = lastWord.substring(0, index);
085:                    }
086:                }
087:
088:                // Step 4: Unescape each escape sequence
089:                // TODO I don't know what to do here.
090:
091:                // Step 5: If protocol is urn, replace - with . in the first word
092:                if (namespace.startsWith("urn:")) {
093:                    words[0] = replace(words[0], "-", ".");
094:                }
095:
096:                // Step 6: Tokenize the first word with "." and reverse the order. (the www is also removed).
097:                // TODO This is not exactly equivalent to the JAXB Rule.
098:                StringTokenizer st2 = new StringTokenizer(words[0], ".");
099:                ArrayList<String> list = new ArrayList<String>();
100:                while (st2.hasMoreTokens()) {
101:                    // Add the strings so they are in reverse order
102:                    list.add(0, st2.nextToken());
103:                }
104:                // Remove www
105:                String last = list.get(list.size() - 1);
106:                if (last.equals("www")) {
107:                    list.remove(list.size() - 1);
108:                }
109:                // Now each of words is represented by list
110:                for (int i = 1; i < words.length; i++) {
111:                    list.add(words[i]);
112:                }
113:
114:                // Step 7: lowercase each word
115:                for (int i = 0; i < list.size(); i++) {
116:                    String word = list.remove(i);
117:                    word = word.toLowerCase();
118:                    list.add(i, word);
119:                }
120:
121:                // Step 8: make into and an appropriate java word
122:                for (int i = 0; i < list.size(); i++) {
123:                    String word = list.get(i);
124:
125:                    // 8a: Convert special characters to underscore
126:                    // Convert non-java words to underscore.
127:                    // TODO: Need to do this for all chars..not just hyphens
128:                    word = replace(word, "-", "_");
129:
130:                    // 8b: Append _ to java keywords
131:                    if (JavaUtils.isJavaKeyword(word)) {
132:                        word = word + "_";
133:                    }
134:                    // 8c: prepend _ if first character cannot be the first character of a java identifier
135:                    if (!Character.isJavaIdentifierPart(word.charAt(0))) {
136:                        word = "_" + word;
137:                    }
138:
139:                    list.set(i, word);
140:                }
141:
142:                // Step 9: Concatenate and return
143:                String name = "";
144:                for (int i = 0; i < list.size(); i++) {
145:                    if (i == 0) {
146:                        name = list.get(0);
147:                    } else {
148:                        name = name + "." + list.get(i);
149:                    }
150:                }
151:                return name;
152:            }
153:
154:            /**
155:             * replace: Like String.replace except that the old new items are strings.
156:             *
157:             * @param name string
158:             * @param oldT old text to replace
159:             * @param newT new text to use
160:             * @return replacement string
161:             */
162:            public static final String replace(String name, String oldT,
163:                    String newT) {
164:
165:                if (name == null)
166:                    return "";
167:
168:                // Create a string buffer that is twice initial length.
169:                // This is a good starting point.
170:                StringBuffer sb = new StringBuffer(name.length() * 2);
171:
172:                int len = oldT.length();
173:                try {
174:                    int start = 0;
175:                    int i = name.indexOf(oldT, start);
176:
177:                    while (i >= 0) {
178:                        sb.append(name.substring(start, i));
179:                        sb.append(newT);
180:                        start = i + len;
181:                        i = name.indexOf(oldT, start);
182:                    }
183:                    if (start < name.length())
184:                        sb.append(name.substring(start));
185:                } catch (NullPointerException e) {
186:                    // No FFDC code needed
187:                }
188:
189:                return new String(sb);
190:            }
191:
192:            /**
193:             * Get a string containing the stack of the current location
194:             *
195:             * @return String
196:             */
197:            public static String stackToString() {
198:                return stackToString(new RuntimeException());
199:            }
200:
201:            /**
202:             * Get a string containing the stack of the specified exception
203:             *
204:             * @param e
205:             * @return
206:             */
207:            public static String stackToString(Throwable e) {
208:                java.io.StringWriter sw = new java.io.StringWriter();
209:                java.io.BufferedWriter bw = new java.io.BufferedWriter(sw);
210:                java.io.PrintWriter pw = new java.io.PrintWriter(bw);
211:                e.printStackTrace(pw);
212:                pw.close();
213:                String text = sw.getBuffer().toString();
214:                // Jump past the throwable
215:                text = text.substring(text.indexOf("at"));
216:                text = replace(text, "at ", "DEBUG_FRAME = ");
217:                return text;
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.