View Javadoc

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