1 package org.ashkelon; 2 7 8 import java.io.Serializable ; 9 import java.sql.Connection ; 10 import java.sql.PreparedStatement ; 11 import java.sql.ResultSet ; 12 import java.sql.SQLException ; 13 import java.util.ArrayList ; 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.db.PKManager; 20 import org.ashkelon.util.JDocUtil; 21 import org.ashkelon.util.Logger; 22 import org.ashkelon.util.StringUtils; 23 24 import com.sun.javadoc.ClassDoc; 25 import com.sun.javadoc.Doc; 26 import com.sun.javadoc.MemberDoc; 27 import com.sun.javadoc.PackageDoc; 28 import com.sun.javadoc.SeeTag; 29 30 37 public class DocInfo implements Serializable 38 { 39 private String since; 40 private String deprecated; 41 private String summaryDescription; 42 private String description; 43 private int docType; 44 private List references; 45 46 private int id; 47 private boolean idSet = false; 48 49 private static String SEQUENCE = "DOC_SEQ"; 50 private static String TABLENAME = "DOC"; 51 52 53 public static final int PACKAGE_TYPE = 1; 54 55 public static final int CLASS_TYPE = 2; 56 57 public static final int MEMBER_TYPE = 3; 58 59 public static final int EXECMEMBER_TYPE = 4; 60 61 public static final String [] DOCTYPES = {"pkg", "cls", "member", "member"}; 62 63 64 public DocInfo() 65 { 66 setSummaryDescription(""); 67 setDescription(""); 68 setSince(""); 69 setDeprecated(""); 70 setReferences(new ArrayList ()); 71 } 72 73 public DocInfo(String summaryDescription, String since, String deprecated) 74 { 75 this(summaryDescription, since, deprecated, ""); 76 } 77 78 public DocInfo(String summaryDescription, String since, String deprecated, String description) 79 { 80 setSummaryDescription(summaryDescription); 81 setDescription(description); 82 setSince(since); 83 setDeprecated(deprecated); 84 setReferences(new ArrayList ()); 85 } 86 87 public DocInfo(Doc doc) 88 { 89 this(); 90 setSince(JDocUtil.getTagText(doc.tags("@since"))); 91 setDeprecated(JDocUtil.resolveDescription(this, doc.tags("@deprecated"))); 92 93 addReferences(doc.seeTags()); 94 setDocType(getDocType(doc)); 95 96 setSummaryDescription(JDocUtil.resolveDescription(this, doc.firstSentenceTags())); 97 setDescription(JDocUtil.resolveDescription(this, doc.inlineTags())); 98 102 } 103 104 public void store(Connection conn) throws SQLException 105 { 106 Map fieldInfo = new HashMap (10); 107 fieldInfo.put("ID", new Integer (getId(conn))); 108 fieldInfo.put("DOC_TYPE", new Integer (getDocType())); 109 110 fieldInfo.put("SINCE", StringUtils.truncate(getSince(), 75)); 111 fieldInfo.put("DEPRECATED", StringUtils.truncate(getDeprecated(), 100)); 112 fieldInfo.put("SUMMARYDESCRIPTION", getSummaryDescription()); 113 fieldInfo.put("DESCRIPTION", getDescription()); 114 115 try 116 { 117 DBUtils.insert(conn, TABLENAME, fieldInfo); 118 } 119 catch (SQLException ex) 120 { 121 fieldInfo.put("SUMMARYDESCRIPTION", StringUtils.truncate(getSummaryDescription(), 400)); 122 fieldInfo.put("DESCRIPTION", StringUtils.truncate(getDescription(), 3600)); 123 DBUtils.insert(conn, TABLENAME, fieldInfo); 124 } 125 126 127 for (int i=0; i<getReferences().size(); i++) 128 { 129 ((Reference) references.get(i)).store(conn); 130 } 131 } 132 133 public static void delete(Connection conn, int docid) throws SQLException 134 { 135 HashMap constraint = new HashMap (); 136 constraint.put("SOURCEDOC_ID", new Integer (docid)); 137 DBUtils.delete(conn, "REFERENCE", constraint); 138 139 constraint.clear(); 140 constraint.put("id", new Integer (docid)); 141 DBUtils.delete(conn, TABLENAME, constraint); 142 } 143 144 public int getId(Connection conn) throws SQLException 145 { 146 if (!idSet) 147 { 148 id = PKManager.getInstance().nextVal(SEQUENCE); 150 idSet = true; 151 } 152 return id; 153 } 154 155 public int getId() 156 { 157 return id; 158 } 159 160 public void setId(int id) 161 { 162 this.id = id; 163 idSet = true; 164 } 165 166 public String getSince() { return since; } 168 public void setSince(String since) 169 { 170 this.since = StringUtils.avoidNull(since); 171 } 172 173 public String getCleanSince() 174 { 175 String since = getSince(); 176 int i = since.indexOf("1."); 179 if (i > -1) 180 return since.substring(i); 181 else 182 return since; 183 } 184 185 186 public String getDeprecated() { return deprecated; } 187 public void setDeprecated(String deprecated) 188 { 189 this.deprecated = StringUtils.avoidNull(deprecated); 190 } 191 192 public String getSummaryDescription() { return summaryDescription; } 193 public void setSummaryDescription(String summaryDescription) 194 { 195 if (StringUtils.isBlank(summaryDescription)) 196 this.summaryDescription = "No description available."; 197 else 198 this.summaryDescription = summaryDescription; 199 } 200 201 public String getDescription() { return description; } 202 public void setDescription(String description) 203 { 204 if (StringUtils.isBlank(description)) 205 this.description = "No description available."; 206 else 207 this.description = description; 208 } 209 210 public int getDocType() { return docType; } 211 public void setDocType(int docType) { this.docType = docType; } 212 213 public String getDocTypeName() 214 { 215 return DOCTYPES[getDocType()-1]; 216 } 217 218 219 public List getReferences() { return references; } 220 public void setReferences(List references) { this.references = references; } 221 222 public void addReferences(SeeTag[] seetags) 223 { 224 Reference ref = null; 225 for (int i=0; i<seetags.length; i++) 226 { 227 ref = new Reference(this, seetags[i]); 228 references.add(ref); 229 } 230 } 231 232 235 public static int getDocType(Doc doc) 236 { 237 if(doc instanceof PackageDoc) 238 { 239 return PACKAGE_TYPE; 240 } 241 else if(doc instanceof ClassDoc) 242 { 243 return CLASS_TYPE; 244 } 245 else if(doc instanceof MemberDoc) 246 { 247 return MEMBER_TYPE; 248 } 249 else 250 { 251 return JDocUtil.UNKNOWN_TYPE; 253 } 254 } 255 256 public boolean hasAnythingToShow() 257 { 258 return (! 259 (StringUtils.isBlank(getSince()) && StringUtils.isBlank(getDeprecated()) && 260 getReferences().isEmpty()) 261 ); 262 } 263 264 public void fetchRefs(Connection conn) throws SQLException 265 { 266 String sql = 267 " select r.label, r.refdoc_name, r.refdoc_type, r.refdoc_id " + 268 " from REFERENCE r " + 269 " where r.sourcedoc_id = ? " + 270 " order by r.label "; 271 272 Logger log = Logger.getInstance(); 273 274 PreparedStatement pstmt = conn.prepareStatement(sql); 275 pstmt.setInt(1, getId()); 276 ResultSet rset = pstmt.executeQuery(); 277 Reference ref; 278 279 while (rset.next()) 280 { 281 ref = new Reference(rset.getString(2)); 282 ref.setLabel(rset.getString(1)); 283 ref.setRefDocType(rset.getInt(3)); 284 ref.getRefDoc().setId(rset.getInt(4)); 285 references.add(ref); 287 log.debug("added a reference to " + ref.getRefDocName()); 288 } 289 290 rset.close(); 291 pstmt.close(); 292 } 293 294 public void fetchRefsOld(Connection conn) throws SQLException 295 { 296 String sql = 297 " select r.label, r.refdoc_name, r.refdoc_type, r.sourcedoc_id, " + 298 " p.id , c.id, m.id, e.id, " + 299 " p.name, c.qualifiedname, m.qualifiedname, e.fullyqualifiedname " + 300 " from REFERENCE r, EXECMEMBER e, MEMBER m, CLASSTYPE c, PACKAGE p " + 301 " where r.sourcedoc_id=? " + 302 " and r.refdoc_name=e.fullyqualifiedname (+) " + 303 " and r.refdoc_name=m.qualifiedname (+) " + 304 " and r.refdoc_name=c.qualifiedname (+) " + 305 " and r.refdoc_name=p.name (+) " + 306 " order by r.label "; 307 308 Logger log = Logger.getInstance(); 309 310 PreparedStatement pstmt = conn.prepareStatement(sql); 311 pstmt.setInt(1, getId()); 312 ResultSet rset = pstmt.executeQuery(); 313 Reference ref; 314 315 while (rset.next()) 316 { 317 ref = new Reference(rset.getString(2)); 318 ref.setLabel(rset.getString(1)); 319 ref.setRefDocType(rset.getInt(3)); 320 ref.getRefDoc().setId(rset.getInt(ref.getRefDocType()+4)); 321 ref.setQualifiedSourceName(rset.getString(ref.getRefDocType()+8)); 322 references.add(ref); 323 log.debug("added a reference to " + ref.getRefDocName()); 324 } 325 326 rset.close(); 327 pstmt.close(); 328 } 329 330 331 public boolean isDeprecated() 332 { 333 return (getDeprecated().trim().length() > 0); 334 } 335 336 public String toString() { return summaryDescription; } 337 338 339 } 340 | Popular Tags |