View Javadoc

1    /****************************************************************************
2    * Copyright (c) 2005, 2006, 2007, 2008, 2009 Imola Informatica.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the LGPL License v2.1
5    * which accompanies this distribution, and is available at
6    * http://www.gnu.org/licenses/lgpl.html
7    ****************************************************************************/
8   package it.imolinfo.jbi4corba.webservice.generator.bcm;
9   
10  import it.imolinfo.jbi4corba.Logger;
11  import it.imolinfo.jbi4corba.LoggerFactory;
12  
13  import org.objectweb.asm.AnnotationVisitor;
14  import org.objectweb.asm.ClassAdapter;
15  import org.objectweb.asm.ClassVisitor;
16  import org.objectweb.asm.ClassWriter;
17  import org.objectweb.asm.FieldVisitor;
18  import org.objectweb.asm.MethodVisitor;
19  
20  /**
21   * XXX javadoc.
22   */
23  public class AnnotationCollectorAdapter extends ClassAdapter {
24  
25    /**
26     * Logger.
27     */
28    private static final Logger LOG = LoggerFactory.getLogger(
29      AnnotationCollectorAdapter.class);
30  
31    /**
32     * The Class Writer.
33     */
34    protected ClassWriter classWriter = null;
35  
36    /**
37     * The class name.
38     */
39    protected String className = null;
40  
41    /**
42     * The java class name.
43     */
44    protected String javaClassName = null;
45  
46    protected AnnotationsMaps tracer = null;
47  
48  
49    /**
50     * Constructor.
51     *
52     * @param    cv        The class visitor
53     * @param    cw        The class writer
54     * @param    cn        The class name
55     * @param    tracer    The annotations map
56     * @param    javaClassName  The java class name
57     */
58    public AnnotationCollectorAdapter(ClassVisitor cv, ClassWriter cw, String cn,
59      AnnotationsMaps tracer, String javaClassName) {
60  
61      super(cv);
62      classWriter = cw;
63      className = cn;
64  
65      this.javaClassName = javaClassName;
66  
67      this.tracer = (tracer == null) ? new AnnotationsMaps() : tracer;
68    }
69  
70    /**
71     * Override.
72     * @param desc     The description
73     * @param visible  The visible
74     * @return         The return
75     */
76    @Override
77    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
78  	  LOG.info("CRB000602_ANNOTATION", new Object[]{desc, visible});
79  
80      AnnotationCollectorVisitor visitor
81        = new AnnotationCollectorVisitor();
82  
83      //return super.visitAnnotation(desc, visible);
84      //return visitor.visitAnnotation(desc, visible);
85  
86      AnnotationCollectorVisitor av = (AnnotationCollectorVisitor)
87        visitor.visitAnnotation(desc, visible);
88  
89      AnnotationVisibleAndValue avv
90        = new AnnotationVisibleAndValue(visible, av.list);
91  
92      tracer.annotationOnClass.put(desc, avv);
93  
94      return av;
95    }
96  
97    /**
98     * Override.
99     * @param access      The access
100    * @param name        The name
101    * @param desc        The description
102    * @param signature   The signature
103    * @param exceptions  The exceptions
104    * @return            The return
105    */
106   @Override
107   public MethodVisitor visitMethod(int access,
108           String name,
109           String desc,
110           String signature,
111           String[] exceptions) {
112 
113     AnnotationCollectorMethodVisitor mv
114       = new AnnotationCollectorMethodVisitor(tracer, name);
115 
116     return mv.visitMethod(access, name, desc, signature, exceptions);
117   }
118 
119   /**
120    * Override.
121    * @param access      The access
122    * @param name        The name
123    * @param desc        The description
124    * @param signature   The signature
125    * @param value       The value
126    * @return            The return
127    */
128   @Override
129   public FieldVisitor visitField(int access,
130                                  String name,
131                                  String desc,
132                                  String signature,
133                                  Object value) {
134       LOG.debug(">>>>> visitField - begin");
135 
136       AnnotationCollectorFieldVisitor fv
137         = new AnnotationCollectorFieldVisitor(tracer, name);
138 
139       LOG.debug(">>>>> visitField - end");
140       return fv.visitField(access, name, desc, signature, value);
141   }
142 
143 }