1 48 49 package com.caucho.services.server; 50 51 import java.io.InputStream ; 52 import java.lang.reflect.Method ; 53 import java.util.HashMap ; 54 55 58 abstract public class AbstractSkeleton { 59 private Class _apiClass; 60 private Class _homeClass; 61 private Class _objectClass; 62 63 private HashMap _methodMap = new HashMap (); 64 65 70 protected AbstractSkeleton(Class apiClass) 71 { 72 _apiClass = apiClass; 73 74 Method []methodList = apiClass.getMethods(); 75 76 for (int i = 0; i < methodList.length; i++) { 77 Method method = methodList[i]; 78 79 if (_methodMap.get(method.getName()) == null) 80 _methodMap.put(method.getName(), methodList[i]); 81 82 Class []param = method.getParameterTypes(); 83 String mangledName = method.getName() + "__" + param.length; 84 _methodMap.put(mangledName, methodList[i]); 85 86 _methodMap.put(mangleName(method, false), methodList[i]); 87 } 88 } 89 90 93 public String getAPIClassName() 94 { 95 return _apiClass.getName(); 96 } 97 98 101 public String getHomeClassName() 102 { 103 if (_homeClass != null) 104 return _homeClass.getName(); 105 else 106 return getAPIClassName(); 107 } 108 109 112 public void setHomeClass(Class homeAPI) 113 { 114 _homeClass = homeAPI; 115 } 116 117 120 public String getObjectClassName() 121 { 122 if (_objectClass != null) 123 return _objectClass.getName(); 124 else 125 return getAPIClassName(); 126 } 127 128 131 public void setObjectClass(Class objectAPI) 132 { 133 _objectClass = objectAPI; 134 } 135 136 141 protected Method getMethod(String mangledName) 142 { 143 return (Method ) _methodMap.get(mangledName); 144 } 145 146 155 private String mangleName(Method method, boolean isFull) 156 { 157 StringBuffer sb = new StringBuffer (); 158 159 sb.append(method.getName()); 160 161 Class []params = method.getParameterTypes(); 162 for (int i = 0; i < params.length; i++) { 163 sb.append('_'); 164 mangleClass(sb, params[i], isFull); 165 } 166 167 return sb.toString(); 168 } 169 170 173 private void mangleClass(StringBuffer sb, Class cl, boolean isFull) 174 { 175 String name = cl.getName(); 176 177 if (name.equals("boolean") || name.equals("java.lang.Boolean")) 178 sb.append("boolean"); 179 else if (name.equals("int") || name.equals("java.lang.Integer") || 180 name.equals("short") || name.equals("java.lang.Short") || 181 name.equals("byte") || name.equals("java.lang.Byte")) 182 sb.append("int"); 183 else if (name.equals("long") || name.equals("java.lang.Long")) 184 sb.append("long"); 185 else if (name.equals("float") || name.equals("java.lang.Float") || 186 name.equals("double") || name.equals("java.lang.Double")) 187 sb.append("double"); 188 else if (name.equals("java.lang.String") || 189 name.equals("com.caucho.util.CharBuffer") || 190 name.equals("char") || name.equals("java.lang.Character") || 191 name.equals("java.io.Reader")) 192 sb.append("string"); 193 else if (name.equals("java.util.Date") || 194 name.equals("com.caucho.util.QDate")) 195 sb.append("date"); 196 else if (InputStream .class.isAssignableFrom(cl) || 197 name.equals("[B")) 198 sb.append("binary"); 199 else if (cl.isArray()) { 200 sb.append("["); 201 mangleClass(sb, cl.getComponentType(), isFull); 202 } 203 else if (name.equals("org.w3c.dom.Node") || 204 name.equals("org.w3c.dom.Element") || 205 name.equals("org.w3c.dom.Document")) 206 sb.append("xml"); 207 else if (isFull) 208 sb.append(name); 209 else { 210 int p = name.lastIndexOf('.'); 211 if (p > 0) 212 sb.append(name.substring(p + 1)); 213 else 214 sb.append(name); 215 } 216 } 217 } 218 | Popular Tags |