From e5b7380c874745c989d1816b8f552504f038e1bc Mon Sep 17 00:00:00 2001 From: lresende Date: Thu, 26 Sep 2013 20:33:20 +0000 Subject: 2.0 branch for possible maintenance release git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1526672 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/binding/ejb/util/MethodInfo.java | 189 +++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 sca-java-2.x/branches/2.0/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java (limited to 'sca-java-2.x/branches/2.0/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java') diff --git a/sca-java-2.x/branches/2.0/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java b/sca-java-2.x/branches/2.0/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java new file mode 100644 index 0000000000..e7ea7c9077 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +/** + * MetaData for a java method + * + * @version $Rev$ $Date$ + */ +class MethodInfo implements Serializable { + + /** Automatically generated javadoc for: serialVersionUID */ + private static final long serialVersionUID = -5557260979514687514L; + private String name; + private String returnType; + private String[] parameterTypes; + private String[] exceptionTypes; + + private String IDLName; + + private transient Method method; + + /** + * Type Signature Java Type -------------- --------- Z boolean B byte C char + * S short I int J long F float D double L fully-qualified-class ; + * fully-qualified-class [ type type[] ( arg-types ) ret-type method type + */ + private static final Map signatures = new HashMap(); + static { + signatures.put("Z", boolean.class); + signatures.put("B", byte.class); + signatures.put("C", char.class); + signatures.put("S", short.class); + signatures.put("I", int.class); + signatures.put("J", long.class); + signatures.put("F", float.class); + signatures.put("D", double.class); + signatures.put("V", void.class); + } + + MethodInfo(Method method) { + this.method = method; + this.name = method.getName(); + // this.declaringClass = method.getDeclaringClass().getName(); + this.returnType = method.getReturnType().getName(); + Class[] types = method.getParameterTypes(); + this.parameterTypes = new String[types.length]; + for (int i = 0; i < types.length; i++) { + this.parameterTypes[i] = types[i].getName(); + } + types = method.getExceptionTypes(); + this.exceptionTypes = new String[types.length]; + for (int i = 0; i < types.length; i++) { + this.exceptionTypes[i] = types[i].getName(); + } + IDLName = this.name; + } + + MethodInfo(String name, String returnType, String[] parameterTypes, String[] exceptionTypes) { + this.name = name; + this.returnType = returnType; + this.parameterTypes = parameterTypes; + this.exceptionTypes = exceptionTypes; + this.IDLName = name; + } + + /** + * Parse the class name from the internal signature Sample signatures: int + * ---> I; int[] ---> [I Object ---> java/lang/Object Object[] ---> + * [Ljava/lang/Object; + * + * @param value + * @return + */ + private static String getName(String signature) { + String name = signature; + // Remove leading ARRAY ([) signatures + int index = name.lastIndexOf('['); + if (index != -1) + name = name.substring(index + 1); + + // Remove L<...>; + if (name.charAt(0) == 'L' && name.charAt(name.length() - 1) == ';') + name = name.substring(1, name.length() - 1); + + // Primitive types + Class primitiveClass = (Class)signatures.get(name); + if (primitiveClass != null) { + name = primitiveClass.getName(); + } + + for (int i = 0; i < index + 1; i++) { + name = name + "[]"; + } + return name; + } + + /** + * @return + */ + String getName() { + return name; + } + + /** + * @return + */ + String[] getParameterTypes() { + return parameterTypes; + } + + /** + * @return + */ + String getReturnType() { + return returnType; + } + + /** + * @return + */ + String[] getExceptionTypes() { + return exceptionTypes; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(getName(returnType)).append(" ").append(name).append("("); + for (int j = 0; j < parameterTypes.length; j++) { + sb.append(getName(parameterTypes[j])).append(" ").append("arg" + j); + if (j < (parameterTypes.length - 1)) + sb.append(", "); + } + sb.append(")"); + if (exceptionTypes.length > 0) { + sb.append(" throws "); + for (int k = 0; k < exceptionTypes.length; k++) { + sb.append(exceptionTypes[k]); + if (k < (exceptionTypes.length - 1)) + sb.append(", "); + } + } + sb.append(";"); + return sb.toString(); + } + + /** + * @return Returns the iDLName. + */ + String getIDLName() { + return IDLName; + } + + /** + * @param name The iDLName to set. + */ + void setIDLName(String name) { + IDLName = name; + } + + /** + * @return the method + */ + Method getMethod() { + return method; + } +} -- cgit v1.2.3