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 java.util.HashMap;
14  import java.util.Map;
15  
16  import org.objectweb.asm.AnnotationVisitor;
17  import org.objectweb.asm.commons.EmptyVisitor;
18  
19  /**
20   * This class is used to collect the annotations on a field.
21   */
22  public class AnnotationCollectorFieldVisitor extends EmptyVisitor {
23  
24    /**
25     * Logger.
26     */
27    private static final Logger LOG
28      = LoggerFactory.getLogger(AnnotationCollectorFieldVisitor.class);
29  
30    /** The field name. */
31    protected String fieldName = null;
32  
33    /** Where the annotations are stored. */
34    protected AnnotationsMaps tracer;
35  
36      /**
37       * Constructor.
38       *
39       * @param tracer  The annotations maps
40       * @param fieldName  The field name
41       */
42      public AnnotationCollectorFieldVisitor(AnnotationsMaps tracer,
43        String fieldName) {
44  
45        super();
46  
47        this.fieldName = fieldName;
48        this.tracer = (tracer == null) ? new AnnotationsMaps() : tracer;
49      }
50  
51      /**
52       * @param desc    The description
53       * @param visible The visibol
54       * @return        The return
55       */
56    @Override
57    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
58  	LOG.info("CRB000602_ANNOTATION", new Object[]{desc, visible});
59  
60      AnnotationCollectorVisitor visitor
61          = new AnnotationCollectorVisitor();
62  
63      AnnotationCollectorVisitor av = (AnnotationCollectorVisitor)
64          visitor.visitAnnotation(desc, visible);
65  
66      AnnotationVisibleAndValue avv
67          = new AnnotationVisibleAndValue(visible, av.list);
68  
69      if (tracer.annotationOnField.get(fieldName) == null) {
70          Map<String, AnnotationVisibleAndValue> annotations
71          = new HashMap<String, AnnotationVisibleAndValue>();
72  
73          tracer.annotationOnField.put(fieldName, annotations);
74      }
75      tracer.annotationOnField.get(fieldName).put(desc, avv);
76  
77      return av;
78    }
79  
80  }