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 it.imolinfo.jbi4corba.webservice.generator.AnyType;
13  import it.imolinfo.jbi4corba.webservice.generator.TypeUtils;
14  
15  import org.objectweb.asm.MethodVisitor;
16  import org.objectweb.asm.Opcodes;
17  import org.objectweb.asm.util.TraceMethodVisitor;
18  
19  /**
20   * This class is to modify the all methods that contain any attribution
21   * Replace: Any with type Object the code to initialize some fields.
22   * 
23   * @author laurLG
24   */
25  public class ReplaceAnyMethodVisitor extends TraceMethodVisitor {
26  
27  	/**
28  	 * Logger.
29  	 */
30  	private static final Logger LOG = LoggerFactory
31  			.getLogger(ConstructorModMethodVisitor.class);
32  
33  	/**
34  	 * Constructor.
35  	 * 
36  	 * @param mv
37  	 *            The method visitor.
38  	 */
39  	public ReplaceAnyMethodVisitor(MethodVisitor mv) {
40  		super(mv);
41  	}
42  
43  	/**
44  	 * This method visit the code of the constructor and change Any
45  	 * with Object
46  	 * 
47  	 */
48           @Override
49  	public void visitFieldInsn(int opcode, String className, String fieldName,
50  			String fieldType) {
51  
52  		LOG.debug("<<<<< AppenderMethodVisitor.visitInsn - end");
53  		if (opcode == Opcodes.PUTFIELD) {
54  			
55  			String arrayStr = TypeUtils.getArrayDimmentionAsPrefix(fieldType);
56  			boolean isAny = TypeUtils.getTypeFromTypeDescription(fieldType).equals(AnyType.CORBA_ANY_TYPE);
57  			if (isAny) {
58  				
59  					fieldType = arrayStr + "Ljava/lang/Object;";
60  			}
61  		}
62  		super.visitFieldInsn(opcode, className, fieldName, fieldType);
63  
64  	}
65  
66  }