KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > gulden > util > javasource > ImportPackage


1 /*
2  * Project: BeautyJ - Customizable Java Source Code Transformer
3  * Class: de.gulden.util.javasource.ImportPackage
4  * Version: 1.0
5  *
6  * Date: 2002-10-27
7  *
8  * Note: Contains auto-generated Javadoc comments created by BeautyJ.
9  *
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 JavaDoc parent) {
40         super(parent);
41     }
42
43     /**
44      * Creates a new instance of ImportPackage.
45      */

46     ImportPackage(Package JavaDoc parent, String JavaDoc name) {
47         this(parent);
48         setName(name);
49     }
50
51
52     // ------------------------------------------------------------------------
53
// --- methods ---
54
// ------------------------------------------------------------------------
55
/**
56      * Fully qualifies a class identifier, if it matches the import statement.
57      *
58      * @return The qualified class identifier, or <code>null</code> if the identifer could not be qualified by this import.
59      */

60     public String JavaDoc qualify(String JavaDoc name) {
61         String JavaDoc testname=getName(); //+"."+name;
62
testname=testname.substring(0,testname.length()-1); // without '*'
63
testname=testname+name;
64         
65         // is imported package part of parsed sources?
66
Class JavaDoc c=getPackage().getBasePackage().findClass(testname);
67         if (c!=null) {
68             return testname;
69         }
70         
71         // can class be loaded from classpath?
72
try {
73             java.lang.Class.forName(testname);
74             return testname;
75         }
76         catch (ClassNotFoundException JavaDoc e) {
77             return null;
78         }
79     }
80
81     /**
82      * Output this object as XML.
83      *
84      * @return The XML tag.
85      * @see #initFromXML
86      */

87     public Element buildXML(Document d) {
88         Element e=super.buildXML(d);
89         e.setAttribute("kind","package");
90         return e;
91     }
92
93 } // end ImportPackage
94
Popular Tags