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  import java.io.StringWriter;
13  import java.util.ArrayList;
14  import java.util.List;
15  
16  
17  import org.objectweb.asm.ClassAdapter;
18  import org.objectweb.asm.ClassVisitor;
19  import org.objectweb.asm.MethodVisitor;
20  
21  /**
22   * This class is used to discover if the class visited is a corba stub with
23   * oneway operations.
24   */
25  public class CorbaOnewayAdapter extends ClassAdapter {
26  
27    /** Logger. */
28    private static final Logger LOG
29      = LoggerFactory.getLogger(CorbaOnewayAdapter.class);
30  
31    /** The internal class name of the class. */
32    private String internalClassName = null;
33  
34    /** The associated IDL interface. */
35    private String associatedInterface = null;
36  
37    /** The list of the 'oneway' operations. */
38    private List<String> onewayOperationList = new ArrayList<String>();
39  
40    /** The class writer that contains the bytecode. */
41    protected StringWriter stringWriter = null;
42  
43    /**
44     * The adapater used to manipulate the code.
45     *
46     * @param   cv    The ClassVisitor used in this object.
47     * @param   cw    The string writer.
48     *
49     */
50    public CorbaOnewayAdapter(ClassVisitor cv, StringWriter  cw) {
51      super(cv);
52      stringWriter = cw;
53    }
54    
55    /**
56     * Ovveride.
57     * @param version     The version
58     * @param access      The access
59     * @param name        The name
60     * @param signature   The signature
61     * @param superName   The superName
62     * @param interfaces  The interfaces
63     */
64    @Override
65    public void visit(int version,
66                      int access,
67                      String name,
68                      String signature,
69                      String superName,
70                      String [] interfaces) {
71      LOG.debug(">>>>> visit - begin");
72  
73      LOG.debug("VISIT"
74              + ".\n version="    + version
75              + ";\n access="     + access
76              + ";\n name="       + name
77              + ";\n signature="  + signature
78              + ";\n superName="  + superName
79              + ";\n interfaces=" + interfaces);
80  
81      setInternalClassName(name);
82  
83  
84      /* WARNING:
85       *
86       * The class inspected is a stub but the original class where the operation
87       * was defined is not the stub.
88       * There is a name convention between stub and original interface:
89       *
90       *          OrigInterface => _OrigInterfaceStub
91       *                        => OrigInterfaceOperations
92       */
93  
94      int underscoreIndex = name.lastIndexOf('/') + 1;
95  
96      // _InterfaceNameStub - underscore - Stub
97      String tempSimpleName
98        = name.substring(underscoreIndex + 1, name.length() - 4);
99      String tempPackage
100       = name.substring(0, underscoreIndex);
101     String temp = tempPackage.replace('/', '.') + tempSimpleName;
102 
103     setAssociatedInterface(temp + "Operations");
104     
105 
106     LOG.debug("<<<<< visit - end");
107     super.visit(version, access, name, signature, superName, interfaces);
108   }
109 
110   /**
111    * Override.
112    * @param access      The access
113    * @param name        The name
114    * @param desc        The desc
115    * @param signature   The signature
116    * @param exceptions  The exceptions
117    * @return            The return
118    */
119   @Override
120   public MethodVisitor visitMethod(int access,
121           String name,
122           String desc,
123           String signature,
124           String[] exceptions) {
125 
126     LOG.debug(">>>>> visitMethod - begin");
127 
128     LOG.debug("visitMethod. access="     + access
129                         + "; name="       + name
130                         + "; desc="       + desc
131                         + "; signature="  + signature
132                         + "; exceptions=" + exceptions);
133 
134     CorbaOnewayMethodVisitor corbaOnewayMethodVisitor
135       = new CorbaOnewayMethodVisitor(getInternalClassName(),
136                                      name,
137                                      getOnewayOperationList());
138 
139     MethodVisitor mv = corbaOnewayMethodVisitor.visitMethod(access,
140                                                             name,
141                                                             desc,
142                                                             signature,
143                                                             exceptions);
144 
145     LOG.debug("<<<<< visitMethod - end. "
146             + "methodName=" + name + "; methodDescription=" + desc);
147 
148     return mv;
149   }
150 
151 
152   // getter and setter
153 /**
154  * @return  the return
155  */
156   public String getInternalClassName() {
157     return internalClassName;
158   }
159 
160   /**
161    * @param internalClassName  The internal class name
162    */
163   public void setInternalClassName(String internalClassName) {
164     this.internalClassName = internalClassName;
165   }
166 
167   /**
168    * @return  The return
169    */
170   public List<String> getOnewayOperationList() {
171       return onewayOperationList;
172   }
173 
174   /**
175    * @param onewayOperationList  The oneway operation list
176    */
177   public void setOnewayOperationList(List<String> onewayOperationList) {
178       this.onewayOperationList = onewayOperationList;
179   }
180 
181   /**
182    * @return  The return
183    */
184   public String getAssociatedInterface() {
185       return associatedInterface;
186   }
187 
188   /**
189    * @param associatedInterface  The associated interface.
190    */
191   public void setAssociatedInterface(String associatedInterface) {
192       this.associatedInterface = associatedInterface;
193   }
194 
195 }