KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > util > WebArchiveLoadableHelper


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.verifier.tests.util;
25
26 import java.io.File JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.StringTokenizer JavaDoc;
31 import java.util.Stack JavaDoc;
32
33 import com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompiler;
34 import com.sun.enterprise.tools.verifier.StringManagerHelper;
35 import com.sun.enterprise.util.LocalStringManagerImpl;
36
37 /**
38  * @author Sudipto Ghosh
39  */

40 public class WebArchiveLoadableHelper {
41
42     public static String JavaDoc getFailedResults(ClosureCompiler cc, File JavaDoc jspDir) {
43         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
44         sb.append("\n");
45         for (Object JavaDoc o : cc.getFailed().entrySet()) {
46             Map.Entry JavaDoc<String JavaDoc, List JavaDoc<String JavaDoc>> referencingPathToFailedList =
47                     (Map.Entry JavaDoc<String JavaDoc, List JavaDoc<String JavaDoc>>)o;
48             LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager();
49             String JavaDoc classes = "Failed to find following classes:";
50             if (smh != null) {
51                 classes = smh.getLocalString(
52                         WebArchiveLoadableHelper.class.getName() + ".classes",
53                         classes);
54             }
55             sb.append(classes).append("\n[");
56             for (Iterator JavaDoc<String JavaDoc> iii = referencingPathToFailedList.getValue().iterator();
57                  iii.hasNext();) {
58                 sb.append("\n\t").append(iii.next());
59                 if(iii.hasNext()) sb.append(",");
60             }
61             sb.append("\n]");
62             String JavaDoc referencingPath = referencingPathToFailedList.getKey();
63             if(referencingPath.length()==0) continue; // skip if a top level class is not found
64
String JavaDoc ref = "referenced in the following call stack :";
65             String JavaDoc reference = "at";
66             if (smh != null) {
67                 ref = smh.getLocalString(
68                         WebArchiveLoadableHelper.class.getName() + ".ref",
69                         ref);
70                 reference = smh.getLocalString(
71                         WebArchiveLoadableHelper.class.getName() + ".reference",
72                         reference);
73             }
74             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(referencingPath, File.separator);
75             Stack JavaDoc<String JavaDoc> referencingClassStack = new Stack JavaDoc<String JavaDoc>();
76             boolean jspDirExists = (jspDir != null && jspDir.exists());
77             final String JavaDoc jspPkgName = "org.apache.jsp.";
78             while(st.hasMoreTokens()) {
79                 String JavaDoc className = st.nextToken();
80                 //This logic is to map the compiled jsp class to original jsp name.
81
//The logic is to find whether the ref class is in jsp out dir. If true
82
//then maniputale the ref class to get the jsp name
83
String JavaDoc fileName = className.replace(".", File.separator)+".class";
84                 if (jspDirExists &&
85                         className.startsWith(jspPkgName) &&
86                         new File JavaDoc(jspDir, fileName).exists()) {
87                     StringBuilder JavaDoc jspName = new StringBuilder JavaDoc(
88                             className.substring(jspPkgName.length()));
89                     int innerClassIndex = jspName.indexOf("$");
90                     if (innerClassIndex != -1) {
91                         jspName = jspName.replace(innerClassIndex, jspName.length(), "");
92                     }
93                     if(jspName.toString().endsWith("_jsp")) {
94                         jspName = jspName.replace(jspName.lastIndexOf("_jsp"),
95                                 jspName.length(), ".jsp");
96                     } else if(jspName.toString().endsWith("_jspx")) {
97                         jspName = jspName.replace(jspName.lastIndexOf("_jspx"),
98                                 jspName.length(), ".jspx");
99                     }
100                     className = jspName.toString();
101                 }
102                 referencingClassStack.push(className);
103             }
104             if ((!referencingClassStack.isEmpty()))
105                 sb.append("\n\n"+ref);
106             while(!referencingClassStack.isEmpty()){
107                 sb.append("\n\t").append(reference).append(" ");
108                 sb.append(referencingClassStack.pop());
109             }
110             sb.append("\n\n");
111         }
112         return sb.toString();
113     }
114 }
115
116
Popular Tags