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.TypeUtils;
13  import it.imolinfo.jbi4corba.webservice.generator.UnionType;
14  import it.imolinfo.jbi4corba.webservice.generator.UnionTypeUtils;
15  
16  import java.util.Map;
17  
18  import org.objectweb.asm.MethodVisitor;
19  import org.objectweb.asm.Opcodes;
20  import org.objectweb.asm.util.TraceMethodVisitor;
21  
22  /**
23   * This class is to modify the all methods that contain uniontype attribution
24   * Replace: Uniontype with type Object the code to initialize some fields.
25   */
26  public class ReplaceUnionsMethodVisitor extends TraceMethodVisitor {
27  
28  	
29  
30  	/**
31  	 * Logger.
32  	 */
33  	private static final Logger LOG = LoggerFactory
34  			.getLogger(ConstructorModMethodVisitor.class);
35  
36  	private Map<String, UnionType> allUnionTypes;
37  
38  	/**
39  	 * Constructor.
40  	 * 
41  	 * @param mv
42  	 *            The method visitor.
43  	 * @param mapOfFields
44  	 *            The fields to initialize.
45  	 * @param className
46  	 *            The name of the class.
47  	 * @param allInterfaceTypes
48  	 */
49  	public ReplaceUnionsMethodVisitor(MethodVisitor mv,
50  			Map<String, UnionType> allUnionTypes) {
51  		super(mv);
52  
53  		this.allUnionTypes = allUnionTypes;
54  	}
55  
56  	/**
57  	 * This method visit the code of the methods and change type of union with wrappers
58  	 * 
59  	 */
60           @Override
61  	public void visitFieldInsn(int opcode, String className, String fieldName,
62  			String fieldType) {
63  
64  		LOG.debug("<<<<< AppenderMethodVisitor.visitFieldInsn - end");
65  		if (opcode == Opcodes.PUTFIELD || opcode == Opcodes.GETFIELD) {
66  			boolean isArray = TypeUtils.isArray(fieldType);
67  			UnionType unionField = UnionTypeUtils.isUnionType(fieldType, isArray, allUnionTypes);
68  			if ( unionField != null) {
69  				String arrayStr = TypeUtils.getArrayDimmentionAsPrefix(fieldType);
70  				
71  				fieldType = arrayStr + "L" + unionField.getTypeName().replace('.', '/') + "Wrapper;";
72  
73  				
74  			}
75  		}
76  		super.visitFieldInsn(opcode, className, fieldName, fieldType);
77  
78  	}
79  	
80  	
81  
82  }