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  import it.imolinfo.jbi4corba.webservice.generator.InterfaceType;
14  import it.imolinfo.jbi4corba.webservice.generator.TypeUtils;
15  
16  import java.util.Map;
17  
18  import org.objectweb.asm.MethodVisitor;
19  import org.objectweb.asm.Opcodes;
20  import org.objectweb.asm.Type;
21  import org.objectweb.asm.util.TraceMethodVisitor;
22  
23  /**
24   * This class is to modify the constructor 
25   * change the field Type : Interfacetype with type W3CEndpointReference 
26   * the code to initialize some fields.
27   */
28  public class ConstructorModMethodVisitor extends TraceMethodVisitor {
29  
30    /**
31     * Logger.
32     */
33    private static final Logger LOG
34            = LoggerFactory.getLogger(ConstructorModMethodVisitor.class);
35  
36  
37   /**
38    * The name of the class.
39    */
40    private String className = null;
41  
42    // Utility Object
43    private ByteCodeManipulationUtil bcmUtil = new ByteCodeManipulationUtil();
44    
45    private Map<String, InterfaceType> allIntTypes;
46  
47   /**
48    * Constructor.
49    *
50    * @param    mv                The method visitor.
51    * @param    mapOfFields        The fields to initialize.
52    * @param    className        The name of the class.
53   * @param allInterfaceTypes 
54    */
55    public ConstructorModMethodVisitor(MethodVisitor mv,
56                                String className, Map<String, InterfaceType> allInterfaceTypes) {
57      super(mv);
58  
59      
60      this.className = className;
61      allIntTypes=allInterfaceTypes;
62    }
63  
64    
65    /**
66     * This method visit the code of the constructor and change InterfaceType with W3CEndpointRef 
67     * 
68     * */
69    
70      @Override
71    public void visitFieldInsn(int opcode,String className,String fieldName,String fieldType){
72  	  
73  	  LOG.debug("<<<<< AppenderMethodVisitor.visitInsn - end");
74  	  if(opcode==Opcodes.PUTFIELD){
75  		  boolean isArray=TypeUtils.isArray(fieldType);
76  	  		  if(TypeUtils.isSearchedType(fieldType, isArray, allIntTypes, TypeUtils.INTERFACE)!=null){
77  	  			  if (isArray){
78  	  				  fieldType= Type.getDescriptor(javax.xml.ws.wsaddressing.W3CEndpointReference[].class);
79  		  
80  	  			  }else{
81  	  				  
82  	  				  fieldType= Type.getDescriptor(javax.xml.ws.wsaddressing.W3CEndpointReference.class);
83  	  				
84  	  			  }
85  	  }
86  	  super.visitFieldInsn(opcode,className,fieldName,fieldType);
87  	  
88  	  }
89  	  
90    }
91    
92    
93   
94  	
95    
96    
97  
98  }