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   
9   package it.imolinfo.jbi4corba.webservice.generator.bcm;
10  
11  import it.imolinfo.jbi4corba.Logger;
12  import it.imolinfo.jbi4corba.LoggerFactory;
13  
14  import org.objectweb.asm.ClassAdapter;
15  import org.objectweb.asm.ClassVisitor;
16  import org.objectweb.asm.MethodVisitor;
17  
18  /**
19   * Bytecode manipulation.
20   *
21   * 1) add the java.rmi.Remote interface to the class
22   * 2) add the java.rmi.RemoteException to the 'throws' clause of each method.
23   */
24  public class RemoteEnhancerAdapter extends ClassAdapter {
25  
26      /**
27       * Logger.
28       */
29      private static final Logger LOG
30              = LoggerFactory.getLogger(RemoteEnhancerAdapter.class);
31      
32      /**
33       * The name of the class that represents the PortType.
34       */
35      protected String portTypeClassName;
36  
37    /**
38     * The name of the class manipulated.
39     */
40    String completeName;
41  
42  
43    /**
44     * Constructor.
45     *
46     * @param    arg0    The ClassVisitor
47     * @param    portTypeClassName    The port type class name
48     */
49    public RemoteEnhancerAdapter(ClassVisitor arg0, String portTypeClassName) {
50      super(arg0);
51      this.portTypeClassName = portTypeClassName;
52    }
53  
54    /**
55     * Override.
56     * @param version     The version
57     * @param access      The access
58     * @param name        The name
59     * @param signature   The signature
60     * @param superName   The super name
61     * @param interfaces  The interfaces
62     */
63    @Override
64    public void visit(int version,
65                      int access,
66                      String name,
67                      String signature,
68                      String superName,
69                      String [] interfaces) {
70  
71      LOG.debug(">>>>> visit - begin");
72  
73      String newName = portTypeClassName + "CorbaInterface";
74  
75      String [] newInterfaces;
76  
77      if (interfaces == null){
78  
79        newInterfaces = new String [] {"java/rmi/Remote"};
80  
81      } else {
82  
83        newInterfaces = new String[interfaces.length + 1];
84  
85        for (int i = 0; i < interfaces.length; i++) {
86          newInterfaces[i] = interfaces[i];
87        }
88  
89        newInterfaces[newInterfaces.length - 1] = "java/rmi/Remote";
90      }
91  
92      super.visit(version, access, newName, signature, superName, newInterfaces);
93  
94      completeName = newName;
95  
96      LOG.debug("<<<<< visit - end");
97    }
98  
99    /**
100    * Override.
101    * @param access      The access
102    * @param name        The name
103    * @param desc        The description
104    * @param signature   The signature
105    * @param exceptions  The exceptions
106    * @return            The return
107    */
108   @Override
109   public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
110     String[] newExceptions;
111     if (exceptions==null){
112       newExceptions=new String[]{"java/rmi/RemoteException"};
113     } else {
114       newExceptions = new String[exceptions.length + 1];
115       if (exceptions!=null){
116       for (int i = 0; i < exceptions.length; i++) {
117         newExceptions[i] = exceptions[i];
118       }
119       }
120       newExceptions[newExceptions.length - 1] = "java/rmi/RemoteException";
121     }
122     return super.visitMethod(access, name, desc, signature, newExceptions);
123   }
124 
125   /**
126    * @return  the complete name
127    */
128   public String getCompleteName() {
129     return completeName;
130   }
131 
132 }