1 package org.ashkelon; 2 7 8 import java.sql.Connection ; 9 import java.sql.PreparedStatement ; 10 import java.sql.ResultSet ; 11 import java.sql.SQLException ; 12 import java.util.ArrayList ; 13 import java.util.Comparator ; 14 import java.util.HashMap ; 15 import java.util.List ; 16 import java.util.Map ; 17 18 import org.ashkelon.db.DBUtils; 19 import org.ashkelon.util.JDocUtil; 20 import org.ashkelon.util.StringUtils; 21 22 import com.sun.javadoc.ClassDoc; 23 import com.sun.javadoc.ExecutableMemberDoc; 24 import com.sun.javadoc.ParamTag; 25 import com.sun.javadoc.Parameter; 26 import com.sun.javadoc.ThrowsTag; 27 28 35 public class ExecMember extends Member implements Comparator 36 { 37 private boolean isSynchronized; 38 private boolean isNative; 39 private List thrownExceptions; 40 private String fullyQualifiedName; 41 private String signature; 42 private List parameters; 43 44 private static String TABLENAME = "EXECMEMBER"; 45 46 47 public ExecMember(String qualifiedName, String signature, int memberType) 48 { 49 super(qualifiedName, memberType); 50 setSignature(signature); 51 setFullyQualifiedName(qualifiedName+signature); 52 setThrownExceptions(new ArrayList ()); 53 setParameters(new ArrayList ()); 54 } 55 56 public ExecMember(Member member, String signature) 57 { 58 super(member); 59 setThrownExceptions(new ArrayList ()); 60 setParameters(new ArrayList ()); 61 setSignature(signature); 62 } 63 64 public ExecMember(ExecutableMemberDoc exmemdoc, ClassType containingClass) 65 { 66 super(exmemdoc, containingClass); 67 parameters = new ArrayList (); 68 thrownExceptions = new ArrayList (); 69 setNative(exmemdoc.isNative()); 70 setSynchronized(exmemdoc.isSynchronized()); 71 setSignature(exmemdoc.signature()); 72 setFullyQualifiedName(getQualifiedName() + getSignature()); 73 74 addParameters(exmemdoc.parameters(), exmemdoc.paramTags()); 75 addThrownExceptions(exmemdoc.thrownExceptions(), exmemdoc.throwsTags()); 76 } 77 78 public void store(Connection conn) throws SQLException 79 { 80 super.store(conn); 81 Map fieldInfo = new HashMap (10); 82 fieldInfo.put("ID", new Integer (getId(conn))); 83 84 int boolvalue = isSynchronized() ? 1 : 0; 86 fieldInfo.put("ISSYNCHRONIZED", new Integer (boolvalue)); 87 88 boolvalue = isNative() ? 1 : 0; 90 fieldInfo.put("ISNATIVE", new Integer (boolvalue)); 91 92 fieldInfo.put("SIGNATURE", StringUtils.truncate(getSignature(), 300)); 93 fieldInfo.put("FULLYQUALIFIEDNAME", StringUtils.truncate(getFullyQualifiedName(), 450)); 94 DBUtils.insert(conn, TABLENAME, fieldInfo); 95 96 for (int i=0; i<parameters.size(); i++) 97 { 98 ((ParameterInfo) parameters.get(i)).store(conn); 99 } 100 101 for (int i=0; i<thrownExceptions.size(); i++) 102 { 103 ((ThrownException) thrownExceptions.get(i)).store(conn); 104 } 105 } 106 107 public static void delete(Connection conn, int memberid, int docid) throws SQLException 108 { 109 deleteThrownExceptions(conn, memberid); 110 deleteParameters(conn, memberid); 111 112 Map constraint = new HashMap (); 113 constraint.put("ID", new Integer (memberid)); 114 DBUtils.delete(conn, TABLENAME, constraint); 115 116 Member.delete(conn, memberid, docid); 117 } 118 119 public static void deleteThrownExceptions(Connection conn, int memberid) throws SQLException 120 { 121 Map constraint = new HashMap (); 122 constraint.put("throwerid", new Integer (memberid)); 123 DBUtils.delete(conn, "THROWNEXCEPTION", constraint); 124 } 125 126 public static void deleteParameters(Connection conn, int memberid) throws SQLException 127 { 128 Map constraint = new HashMap (); 129 constraint.put("execmemberid", new Integer (memberid)); 130 DBUtils.delete(conn, "PARAMETER", constraint); 131 } 132 133 public boolean isNative(){ return isNative; } 135 public void setNative(boolean isNative){ this.isNative = isNative; } 136 137 public boolean isSynchronized(){ return isSynchronized; } 138 public void setSynchronized(boolean isSynchronized){ this.isSynchronized = isSynchronized; } 139 140 public String getFullyQualifiedName(){ return fullyQualifiedName; } 141 public void setFullyQualifiedName(String fullyQualifiedName){ this.fullyQualifiedName = fullyQualifiedName; } 142 143 public String getSignature(){ return signature; } 144 public void setSignature(String signature){ this.signature = signature; } 145 146 public List getParameters() { return parameters; } 147 public void setParameters(List parameters) { this.parameters = parameters; } 148 149 public void addParameters(Parameter[] parameters, ParamTag[] tags) 150 { 151 Map paramMap = JDocUtil.makeParamMap(getDoc(), tags); 152 String paramdescription; 153 ParameterInfo paramInfo = null; 154 155 for (int i=0; i<parameters.length; i++) 156 { 157 if (paramMap.get(parameters[i].name()) == null) 158 { 159 paramdescription = ""; 160 } else 161 { 162 paramdescription = (String ) paramMap.get(parameters[i].name()); 163 } 164 paramInfo = new ParameterInfo(parameters[i], i, paramdescription, this); 165 addParameter(paramInfo); 166 } 167 } 168 169 public void addParameter(ParameterInfo param) 170 { 171 this.parameters.add(param); 172 } 173 174 175 public List getThrownExceptions() { return thrownExceptions; } 176 public void setThrownExceptions(List thrownExceptions) { this.thrownExceptions = thrownExceptions; } 177 178 public void addThrownExceptions(ClassDoc[] exceptions, ThrowsTag[] throwsTags) 179 { 180 String exceptionComment; 181 ThrownException thrownException; 182 for (int i=0; i<exceptions.length; i++) 183 { 184 exceptionComment = ""; 185 for (int j=0; j<throwsTags.length; j++) 186 { 187 if (exceptions[i].qualifiedName().endsWith(throwsTags[j].exceptionName())) 188 { 189 exceptionComment = JDocUtil.resolveDescription(getDoc(), throwsTags[j].inlineTags()); 191 break; 192 } 193 } 194 thrownException = new ThrownException(exceptions[i].qualifiedName(), exceptionComment, this); 195 addThrownException(thrownException); 196 } 197 } 198 199 public void addThrownException(ThrownException thrownException) 200 { 201 thrownExceptions.add(thrownException); 202 } 203 204 205 public int compare(Object first, Object second) 206 { 207 ExecMember m1 = (ExecMember) first; 208 ExecMember m2 = (ExecMember) second; 209 if (m1.getQualifiedName().equals(m2.getQualifiedName())) 210 { 211 return (m1.getParameters().size() - m2.getParameters().size()); 212 } 213 else 214 { 215 return 1; 216 } 217 } 218 219 220 public void fetchParameters(Connection conn) throws SQLException 221 { 222 223 String sql = 224 "select p.name, p.description, p.typeid, p.typedimension, " + 225 " p.typename, p.listedorder " + 226 "from PARAMETER p " + 227 " where p.execmemberid=? " + 228 " order by p.listedorder"; 229 230 PreparedStatement pstmt = conn.prepareStatement(sql); 231 pstmt.setInt(1, getId()); 232 ResultSet rset = pstmt.executeQuery(); 233 234 ParameterInfo param; 235 while (rset.next()) 236 { 237 param = new ParameterInfo(rset.getString(5)); 238 param.setName(rset.getString(1)); 239 param.setDescription(rset.getString(2)); 240 param.setListedOrder(rset.getInt(6)); 241 param.setTypeDimension(rset.getInt(4)); 242 param.setContainingMember(this); 243 int typeid = rset.getInt(3); 244 if (typeid > 0) { 246 param.setType(new ClassType(param.getTypeName())); 247 param.getType().setId(typeid); 248 } 249 addParameter(param); 250 } 251 252 rset.close(); 253 pstmt.close(); 254 } 255 256 public void fetchExceptions(Connection conn) throws SQLException 257 { 258 String sql = 259 "select ex.exceptionid, ex.name, ex.description " + 260 " from THROWNEXCEPTION ex " + 261 " where ex.throwerid=? " + 262 " order by ex.name"; 263 264 PreparedStatement pstmt = conn.prepareStatement(sql); 265 pstmt.setInt(1, getId()); 266 ResultSet rset = pstmt.executeQuery(); 267 268 ThrownException ex; 269 while (rset.next()) 270 { 271 ex = new ThrownException(rset.getString(2)); 272 ex.setDescription(rset.getString(3)); 273 int exid = rset.getInt(1); 274 if (exid > 0) { 276 ex.setException(new ClassType(ex.getName())); 277 ex.getException().setId(exid); 278 } 279 ex.setThrower(this); 280 addThrownException(ex); 281 } 282 283 rset.close(); 284 pstmt.close(); 285 } 286 } 287 | Popular Tags |