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.ClassAdapter;
14  import org.objectweb.asm.ClassVisitor;
15  import org.objectweb.asm.MethodVisitor;
16  
17  /**
18   * Adds the Exception superclass and removes the default constructor.
19   * Taken from the Jbi4Ejb project
20   */
21  public class AddExceptionSuperclass extends ClassAdapter {
22  
23  
24      /** Logger. */
25      private static final Logger LOG
26      = LoggerFactory.getLogger(AddExceptionSuperclass.class);   
27  
28  
29      /**
30       * The adapter used to manipulate the code.
31       * 
32       * @param cv
33       *            The <code>ClassVisitor</code>
34       */
35      public AddExceptionSuperclass(ClassVisitor cv) {
36          super(cv);
37      }
38  
39  
40      /**
41       * Adds the java.lang.Exception superclass.
42       * 
43       * @param version the version
44       * @param access the class access modifier
45       * @param name the class name
46       * @param signature the class signature
47       * @param superName the superclass name
48       * @param interfaces the interfaces impelemented
49       */
50      public void visit(int version,
51              int access,
52              String name,
53              String signature,
54              String superName,
55              String [] interfaces) {
56  
57          LOG.debug("Adding the java.lang.Exception superclass to class: " + name);                
58  
59          // Adding the java.lan.Excpetion superclass
60          String javaLangExceptionClassName = "java/lang/Exception"; 
61  
62          super.visit(version, access, name, signature, javaLangExceptionClassName, interfaces);
63      }
64  
65      /**
66       * Removes the default constructor (at bytecode level call the Object
67       * constructor.
68       * 
69       * @param access
70       *          The access modifier
71       * @param name
72       *          The method name
73       * @param desc
74       *          The description
75       * @param signature
76       *          The method signature
77       * @param exceptions
78       *          The throwed exceptions
79       * 
80       * @return 
81       *          The return
82       */
83      public MethodVisitor visitMethod(int access,
84              String name,
85              String desc,
86              String signature,
87              String[] exceptions) {
88  
89          LOG.debug(">>>>> visitMethod - begin");
90  
91          LOG.debug("visitMethod. access="     + access
92                  + "; name="       + name
93                  + "; desc="       + desc
94                  + "; signature="  + signature
95                  + "; exceptions=" + exceptions);
96  
97          // if we found the default constructor then ...
98          if ("<init>".equals(name)) {
99  
100             LOG.debug("Default constructor modifications of the class:" + name);
101             // removes the default constructor
102             return null;        
103 
104         }
105         return super.visitMethod(access, name, desc, signature, exceptions);
106     }
107 
108 
109 }