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;
9   
10  import it.imolinfo.jbi4corba.Logger;
11  import it.imolinfo.jbi4corba.LoggerFactory;
12  import it.imolinfo.jbi4corba.webservice.generator.bcm.InternalMethodDescriptionParser;
13  
14  import java.util.HashMap;
15  import java.util.Map;
16  
17  import java.util.Set;
18  import org.objectweb.asm.Type;
19  import org.omg.CORBA.TCKind;
20  
21  /**
22   * 
23   * @author Luca
24   */
25  public class InterfaceTypeUtils extends TypeUtils {
26  
27  	private static final TCKind INTERFACE = TCKind.tk_objref;
28  
29  	private static final Logger LOG = LoggerFactory
30  			.getLogger(InterfaceTypeUtils.class);
31  
32  	@Override
33      protected SearchedType processType(Class clsType) {
34  
35  		InterfaceType it = new InterfaceType(clsType.getName());
36  
37  		return it;
38  
39  	}
40  
41  	@Override
42  	protected Map<String, Class> getFields(Class clsUnion) {
43  		return new HashMap<String, Class>();
44  	}
45  
46  	/**
47  	 * isUnionType - verify that is union type
48  	 * 
49  	 * @param desc
50  	 * @return
51  	 */
52  	public static InterfaceType isInterfaceType(String desc, boolean isArray,
53  			Map<String, InterfaceType> allInterfaceTypes) {
54  
55  		return (InterfaceType) TypeUtils.isSearchedType(desc, isArray,
56  				allInterfaceTypes, INTERFACE);
57  	}
58  
59  	/**
60  	 * This Method change the type paramters and the return parameters
61  	 * 
62  	 * @param String
63  	 *            the descriptor that contains the parameter
64  	 * @param Map
65  	 *            th map that contains all the interfecs type
66  	 * */
67  
68  	public static String changeInterfaceTypeDesc(String desc,
69  			Map allInterfaceTypes) {
70  
71  		LOG.debug("Changing description: " + desc);		
72  		// Remove "(" and ";")
73  		// Extract param from desc => there are some param with the form
74  		int start = desc.indexOf("(");		
75  		String descStart = desc.substring(0, start + 1);		
76  
77  		// Extract Params
78  		InternalMethodDescriptionParser parser = new InternalMethodDescriptionParser(desc);
79  		String params[] = parser.parse().toArray(new String[] {});
80  
81  		// String params[] = Util.extractParamsformDesc(desc);
82  		String result = descStart;
83  		String retType = null;
84  
85  		// Process All Parameters
86  		for (int i = 0; i < params.length; i++) {
87  			LOG.debug("Investigating: " + params[i]);
88  			boolean isArray = TypeUtils.isArray(params[i]);
89  			if (TypeUtils.isSearchedType(params[i], isArray,
90  					allInterfaceTypes, TypeUtils.INTERFACE) != null) {
91  
92  				if (isArray) {
93  
94  					result += Type
95  							.getDescriptor(javax.xml.ws.wsaddressing.W3CEndpointReference[].class);					
96  				} else {
97  					result += Type
98  							.getDescriptor(javax.xml.ws.wsaddressing.W3CEndpointReference.class);
99  				}
100 
101 			} else {
102 				result += params[i];				
103 			}
104 		}
105 
106 		result += ")";	
107 		
108 		retType = parser.getMethodDescriptionTail();
109 		// is ReturnType
110 		if (retType.contains("L")) {
111 					
112 			boolean isArray = TypeUtils.isArray(retType);
113 			if (retType != null) {
114 
115 				if (TypeUtils.isSearchedType(retType, isArray,
116 						allInterfaceTypes, TypeUtils.INTERFACE) != null) {
117 
118 					if (isArray) {
119 
120 						retType = Type
121 								.getDescriptor(javax.xml.ws.wsaddressing.W3CEndpointReference[].class);
122 					} else {
123 						retType = Type
124 								.getDescriptor(javax.xml.ws.wsaddressing.W3CEndpointReference.class);
125 					}
126 				}
127 			}
128 		} if (retType != null) {
129 			result += retType;
130 		}		
131 		LOG.debug("Changing description end, returning: " + result);
132 		return result;
133 
134 	}
135 
136 	@Override
137 	protected void setMethodTypes(MethodSignature methodSignature,
138 			Set<String> typeList) {
139 		methodSignature.setMethodInterfaceTypes(typeList);
140 	}
141 
142 }