KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > Reference


1 package org.ashkelon;
2 /**
3  * Ashkelon
4  * Copyright UptoData Inc. 2001
5  * March 2001
6  */

7
8 import java.io.Serializable JavaDoc;
9 import java.sql.Connection JavaDoc;
10 import java.sql.SQLException JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Map JavaDoc;
13
14 import org.ashkelon.db.DBUtils;
15 import org.ashkelon.util.Logger;
16 import org.ashkelon.util.StringUtils;
17
18 import com.sun.javadoc.ExecutableMemberDoc;
19 import com.sun.javadoc.SeeTag;
20
21 /**
22  * Part of Persistable javadoc object model
23  * Analog of com.sun.javadoc.SeeTag
24  *
25  * @author Eitan Suez
26  * @version 2.0
27  */

28 public class Reference implements Serializable JavaDoc
29 {
30    private String JavaDoc label;
31    private DocInfo refDoc;
32    private String JavaDoc refDocName;
33    private int refDocType;
34    private DocInfo sourceDoc;
35    private String JavaDoc qualifiedSourceName;
36    
37    
38    private static String JavaDoc TABLENAME = "REFERENCE";
39    
40    public Reference(String JavaDoc refDocName)
41    {
42       setRefDocName(refDocName);
43       setLabel("");
44       setRefDoc(new DocInfo());
45    }
46    
47    public Reference(DocInfo sourceDoc, SeeTag seetag)
48    {
49       Logger log = Logger.getInstance();
50       
51       setSourceDoc(sourceDoc);
52       setLabel(seetag.label());
53       
54       String JavaDoc refDocName = "";
55       int refDocType = 0;
56       
57       if (seetag.referencedMember() == null)
58       {
59          if (seetag.referencedClass() == null)
60          {
61             if (seetag.referencedPackage() != null)
62             {
63                refDocName = seetag.referencedPackage().name();
64                refDocType = DocInfo.PACKAGE_TYPE;
65             }
66          } else
67          {
68             refDocName = seetag.referencedClass().qualifiedName();
69             refDocType = DocInfo.CLASS_TYPE;
70          }
71       } else
72       {
73          refDocName = seetag.referencedMember().qualifiedName();
74          refDocType = DocInfo.MEMBER_TYPE;
75          if (seetag.referencedMember() instanceof ExecutableMemberDoc)
76          {
77             refDocType = DocInfo.EXECMEMBER_TYPE;
78             refDocName += ((ExecutableMemberDoc) seetag.referencedMember()).signature();
79          }
80       }
81       
82       if (StringUtils.isBlank(refDocName))
83       {
84          refDocName = seetag.referencedMemberName();
85          if (StringUtils.isBlank(refDocName))
86          {
87             refDocName = seetag.referencedClassName();
88             if (!StringUtils.isBlank(refDocName))
89             {
90                log.debug("class ref doc name: "+refDocName);
91                refDocType = DocInfo.CLASS_TYPE;
92             }
93          }
94          else
95          {
96             log.debug("member ref doc name: "+refDocName);
97             refDocType = DocInfo.MEMBER_TYPE;
98          }
99       }
100       
101       if(StringUtils.isBlank(refDocName))
102       {
103          refDocName = "";
104          log.debug("still have blank refdocnames!");
105       }
106       
107       setRefDocName(refDocName);
108       setRefDocType(refDocType);
109    }
110    
111    public void store(Connection JavaDoc conn) throws SQLException JavaDoc
112    {
113       Map JavaDoc fieldInfo = new HashMap JavaDoc(5);
114
115       fieldInfo.put("LABEL", StringUtils.truncate(getLabel(), 60));
116       fieldInfo.put("SOURCEDOC_ID", new Integer JavaDoc(getSourceDoc().getId(conn)));
117       fieldInfo.put("REFDOC_NAME", StringUtils.truncate(getRefDocName(), 450));
118       fieldInfo.put("REFDOC_TYPE", new Integer JavaDoc(getRefDocType()));
119       DBUtils.insert(conn, TABLENAME, fieldInfo);
120    }
121    
122    // accessor methods
123
public String JavaDoc getLabel() { return label; }
124    public void setLabel(String JavaDoc label) { this.label = label; }
125    
126    public DocInfo getRefDoc() { return refDoc; }
127    public void setRefDoc(DocInfo refDoc) { this.refDoc = refDoc; }
128    
129    public String JavaDoc getRefDocName() { return refDocName; }
130    public void setRefDocName(String JavaDoc refDocName) { this.refDocName = refDocName; }
131    
132    public DocInfo getSourceDoc() { return sourceDoc; }
133    public void setSourceDoc(DocInfo sourceDoc) { this.sourceDoc = sourceDoc; }
134    
135    public int getRefDocType() { return refDocType; }
136    public void setRefDocType(int refDocType) { this.refDocType = refDocType; }
137
138    public String JavaDoc toString()
139    {
140       return getLabel() + "("+getRefDocName()+")";
141    }
142
143    public String JavaDoc getQualifiedSourceName()
144    {
145       return qualifiedSourceName;
146    }
147    public void setQualifiedSourceName(String JavaDoc qsn)
148    {
149       this.qualifiedSourceName = qsn;
150    }
151    
152 }
153
Popular Tags