001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.kernel;
032:
033: import java.io.*;
034: import java.util.*;
035: import java.util.jar.*;
036:
037: public final class KeClassBrowser {
038: public ArrayList pcmf_getClasses(String xAddCp, Class xIClass)
039: throws Exception {
040: ArrayList l_res = new ArrayList();
041: String l_cp = System.getProperty("java.class.path", ".");
042:
043: // Workaround für ServletContainer mit wegen ClassLoader
044: if (xAddCp != null)
045: l_cp = xAddCp;
046:
047: ArrayList l_rootPaths = new ArrayList();
048: StringTokenizer l_tok = new StringTokenizer(l_cp, ";:");
049: while (l_tok.hasMoreTokens())
050: l_rootPaths.add(new File(l_tok.nextToken()));
051:
052: Iterator l_it = l_rootPaths.iterator();
053: ArrayList l_allClasses = new ArrayList();
054: File l_file = null;
055: while (l_it.hasNext()) {
056: l_file = (File) l_it.next();
057: this .pcmf_addClasses(l_file, l_allClasses, "", true);
058: }
059:
060: Class l_cl2 = null;
061: l_it = l_allClasses.iterator();
062: Class l_ifs[] = null;
063: String l_class = null;
064: while (l_it.hasNext()) {
065: try {
066: l_class = l_it.next().toString();
067: l_cl2 = Class.forName(l_class);
068: } catch (Throwable e) {
069: KeLog.pcmf_log("ug2t",
070: "classbrowser cannot load class: " + l_class,
071: this , KeLog.MESSAGE);
072: continue;
073: }
074:
075: l_ifs = l_cl2.getInterfaces();
076: for (int i = 0; i < l_ifs.length; i++)
077: // if (l_ifs[i].equals(xIClass))
078: if (xIClass.isAssignableFrom(l_ifs[i])) {
079: if (l_cl2.isInterface() == false) {
080: l_res.add(l_cl2);
081: }
082: }
083: }
084: return (l_res);
085: }
086:
087: public void pcmf_addClasses(File xPath, ArrayList xAll,
088: String xName, boolean xLoadJar) {
089: File l_all[] = xPath.listFiles();
090:
091: if (l_all == null) {
092: l_all = new File[1];
093: l_all[0] = xPath;
094: }
095: ;
096:
097: for (int i = 0; i < l_all.length; i++) {
098: if (l_all[i].getName().indexOf(".class") != -1)
099: xAll.add(xName
100: + l_all[i].getName().substring(0,
101: l_all[i].getName().indexOf(".class")));
102:
103: if (l_all[i].getName().indexOf(".jar") != -1 && xLoadJar) {
104: try {
105: JarFile l_jFile = new JarFile(l_all[i]);
106: Enumeration l_enu = l_jFile.entries();
107: JarEntry l_jEntry = null;
108: while (l_enu.hasMoreElements()) {
109: l_jEntry = (JarEntry) l_enu.nextElement();
110: if (l_jEntry.isDirectory())
111: continue;
112: if (l_jEntry.getName().indexOf(".class") != -1) {
113: String l_cName = l_jEntry.getName()
114: .substring(
115: 0,
116: l_jEntry.getName().indexOf(
117: ".class"));
118: l_cName = l_cName.replace('/', '.');
119: l_cName = l_cName.replace('\\', '.');
120: xAll.add(l_cName);
121: }
122: }
123: } catch (Exception e) {
124: }
125: }
126:
127: if (l_all[i].isDirectory())
128: this .pcmf_addClasses(l_all[i], xAll, xName
129: + l_all[i].getName() + ".", false);
130: }
131: }
132: }
|