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.util.ArrayList;
13  import java.util.List;
14  import org.objectweb.asm.Opcodes;
15  
16  import org.objectweb.asm.commons.EmptyVisitor;
17  
18  /**
19   * This class is used to discover if a method is a oneway corba request.
20   */
21  public class CorbaOnewayMethodVisitor extends EmptyVisitor {
22  
23    /**
24     * Logger.
25     */
26    private static final Logger LOG
27      = LoggerFactory.getLogger(CorbaOnewayMethodVisitor.class);
28  
29    /** The internal name of the stub. */
30    protected String internalStubName = null;
31  
32    /** The method name. */
33    protected String methodName = null;
34  
35    /** The list of the 'oneway' operations. */
36    protected List<String> onewayOperationList = new ArrayList<String>();
37  
38    /** The boolean information to create the oneway corba request. */
39    protected boolean zero = false;
40  
41    /**
42     * Constructor.
43     *
44     * @param   stub                  The internal class name of the stub.
45     * @param   aMethodName           The name of the method visited.
46     * @param   aOnewayOperationList  The oneway request collected.
47     */
48    public CorbaOnewayMethodVisitor(String stub, String aMethodName,
49      List<String> aOnewayOperationList) {
50      super();
51      internalStubName = stub;
52      methodName = aMethodName;
53      onewayOperationList = aOnewayOperationList;
54    }
55  
56    /**
57     * Override.
58     * @param opcode  The op code
59     */
60    @Override
61    public void visitInsn(int opcode) {
62      super.visitInsn(opcode);
63  
64      if (Opcodes.ICONST_0 == opcode) {
65        zero = true;
66      } else {
67        zero = false;
68      }
69      //LOG.debug("___ ZERO=" + zero);
70    }
71  
72    /**
73     * Override.
74     * @param opcode  The op code
75     * @param owner   The owner
76     * @param name    The name
77     * @param desc    The desc
78     */
79    @Override
80    public void visitMethodInsn(int opcode,String owner,String name,String desc) {
81  
82      LOG.debug("CorbaOnewayMethodVisitor.visitMethodInsn. opcode=" + opcode
83        + "; owner=" + owner + "; name=" + name + "; desc=" + desc);
84  
85      final String corbaOutputStream = "(Ljava/lang/String;Z)"
86                                     + "Lorg/omg/CORBA/portable/OutputStream;";
87      /*
88      mv.visitMethodInsn(
89          INVOKEVIRTUAL,
90          "it/imolinfo/jbi4corba/test/async/_EchoAsyncStub",
91          "_request",
92          "(Ljava/lang/String;Z)Lorg/omg/CORBA/portable/OutputStream;"
93       );
94       */
95      if (Opcodes.INVOKEVIRTUAL == opcode
96        && owner.equals(internalStubName)
97        && "_request".equals(name)
98        && corbaOutputStream.equals(desc)
99        && zero) {
100 
101       LOG.debug("The method " + methodName + " is a oneway corba request.");
102       onewayOperationList.add(methodName);
103     } else {
104       LOG.debug("The method " + methodName + " is NOT a oneway corba request.");
105     }
106 
107     super.visitMethodInsn(opcode, owner, name, desc);
108   }
109 
110 }