KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > annotation > compiler > XmlAnnotationVisitor


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aop.annotation.compiler;
23
24 import org.jboss.aop.annotation.factory.duplicate.ast.ASTAnnotation;
25 import org.jboss.aop.annotation.factory.duplicate.ast.ASTChar;
26 import org.jboss.aop.annotation.factory.duplicate.ast.ASTIdentifier;
27 import org.jboss.aop.annotation.factory.duplicate.ast.ASTMemberValueArrayInitializer;
28 import org.jboss.aop.annotation.factory.duplicate.ast.ASTMemberValuePair;
29 import org.jboss.aop.annotation.factory.duplicate.ast.ASTMemberValuePairs;
30 import org.jboss.aop.annotation.factory.duplicate.ast.ASTSingleMemberValue;
31 import org.jboss.aop.annotation.factory.duplicate.ast.ASTStart;
32 import org.jboss.aop.annotation.factory.duplicate.ast.ASTString;
33 import org.jboss.aop.annotation.factory.duplicate.ast.AnnotationParserVisitor;
34 import org.jboss.aop.annotation.factory.duplicate.ast.SimpleNode;
35
36 import java.io.PrintWriter JavaDoc;
37
38 /**
39  * Comment
40  *
41  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
42  * @version $Revision: 57019 $
43  *
44  **/

45 public class XmlAnnotationVisitor implements AnnotationParserVisitor
46 {
47    private int indent;
48    PrintWriter JavaDoc pw;
49
50    public XmlAnnotationVisitor(int indent, PrintWriter JavaDoc pw)
51    {
52       this.indent = indent;
53       this.pw = pw;
54    }
55
56    public Object JavaDoc visit(ASTMemberValuePairs node, Object JavaDoc data)
57    {
58       node.childrenAccept(this, data);
59       return null;
60    }
61
62
63    public Object JavaDoc visit(ASTMemberValuePair node, Object JavaDoc data)
64    {
65       XmlAnnotationCompiler.indenter(pw, indent);
66       pw.print("<" + node.getIdentifier().getValue() + ">");
67       node.getValue().jjtAccept(this, null);
68       pw.println("</" + node.getIdentifier().getValue() + ">");
69       return null;
70    }
71
72    public Object JavaDoc visit(ASTSingleMemberValue node, Object JavaDoc data)
73    {
74       XmlAnnotationCompiler.indenter(pw, indent);
75       pw.print("<value>");
76       node.getValue().jjtAccept(this, null);
77       pw.println("</value>");
78       return null;
79    }
80
81    public Object JavaDoc visit(ASTAnnotation node, Object JavaDoc data)
82    {
83       pw.println("");
84       indent++;
85       XmlAnnotationCompiler.indenter(pw, indent);
86       pw.println("<annotation tag=\"" + node.getIdentifier() + "\">");
87       indent++;
88       node.childrenAccept(this, data);
89       indent--;
90       XmlAnnotationCompiler.indenter(pw, indent);
91       pw.println("</annotation>");
92       indent--;
93       XmlAnnotationCompiler.indenter(pw, indent);
94       return null;
95    }
96
97    public Object JavaDoc visit(ASTMemberValueArrayInitializer node, Object JavaDoc data)
98    {
99       pw.println("");
100       indent++;
101       XmlAnnotationCompiler.indenter(pw, indent);
102       pw.println("<array>");
103       indent++;
104       int size = node.jjtGetNumChildren();
105       for (int i = 0; i < size; i++)
106       {
107          XmlAnnotationCompiler.indenter(pw, indent);
108          pw.print("<value>");
109          node.jjtGetChild(i).jjtAccept(this, null);
110          pw.println("</value>");
111       }
112       indent--;
113       XmlAnnotationCompiler.indenter(pw, indent);
114       pw.println("</array>");
115       indent--;
116       XmlAnnotationCompiler.indenter(pw, indent);
117       return null;
118    }
119
120    public Object JavaDoc visit(ASTIdentifier node, Object JavaDoc data)
121    {
122       pw.print(node.getValue());
123       return null;
124    }
125
126    public Object JavaDoc visit(ASTString node, Object JavaDoc data)
127    {
128       pw.print(node.getValue());
129       return null;
130    }
131
132    public Object JavaDoc visit(ASTChar node, Object JavaDoc data)
133    {
134       pw.print(node.getValue());
135       return null;
136    }
137    public Object JavaDoc visit(SimpleNode node, Object JavaDoc data)
138    {
139       return null;
140    }
141
142    public Object JavaDoc visit(ASTStart node, Object JavaDoc data)
143    {
144       return null;
145    }
146
147 }
148
Popular Tags