01: /*
02: * Project: BeautyJ - Customizable Java Source Code Transformer
03: * Class: de.gulden.util.javasource.ImportPackage
04: * Version: 1.0
05: *
06: * Date: 2002-10-27
07: *
08: * Note: Contains auto-generated Javadoc comments created by BeautyJ.
09: *
10: * This is licensed under the GNU General Public License (GPL)
11: * and comes with NO WARRANTY. See file license.txt for details.
12: *
13: * Author: Jens Gulden
14: * Email: beautyj@jensgulden.de
15: */
16:
17: package de.gulden.util.javasource;
18:
19: import de.gulden.util.xml.XMLToolbox;
20: import javax.xml.parsers.*;
21: import org.w3c.dom.*;
22: import java.io.*;
23: import java.util.*;
24:
25: /**
26: * Class ImportPackage.
27: *
28: * @author Jens Gulden
29: * @version 1.0
30: */
31: public class ImportPackage extends Import {
32:
33: // ------------------------------------------------------------------------
34: // --- constructors ---
35: // ------------------------------------------------------------------------
36: /**
37: * Creates a new instance of ImportPackage.
38: */
39: public ImportPackage(Package parent) {
40: super (parent);
41: }
42:
43: /**
44: * Creates a new instance of ImportPackage.
45: */
46: ImportPackage(Package parent, String name) {
47: this (parent);
48: setName(name);
49: }
50:
51: // ------------------------------------------------------------------------
52: // --- methods ---
53: // ------------------------------------------------------------------------
54: /**
55: * Fully qualifies a class identifier, if it matches the import statement.
56: *
57: * @return The qualified class identifier, or <code>null</code> if the identifer could not be qualified by this import.
58: */
59: public String qualify(String name) {
60: String testname = getName(); //+"."+name;
61: testname = testname.substring(0, testname.length() - 1); // without '*'
62: testname = testname + name;
63:
64: // is imported package part of parsed sources?
65: Class c = getPackage().getBasePackage().findClass(testname);
66: if (c != null) {
67: return testname;
68: }
69:
70: // can class be loaded from classpath?
71: try {
72: java.lang.Class.forName(testname);
73: return testname;
74: } catch (ClassNotFoundException e) {
75: return null;
76: }
77: }
78:
79: /**
80: * Output this object as XML.
81: *
82: * @return The XML tag.
83: * @see #initFromXML
84: */
85: public Element buildXML(Document d) {
86: Element e = super .buildXML(d);
87: e.setAttribute("kind", "package");
88: return e;
89: }
90:
91: } // end ImportPackage
|