001: /*
002: * Project: BeautyJ - Customizable Java Source Code Transformer
003: * Class: de.gulden.util.javasource.SourceObjectDeclaredVisible
004: * Version: 1.0
005: *
006: * Date: 2002-10-27
007: *
008: * Note: Contains auto-generated Javadoc comments created by BeautyJ.
009: *
010: * This is licensed under the GNU General Public License (GPL)
011: * and comes with NO WARRANTY. See file license.txt for details.
012: *
013: * Author: Jens Gulden
014: * Email: beautyj@jensgulden.de
015: */
016:
017: package de.gulden.util.javasource;
018:
019: import de.gulden.util.javasource.jjt.Node;
020: import de.gulden.util.javasource.jjt.*;
021: import de.gulden.util.xml.XMLToolbox;
022: import javax.xml.parsers.*;
023: import org.w3c.dom.*;
024: import java.io.*;
025: import java.util.*;
026:
027: /**
028: * Class SourceObjectDeclaredVisible.
029: *
030: * @author Jens Gulden
031: * @version 1.0
032: */
033: public abstract class SourceObjectDeclaredVisible extends
034: SourceObjectDeclared {
035:
036: // ------------------------------------------------------------------------
037: // --- methods ---
038: // ------------------------------------------------------------------------
039: /**
040: * Output this object as XML.
041: *
042: * @return The XML tag.
043: * @see #initFromXML
044: */
045: public Element buildXML(Document d) {
046: Element e = super .buildXML(d);
047:
048: e.setAttribute("unqualifiedName", getUnqualifiedName());
049:
050: if (java.lang.reflect.Modifier.isStatic(modifier)) {
051: e.setAttribute("static", "yes");
052: }
053: if (java.lang.reflect.Modifier.isAbstract(modifier)) {
054: e.setAttribute("abstract", "yes");
055: }
056: if (java.lang.reflect.Modifier.isSynchronized(modifier)) {
057: e.setAttribute("synchronized", "yes");
058: }
059: if (java.lang.reflect.Modifier.isTransient(modifier)) {
060: e.setAttribute("transient", "yes");
061: }
062: if (java.lang.reflect.Modifier.isVolatile(modifier)) {
063: e.setAttribute("volatile", "yes");
064: }
065: if (java.lang.reflect.Modifier.isNative(modifier)) {
066: e.setAttribute("native", "yes");
067: }
068:
069: if (java.lang.reflect.Modifier.isPublic(modifier)) {
070: e.setAttribute("public", "yes");
071: } else if (java.lang.reflect.Modifier.isProtected(modifier)) {
072: e.setAttribute("protected", "yes");
073: } else if (java.lang.reflect.Modifier.isPrivate(modifier)) {
074: e.setAttribute("private", "yes");
075: } else {
076: e.setAttribute("packageprivate", "yes"); // !(public|protected|private)
077: }
078:
079: return e;
080: }
081:
082: /**
083: * Initialize this object from XML.
084: *
085: * @param element The XML tag.
086: * @throws IOException if an i/o error occurs
087: */
088: public void initFromXML(Element element) throws IOException {
089: // to be extended (not overwritten) by subclasses
090: super .initFromXML(element);
091:
092: if (XMLToolbox.isYesAttribute(element, "static")) {
093: this .modifier |= java.lang.reflect.Modifier.STATIC;
094: }
095: if (XMLToolbox.isYesAttribute(element, "abstract")) {
096: this .modifier |= java.lang.reflect.Modifier.ABSTRACT;
097: }
098: if (XMLToolbox.isYesAttribute(element, "synchronized")) {
099: this .modifier |= java.lang.reflect.Modifier.SYNCHRONIZED;
100: }
101: if (XMLToolbox.isYesAttribute(element, "transient")) {
102: this .modifier |= java.lang.reflect.Modifier.TRANSIENT;
103: }
104: if (XMLToolbox.isYesAttribute(element, "volatile")) {
105: this .modifier |= java.lang.reflect.Modifier.VOLATILE;
106: }
107: if (XMLToolbox.isYesAttribute(element, "native")) {
108: this .modifier |= java.lang.reflect.Modifier.NATIVE;
109: }
110:
111: if (XMLToolbox.isYesAttribute(element, "public")) {
112: this .modifier |= java.lang.reflect.Modifier.PUBLIC;
113: }
114: if (XMLToolbox.isYesAttribute(element, "protected")) {
115: this .modifier |= java.lang.reflect.Modifier.PROTECTED;
116: }
117: if (XMLToolbox.isYesAttribute(element, "private")) {
118: this .modifier |= java.lang.reflect.Modifier.PRIVATE;
119: }
120: }
121:
122: /**
123: * Initialize this object with values from parsed Java code.
124: *
125: * @param rootnode The corresponding node in the abstract syntax tree (AST).
126: */
127: void initFromAST(Node rootnode) {
128: super .initFromAST(rootnode);
129:
130: // modifier
131: Node mod = rootnode.getChild(JJT_MODIFIER);
132: if (mod != null) {
133: if (mod.hasChild(JJT_STATIC)) {
134: this .modifier |= java.lang.reflect.Modifier.STATIC;
135: }
136: if (mod.hasChild(JJT_ABSTRACT)) {
137: this .modifier |= java.lang.reflect.Modifier.ABSTRACT;
138: }
139: if (mod.hasChild(JJT_TRANSIENT)) {
140: this .modifier |= java.lang.reflect.Modifier.TRANSIENT;
141: }
142: if (mod.hasChild(JJT_VOLATILE)) {
143: this .modifier |= java.lang.reflect.Modifier.VOLATILE;
144: }
145: if (mod.hasChild(JJT_NATIVE)) {
146: this .modifier |= java.lang.reflect.Modifier.NATIVE;
147: }
148: if (mod.hasChild(JJT_SYNCHRONIZED)) {
149: this .modifier |= java.lang.reflect.Modifier.SYNCHRONIZED;
150: }
151:
152: if (mod.hasChild(JJT_PUBLIC)) {
153: this .modifier |= java.lang.reflect.Modifier.PUBLIC;
154: } else if (mod.hasChild(JJT_PROTECTED)) {
155: this .modifier |= java.lang.reflect.Modifier.PROTECTED;
156: } else if (mod.hasChild(JJT_PRIVATE)) {
157: this .modifier |= java.lang.reflect.Modifier.PRIVATE;
158: }
159: }
160: }
161:
162: } // end SourceObjectDeclaredVisible
|