KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > ExecMember


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

7
8 import java.sql.Connection JavaDoc;
9 import java.sql.PreparedStatement JavaDoc;
10 import java.sql.ResultSet JavaDoc;
11 import java.sql.SQLException JavaDoc;
12 import java.util.ArrayList JavaDoc;
13 import java.util.Comparator JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Map JavaDoc;
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 /**
29  * Part of Persistable javadoc object model known as ashkelon
30  * Analog of com.sun.javadoc.ExecutableMemberDoc
31  *
32  * @author Eitan Suez
33  * @version 2.0
34  */

35 public class ExecMember extends Member implements Comparator JavaDoc
36 {
37    private boolean isSynchronized;
38    private boolean isNative;
39    private List JavaDoc thrownExceptions;
40    private String JavaDoc fullyQualifiedName;
41    private String JavaDoc signature;
42    private List JavaDoc parameters;
43    
44    private static String JavaDoc TABLENAME = "EXECMEMBER";
45
46    
47    public ExecMember(String JavaDoc qualifiedName, String JavaDoc signature, int memberType)
48    {
49       super(qualifiedName, memberType);
50       setSignature(signature);
51       setFullyQualifiedName(qualifiedName+signature);
52       setThrownExceptions(new ArrayList JavaDoc());
53       setParameters(new ArrayList JavaDoc());
54    }
55    
56    public ExecMember(Member member, String JavaDoc signature)
57    {
58       super(member);
59       setThrownExceptions(new ArrayList JavaDoc());
60       setParameters(new ArrayList JavaDoc());
61       setSignature(signature);
62    }
63    
64    public ExecMember(ExecutableMemberDoc exmemdoc, ClassType containingClass)
65    {
66       super(exmemdoc, containingClass);
67       parameters = new ArrayList JavaDoc();
68       thrownExceptions = new ArrayList JavaDoc();
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 JavaDoc conn) throws SQLException JavaDoc
79    {
80       super.store(conn);
81       Map JavaDoc fieldInfo = new HashMap JavaDoc(10);
82       fieldInfo.put("ID", new Integer JavaDoc(getId(conn)));
83       
84       //fieldInfo.put("ISSYNCHRONIZED", new Boolean(isSynchronized()));
85
int boolvalue = isSynchronized() ? 1 : 0;
86       fieldInfo.put("ISSYNCHRONIZED", new Integer JavaDoc(boolvalue));
87       
88       //fieldInfo.put("ISNATIVE", new Boolean(isNative()));
89
boolvalue = isNative() ? 1 : 0;
90       fieldInfo.put("ISNATIVE", new Integer JavaDoc(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 JavaDoc conn, int memberid, int docid) throws SQLException JavaDoc
108    {
109       deleteThrownExceptions(conn, memberid);
110       deleteParameters(conn, memberid);
111       
112       Map JavaDoc constraint = new HashMap JavaDoc();
113       constraint.put("ID", new Integer JavaDoc(memberid));
114       DBUtils.delete(conn, TABLENAME, constraint);
115
116       Member.delete(conn, memberid, docid);
117    }
118    
119    public static void deleteThrownExceptions(Connection JavaDoc conn, int memberid) throws SQLException JavaDoc
120    {
121       Map JavaDoc constraint = new HashMap JavaDoc();
122       constraint.put("throwerid", new Integer JavaDoc(memberid));
123       DBUtils.delete(conn, "THROWNEXCEPTION", constraint);
124    }
125     
126    public static void deleteParameters(Connection JavaDoc conn, int memberid) throws SQLException JavaDoc
127    {
128       Map JavaDoc constraint = new HashMap JavaDoc();
129       constraint.put("execmemberid", new Integer JavaDoc(memberid));
130       DBUtils.delete(conn, "PARAMETER", constraint);
131    }
132
133    // accessor methods:
134
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 JavaDoc getFullyQualifiedName(){ return fullyQualifiedName; }
141    public void setFullyQualifiedName(String JavaDoc fullyQualifiedName){ this.fullyQualifiedName = fullyQualifiedName; }
142    
143    public String JavaDoc getSignature(){ return signature; }
144    public void setSignature(String JavaDoc signature){ this.signature = signature; }
145    
146    public List JavaDoc getParameters() { return parameters; }
147    public void setParameters(List JavaDoc parameters) { this.parameters = parameters; }
148    
149    public void addParameters(Parameter[] parameters, ParamTag[] tags)
150    {
151       Map JavaDoc paramMap = JDocUtil.makeParamMap(getDoc(), tags);
152       String JavaDoc 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 JavaDoc) 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 JavaDoc getThrownExceptions() { return thrownExceptions; }
176    public void setThrownExceptions(List JavaDoc thrownExceptions) { this.thrownExceptions = thrownExceptions; }
177    
178    public void addThrownExceptions(ClassDoc[] exceptions, ThrowsTag[] throwsTags)
179    {
180       String JavaDoc 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 = throwsTags[j].exceptionComment();
190
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 JavaDoc first, Object JavaDoc 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 JavaDoc conn) throws SQLException JavaDoc
221    {
222       
223       String JavaDoc 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 JavaDoc pstmt = conn.prepareStatement(sql);
231       pstmt.setInt(1, getId());
232       ResultSet JavaDoc 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) // i.e. not a primitive and internally referenceable
245
{
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 JavaDoc conn) throws SQLException JavaDoc
257    {
258       String JavaDoc 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 JavaDoc pstmt = conn.prepareStatement(sql);
265       pstmt.setInt(1, getId());
266       ResultSet JavaDoc 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) // i.e. not a primitive and internally referenceable
275
{
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