1 package org.ashkelon.pages; 2 3 import org.ashkelon.*; 4 import org.ashkelon.util.*; 5 import org.ashkelon.db.*; 6 7 import java.util.*; 8 import java.sql.*; 9 10 11 14 public class XrefsPage extends Page 15 { 16 public XrefsPage() 17 { 18 super(); 19 } 20 21 public String handleRequest() throws SQLException, ClassNotFoundException 22 { 23 int clsId = Integer.parseInt(ServletUtils.getRequestParam(request, "cls_id")); 24 String cmd = ServletUtils.getCommand(request); 25 26 ClassType cls = ClassType.makeClassFor(conn, clsId, true); 27 request.setAttribute("cls", cls); 28 29 if (cmd.equals("cls.xref")) 30 return null; 31 32 String xrefType = StringUtils.split(cmd, ".")[2]; 33 if (xrefType.equals("field")) 34 doFields(clsId); 35 else if (xrefType.equals("returnedby")) 36 doReturnedBy(clsId); 37 else if (xrefType.equals("passedto")) 38 doPassedTo(clsId); 39 else if (xrefType.equals("thrownby")) 40 doThrownBy(clsId); 41 else if (xrefType.equals("implementedby")) 42 doImplementedBy(clsId); 43 else if (xrefType.equals("extendedby")) 44 doExtendedBy(clsId); 45 else if (xrefType.equals("subclasses")) 46 doSubclasses(cls); 47 else if (xrefType.equals("descendents")) 48 { 49 TreeNode descendents = cls.getDescendents(conn); 50 request.setAttribute("descendents", descendents); 51 } 52 53 return null; 54 } 55 56 public void doFields(int clsId) throws SQLException 57 { 58 ResultSet rset = executeQuery("xref_fields", clsId); 59 int position = position(rset); 60 61 List fields = new ArrayList(); 62 FieldMember field; 63 while (rset.next() && rset.getRow() <= (position + FETCH_SIZE)) 64 { 65 field = new FieldMember(rset.getString(1), rset.getString(3)); 66 field.setId(rset.getInt(2)); 67 field.setTypeDimension(rset.getInt(4)); 68 field.setStatic(rset.getBoolean(6)); 69 field.setFinal(rset.getBoolean(7)); 70 field.setAccessibility(rset.getInt(8)); 71 DocInfo doc = new DocInfo(); 72 doc.setSummaryDescription(rset.getString(5)); 73 doc.setDeprecated(rset.getString(9)); 74 field.setDoc(doc); 75 fields.add(field); 76 } 77 78 rset.close(); 79 request.setAttribute("field", fields); 80 } 81 82 private ResultSet executeQuery(String stmtName, int clsId) 83 throws SQLException 84 { 85 String sql = DBMgr.getInstance().getStatement(stmtName); 86 87 PreparedStatement pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, 88 ResultSet.CONCUR_READ_ONLY); 89 pstmt.setInt(1, clsId); 90 pstmt.setFetchSize(FETCH_SIZE); 91 return pstmt.executeQuery(); 92 } 93 94 public void doReturnedBy(int clsId) throws SQLException 95 { 96 ResultSet rset = executeQuery("xref_returnedby", clsId); 97 int position = position(rset); 98 99 List methods = new ArrayList(); 100 MethodMember method; 101 while (rset.next() && rset.getRow() <= (position + FETCH_SIZE)) 102 { 103 method = new MethodMember(rset.getString(1), rset.getString(7)); 104 method.setId(rset.getInt(2)); 105 method.setStatic(rset.getBoolean(3)); 106 method.setFinal(rset.getBoolean(4)); 107 method.setAccessibility(rset.getInt(5)); 108 method.setModifiers(rset.getString(6)); 109 110 method.setReturnTypeName(rset.getString(8)); 111 method.setReturnTypeDimension(rset.getInt(9)); 112 method.setAbstract(rset.getBoolean(10)); 113 114 method.setDoc(new DocInfo(rset.getString(11), rset.getString(12), rset.getString(13))); 115 116 methods.add(method); 117 } 118 119 rset.close(); 120 request.setAttribute("returnedby", methods); 121 } 122 123 124 public void doPassedTo(int clsId) throws SQLException 125 { 126 ResultSet rset = executeQuery("xref_passedto", clsId); 127 int position = position(rset); 128 129 List execs = new ArrayList(); 130 ExecMember exec; 131 int memberType; 132 while (rset.next() && rset.getRow() <= (position + FETCH_SIZE)) 133 { 134 memberType = rset.getInt(3); 135 if (memberType == Member.METHOD_MEMBER) 136 { 137 exec = new MethodMember(rset.getString(1), rset.getString(4)); 138 ((MethodMember) exec).setAbstract(rset.getBoolean(14)); 139 } 140 else 141 { 142 exec = new ConstructorMember(rset.getString(1), rset.getString(4)); 143 } 144 145 exec.setId(rset.getInt(2)); 146 exec.setModifiers(rset.getString(13)); 147 exec.setAccessibility(rset.getInt(12)); 148 exec.setFinal(rset.getBoolean(11)); 149 exec.setStatic(rset.getBoolean(10)); 150 151 exec.setDoc(new DocInfo(rset.getString(5), rset.getString(6), rset.getString(7))); 152 execs.add(exec); 153 } 154 155 rset.close(); 156 request.setAttribute("passedto", execs); 157 } 158 159 160 public void doThrownBy(int clsId) throws SQLException 161 { 162 ResultSet rset = executeQuery("xref_thrownby", clsId); 163 int position = position(rset); 164 165 List execs = new ArrayList(); 166 ExecMember exec; 167 int memberType; 168 while (rset.next() && rset.getRow() <= (position + FETCH_SIZE)) 169 { 170 memberType = rset.getInt(3); 171 if (memberType == Member.METHOD_MEMBER) 172 exec = new MethodMember(rset.getString(1), rset.getString(4)); 173 else 174 exec = new ConstructorMember(rset.getString(1), rset.getString(4)); 175 176 exec.setId(rset.getInt(2)); 177 178 DocInfo doc = new DocInfo(); 179 doc.setSummaryDescription(rset.getString(5)); 180 exec.setDoc(doc); 181 182 execs.add(exec); 183 } 184 185 rset.close(); 186 request.setAttribute("thrownby", execs); 187 } 188 189 190 public void doExtendedBy(int clsId) throws SQLException 191 { 192 doImplementedBy(clsId, "extendedby"); 193 } 194 195 public void doImplementedBy(int clsId) throws SQLException 196 { 197 doImplementedBy(clsId, "implementedby"); 198 } 199 200 public void doImplementedBy(int clsId, String key) throws SQLException 201 { 202 ResultSet rset = null; 203 rset = executeQuery("xref_"+key, clsId); 204 205 int position = position(rset); 206 207 List classes = new ArrayList(); 208 ClassType c; 209 while (rset.next() && rset.getRow() <= (position + FETCH_SIZE)) 210 { 211 c = new ClassType(rset.getString(1)); 212 c.setId(rset.getInt(2)); 213 c.setClassType(rset.getInt(4)); 214 215 DocInfo doc = new DocInfo(); 216 doc.setSummaryDescription(rset.getString(3)); 217 c.setDoc(doc); 218 219 classes.add(c); 220 } 221 222 rset.close(); 223 request.setAttribute(key, classes); 224 } 225 226 227 public void doSubclasses(ClassType refc) throws SQLException 228 { 229 String sql = DBMgr.getInstance().getStatement("xref_subclass"); 230 231 PreparedStatement pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, 232 ResultSet.CONCUR_READ_ONLY); 233 pstmt.setString(1, refc.getQualifiedName()); 234 pstmt.setFetchSize(FETCH_SIZE); 235 ResultSet rset = pstmt.executeQuery(); 236 237 int position = position(rset); 238 239 List classes = new ArrayList(); 240 ClassType c; 241 while (rset.next() && rset.getRow() <= (position + FETCH_SIZE)) 242 { 243 c = new ClassType(rset.getString(1)); 244 c.setId(rset.getInt(2)); 245 c.setClassType(rset.getInt(4)); 246 247 DocInfo doc = new DocInfo(); 248 doc.setSummaryDescription(rset.getString(3)); 249 c.setDoc(doc); 250 251 classes.add(c); 252 } 253 254 rset.close(); 255 request.setAttribute("subclasses", classes); 256 } 257 258 259 } 260 | Popular Tags |