1 28 29 package com.caucho.es.wrapper; 30 31 import java.beans.IntrospectionException ; 32 import java.beans.MethodDescriptor ; 33 import java.lang.reflect.Method ; 34 import java.lang.reflect.Modifier ; 35 36 39 public class ESMethodDescriptor extends MethodDescriptor { 40 String name; 41 boolean overwrite; 42 boolean staticVirtual; 43 Class declaringClass; 44 String classJVMName; 45 Class []parameterTypes; 46 47 54 public ESMethodDescriptor(Method method, boolean overwrite, 55 boolean staticVirtual) 56 throws IntrospectionException 57 { 58 super(method); 59 60 this.name = method.getName(); 61 if (this.name == null) 62 throw new RuntimeException (); 63 this.overwrite = overwrite; 64 this.staticVirtual = staticVirtual; 65 } 66 67 public ESMethodDescriptor(ESMethodDescriptor md) 68 throws IntrospectionException 69 { 70 super(md.getMethod()); 71 72 this.name = md.getName(); 73 this.overwrite = md.overwrite; 74 this.staticVirtual = md.staticVirtual; 75 this.declaringClass = md.declaringClass; 76 this.parameterTypes = md.parameterTypes; 77 this.classJVMName = md.classJVMName; 78 } 79 80 public String getName() 81 { 82 return name; 83 } 84 85 public void setName(String name) 86 { 87 this.name = name; 88 } 89 90 93 boolean isOverwrite() 94 { 95 return overwrite; 96 } 97 98 public boolean isStaticVirtual() 99 { 100 return staticVirtual; 101 } 102 103 106 public boolean isStatic() 107 { 108 return ! staticVirtual && Modifier.isStatic(getMethod().getModifiers()); 109 } 110 111 114 public boolean overwrites(ESMethodDescriptor md) 115 { 116 if (! isStatic() && md.isStatic()) 117 return true; 118 else if (isOverwrite() && ! md.isOverwrite()) 119 return true; 120 else 121 return false; 122 } 123 124 127 public Class []getParameterTypes() 128 { 129 if (parameterTypes != null) 130 return parameterTypes; 131 132 if (! isStaticVirtual()) 133 parameterTypes = getMethod().getParameterTypes(); 134 else { 135 Class []realParam = getMethod().getParameterTypes(); 136 137 parameterTypes = new Class [realParam.length - 1]; 138 139 for (int i = 0; i < parameterTypes.length; i++) 140 parameterTypes[i] = realParam[i + 1]; 141 } 142 143 return parameterTypes; 144 } 145 146 149 public Class getDeclaringClass() 150 { 151 if (declaringClass == null) { 152 if (staticVirtual) 153 declaringClass = getMethod().getParameterTypes()[0]; 154 else 155 declaringClass = getMethod().getDeclaringClass(); 156 } 157 158 return declaringClass; 159 } 160 161 164 public Class getReturnType() 165 { 166 return getMethod().getReturnType(); 167 } 168 169 173 public String getMethodClassName() 174 { 175 return getMethod().getDeclaringClass().getName(); 176 } 177 178 String getObjectClassName() 179 { 180 return getDeclaringClass().getName(); 181 } 182 183 String getClassJVMName() 184 { 185 if (classJVMName == null) 186 classJVMName = getDeclaringClass().getName().replace('.', '/'); 187 188 return classJVMName; 189 } 190 191 public String toString() 192 { 193 Class []param = getParameterTypes(); 194 195 if (param == null || param.length == 0) 196 return ("[ESMethodDescriptor " + getDeclaringClass().getName() + 197 "." + getName() + "]"); 198 else 199 return ("[ESMethodDescriptor " + getDeclaringClass().getName() + 200 "." + getName() + " " + param[0] + "]"); 201 } 202 } 203 204 205 | Popular Tags |