1 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 ; 37 38 45 public class XmlAnnotationVisitor implements AnnotationParserVisitor 46 { 47 private int indent; 48 PrintWriter pw; 49 50 public XmlAnnotationVisitor(int indent, PrintWriter pw) 51 { 52 this.indent = indent; 53 this.pw = pw; 54 } 55 56 public Object visit(ASTMemberValuePairs node, Object data) 57 { 58 node.childrenAccept(this, data); 59 return null; 60 } 61 62 63 public Object visit(ASTMemberValuePair node, Object 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 visit(ASTSingleMemberValue node, Object 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 visit(ASTAnnotation node, Object 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 visit(ASTMemberValueArrayInitializer node, Object 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 visit(ASTIdentifier node, Object data) 121 { 122 pw.print(node.getValue()); 123 return null; 124 } 125 126 public Object visit(ASTString node, Object data) 127 { 128 pw.print(node.getValue()); 129 return null; 130 } 131 132 public Object visit(ASTChar node, Object data) 133 { 134 pw.print(node.getValue()); 135 return null; 136 } 137 public Object visit(SimpleNode node, Object data) 138 { 139 return null; 140 } 141 142 public Object visit(ASTStart node, Object data) 143 { 144 return null; 145 } 146 147 } 148 | Popular Tags |