KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompiler;
27 import com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompilerImpl;
28 import com.sun.enterprise.tools.verifier.StringManagerHelper;
29 import com.sun.enterprise.util.LocalStringManagerImpl;
30
31 import java.util.*;
32 import java.io.File JavaDoc;
33
34 /**
35  * This class is a helper around {@link ClosureCompiler}.
36  *
37  * @author Sanjeeb.Sahoo@Sun.COM
38  */

39 public class ArchiveClassesLoadableHelper {
40     /**
41      * This method is used to print the result in various
42      * *ArchiveClassesLoadable tests.
43      * @param cc a closure compiler which provides the necesasry information
44      * @return a localized string which contains the details.
45      */

46     public static String JavaDoc getFailedResult(ClosureCompiler cc){
47         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
48         sb.append("\n");
49         for (Object JavaDoc o : cc.getFailed().entrySet()) {
50             Map.Entry<String JavaDoc, List<String JavaDoc>> referencingPathToFailedList =
51                     (Map.Entry<String JavaDoc, List<String JavaDoc>>)o;
52             LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager();
53             String JavaDoc classes = "Failed to find following classes:";
54             if (smh != null) {
55                 classes = smh.getLocalString(
56                         ArchiveClassesLoadableHelper.class.getName() + ".classes",
57                         classes);
58             }
59             sb.append(classes).append("\n[");
60             for (Iterator<String JavaDoc> iii = referencingPathToFailedList.getValue().iterator();
61                  iii.hasNext();) {
62                 sb.append("\n\t").append(iii.next());
63                 if(iii.hasNext()) sb.append(",");
64             }
65             sb.append("\n]");
66             String JavaDoc referencingPath = referencingPathToFailedList.getKey();
67             if(referencingPath.length()==0) continue; // skip if a top level class is not found
68
String JavaDoc ref = "referenced in the following call stack :\n";
69             String JavaDoc reference = "at";
70             if (smh != null) {
71                ref = smh.getLocalString(
72                         ArchiveClassesLoadableHelper.class.getName() + ".ref",
73                         ref);
74                 reference = smh.getLocalString(
75                         ArchiveClassesLoadableHelper.class.getName() + ".reference",
76                         reference);
77             }
78             StringTokenizer st = new StringTokenizer(referencingPath, File.separator);
79             Stack<String JavaDoc> referencingClassStack = new Stack<String JavaDoc>();
80             while(st.hasMoreTokens()) {
81                 referencingClassStack.push(st.nextToken());
82             }
83             if(!referencingClassStack.isEmpty())
84                  sb.append("\n\n"+ref);
85             while(!referencingClassStack.isEmpty()){
86                 sb.append("\n\t").append(reference).append(" ");
87                 sb.append(referencingClassStack.pop());
88             }
89             sb.append("\n\n");
90         }
91         return sb.toString();
92     }
93 }
94
95
Popular Tags