1 19 package org.objectweb.carol.cmi.compiler; 20 21 import java.lang.reflect.Method ; 22 23 24 public class MethodConf { 25 private MethodProto methodProto; 26 private ClassConf ccc; 27 private String balancer; 28 private Method method = null; 29 30 public MethodConf(ClassConf ccc, MethodProto mp, String balancerName) { 31 this.ccc = ccc; 32 methodProto = mp; 33 if (balancerName == null) { 34 balancerName = ccc.getBalancer(); 35 } 36 this.balancer = balancerName; 37 } 38 39 public ClassConf getClassConf() { 40 return ccc; 41 } 42 43 public MethodProto getMethodProto() { 44 return methodProto; 45 } 46 47 public String getBalancer() { 48 return balancer; 49 } 50 51 public Method getMethod() { 52 return method; 53 } 54 55 public String getMthName() { 56 return method.getName(); 57 } 58 59 public String getReturnTypeName() { 60 return MethodProto.getName(method.getReturnType()); 61 } 62 63 private String paramString; 64 65 public String getParamString() { 66 if (paramString != null) { 67 return paramString; 68 } 69 Class [] params = method.getParameterTypes(); 70 String s = ""; 71 for (int i=0; i<params.length; i++) { 72 if (s.equals("")) { 73 s = MethodProto.getName(params[i]) + " param" + (i + 1); 74 } else { 75 s += ", " + MethodProto.getName(params[i]) + " param" + (i + 1); 76 } 77 } 78 paramString = s; 79 return s; 80 } 81 82 private String paramNamesString; 83 84 public String getParamNamesString() { 85 if (paramNamesString != null) { 86 return paramNamesString; 87 } 88 int len = method.getParameterTypes().length; 89 String s = ""; 90 for (int i=0; i<len; i++) { 91 if (s.equals("")) { 92 s = "param" + (i + 1); 93 } else { 94 s += ", param" + (i + 1); 95 } 96 } 97 paramNamesString = s; 98 return s; 99 } 100 101 private String throwsString; 102 103 public String getThrowsString() { 104 if (throwsString != null) { 105 return throwsString; 106 } 107 Class [] ex = method.getExceptionTypes(); 108 String s = ""; 109 for (int i=0; i<ex.length; i++) { 110 if (s.equals("")) { 111 s = MethodProto.getName(ex[i]); 112 } else { 113 s += ", " + MethodProto.getName(ex[i]); 114 } 115 } 116 throwsString = s; 117 return s; 118 } 119 120 public String getDeclItfName() { 121 return MethodProto.getName(method.getDeclaringClass()); 122 } 123 124 public boolean returnsVoid() { 125 return method.getReturnType().equals(void.class); 126 } 127 128 public void setMethod(Method method) throws CompilerException { 129 if (this.method == null) { 130 this.method = method; 131 } else { 132 throw new CompilerException("internal error"); 133 } 134 } 135 } 136 | Popular Tags |