KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > pages > ClassPage


1 package org.ashkelon.pages;
2
3 import org.ashkelon.*;
4 import org.ashkelon.util.*;
5 import org.ashkelon.db.*;
6
7 import java.sql.*;
8 import org.apache.oro.util.*;
9
10
11 /**
12  * @author Eitan Suez
13  */

14 public class ClassPage extends Page
15 {
16    public ClassPage()
17    {
18       super();
19    }
20    
21    public String JavaDoc handleRequest() throws SQLException, ClassNotFoundException JavaDoc
22    {
23       int clsId = 0;
24       try
25       {
26          clsId = Integer.parseInt(ServletUtils.getRequestParam(request, "cls_id"));
27       }
28       catch (NumberFormatException JavaDoc ex)
29       {
30          String JavaDoc clsName = ServletUtils.getRequestParam(request, "cls_name");
31          
32          String JavaDoc sql = DBMgr.getInstance().getStatement("getclassid");
33          PreparedStatement pstmt = conn.prepareStatement(sql);
34          pstmt.setString(1, clsName);
35          ResultSet rset = pstmt.executeQuery();
36          if (rset.next())
37             clsId = rset.getInt(1);
38          rset.close();
39          pstmt.close();
40       }
41       
42       Integer JavaDoc clsId_obj = new Integer JavaDoc(clsId);
43
44       
45       Object JavaDoc classCacheObj = app.getAttribute("classCache");
46       CacheLRU classCache = null;
47       if (classCacheObj == null)
48       {
49          classCache = new CacheLRU(1000);
50       }
51       else
52       {
53          classCache = (CacheLRU) classCacheObj;
54          Object JavaDoc clsobject = classCache.getElement(clsId_obj);
55          if (clsobject!=null)
56          {
57             ClassType cls = (ClassType) clsobject;
58             log.brief("retrieving "+cls.getName()+" from cache");
59             request.setAttribute("cls", cls);
60             TreeNode superclasses = cls.getSuperclasses(conn);
61             request.setAttribute("tree", superclasses);
62             return null;
63          }
64       }
65       
66       ClassType cls = ClassType.makeClassFor(conn, clsId, true);
67       
68       classCache.addElement(clsId_obj, cls);
69       app.setAttribute("classCache", classCache);
70
71       request.setAttribute("cls", cls);
72       TreeNode superclasses = cls.getSuperclasses(conn);
73       request.setAttribute("tree", superclasses);
74       return null;
75    }
76    
77 }
78
Popular Tags