KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Project: BeautyJ - Customizable Java Source Code Transformer
3  * Class: de.gulden.util.javasource.Import
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.javasource.jjt.Node;
20 import de.gulden.util.javasource.jjt.*;
21 import de.gulden.util.xml.XMLToolbox;
22 import javax.xml.parsers.*;
23 import org.w3c.dom.*;
24 import java.io.*;
25 import java.util.*;
26
27 /**
28  * Represent an import statement.
29  *
30  * @author Jens Gulden
31  * @version 1.0
32  */

33 public abstract class Import extends SourceObject implements ParserTreeConstants {
34
35     // ------------------------------------------------------------------------
36
// --- constructor ---
37
// ------------------------------------------------------------------------
38
/**
39      * Creates a new instance of Import.
40      */

41     public Import(Package JavaDoc p) {
42         myPackage=p;
43     }
44
45
46     // ------------------------------------------------------------------------
47
// --- methods ---
48
// ------------------------------------------------------------------------
49
/**
50      * Fully qualifies a class identifier, if it matches the import statement.
51      *
52      * @return The qualified class identifier, or <code>null</code> if the identifer could not be qualified by this import.
53      */

54     public abstract String JavaDoc qualify(String JavaDoc name);
55
56     /**
57      * Output this object as XML.
58      *
59      * @return The XML tag.
60      * @see #initFromXML
61      */

62     public Element buildXML(Document d) {
63         // overwrites SourceObject.buildXML
64
// will be overloaded by subclasses
65
String JavaDoc tagName=getXMLName();
66         Element e=d.createElement(tagName);
67         e.appendChild(d.createTextNode(getName()));
68         return e;
69     }
70
71     /**
72      * Returns the name of the XML tag representing this SourceObject.
73      */

74     protected String JavaDoc getXMLName() {
75         return "import";
76     }
77
78
79     // ------------------------------------------------------------------------
80
// --- static methods ---
81
// ------------------------------------------------------------------------
82
/**
83      * Create a new Import-object, specified by the XML element.
84      * The created object will either be of type ImportPackage or ImportClass.
85      *
86      * @throws IOException if an i/o error occurs
87      */

88     public static Import createFromXML(Package JavaDoc parent, Element element) throws IOException {
89         String JavaDoc name=XMLToolbox.getText(element);//element.getAttribute("name");
90
String JavaDoc kind=element.getAttribute("kind");
91         boolean isClass=kind.equals("class");
92         if (!isClass) {
93             return new ImportPackage(parent,name);
94         }
95         else {
96             return new ImportClass(parent,name);
97         }
98     }
99
100     /**
101      * Create a new Import-object.
102      * The created object will either be of type ImportPackage or ImportClass.
103      */

104     static Import createFromAST(Package JavaDoc p, Node node) {
105         Import im;
106         if (node.getChild(JJT_PACKAGEIMPORT)!=null) // sub-node 'ImportPackage' exists
107
{
108             im=new ImportPackage(p);
109             im.setName(node.getName()+".*");
110         }
111         else {
112             im=new ImportClass(p);
113             im.setName(node.getName());
114         }
115         return im;
116     }
117
118 } // end Import
119
Popular Tags