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 org.objectweb.asm.ClassAdapter;
11  import org.objectweb.asm.ClassVisitor;
12  import org.objectweb.asm.MethodVisitor;
13  
14  
15  /**
16   * "Remotizes" the interface. A copy from the jbi4corba project, but no "CorbaInterface" is added.
17   * 
18   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
19   */
20  public class RemoteEnancherAdapter extends ClassAdapter {
21  
22  
23    /** The name of the class manipulated. */
24    private String completeName;
25  
26    /** The name of the class that represents the PortType. */
27    private String portTypeClassName;
28  
29    /**
30       * Constructor.
31       * 
32       * @param cv
33       *          The <code>ClassVisitor</code>
34       * @param portTypeClassName
35       *          The port type class name
36       */
37    public RemoteEnancherAdapter(ClassVisitor cv, String portTypeClassName) {
38      super(cv);
39      this.portTypeClassName = portTypeClassName;
40    }
41  
42    
43    /**
44     * Adds the <code>java.rmi.Remote</code>.
45     * 
46     * @param version 
47     *            The version
48     * @param access 
49     *            The access modifier
50     * @param name 
51     *            The method name
52     * @param signature 
53     *            The signature
54     * @param superName 
55     *            The superclass name
56     * @param interfaces
57     *            The interfaces implemented
58     */
59    public void visit(int version,
60                      int access,
61                      String name,
62                      String signature,
63                      String superName,
64                      String [] interfaces) {
65      
66  
67      // MARCO: Modified from jbi4corba
68      String newName = portTypeClassName;
69  
70      String [] newInterfaces;
71  
72      if (interfaces == null){
73  
74        newInterfaces = new String [] {"java/rmi/Remote"};
75  
76      } else {
77  
78        newInterfaces = new String[interfaces.length + 1];
79  
80        for (int i = 0; i < interfaces.length; i++) {
81          newInterfaces[i] = interfaces[i];
82        }
83  
84        newInterfaces[newInterfaces.length - 1] = "java/rmi/Remote";
85      }
86  
87      super.visit(version, access, newName, signature, superName, newInterfaces);
88  
89      completeName = newName;
90      
91    }
92  
93   
94    /**
95       * Adds the <code>java.rmi.Exception</code> to the exceptions throws.
96       * 
97       * @param access
98       *          The access modifier
99       * @param name
100      *          The method name
101      * @param desc
102      *          The method desc
103      * @param signature
104      *          The signature
105      * @param exceptions
106      *          The exception raised
107      * 
108      * @return
109      *          The method visitor
110      * 
111      * @see org.objectweb.asm.ClassAdapter#visitMethod(int, java.lang.String,
112      *      java.lang.String, java.lang.String, java.lang.String[])
113      */
114   public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
115     String[] newExceptions;
116     if (exceptions==null) {
117       newExceptions=new String[]{"java/rmi/RemoteException"};
118     }
119     else {
120         newExceptions = new String[exceptions.length + 1];
121         if (exceptions!=null) {
122             for (int i = 0; i < exceptions.length; i++) {
123                 newExceptions[i] = exceptions[i];
124             }
125         }
126       newExceptions[newExceptions.length - 1] = "java/rmi/RemoteException";
127     }
128     return super.visitMethod(access, name, desc, signature, newExceptions);
129   }
130 
131   /**
132      * Gets the complete name.
133      * 
134      * @return the complete name
135      */
136   public String getCompleteName() {
137     return completeName;
138   }
139 
140 }
141     
142