KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > security > GetMenu


1 package dinamica.security;
2
3 import dinamica.*;
4 import javax.sql.DataSource JavaDoc;
5 import java.sql.*;
6
7 /**
8  * Loads menu titles and menu items. This transaction will
9  * be used by the output module dinamica.security.MenuOutput.
10  * It does provide the menu recordset and a method to retrieve
11  * a menu's items recordset.
12  * <br><br>
13  * (c) 2004 Martin Cordova<br>
14  * This code is released under the LGPL license<br>
15  * Dinamica Framework - http://www.martincordova.com
16  * @author Martin Cordova (dinamica@martincordova.com)
17  * */

18 public class GetMenu extends GenericTransaction
19 {
20
21     /* (non-Javadoc)
22      * @see dinamica.GenericTransaction#service(dinamica.Recordset)
23      */

24     public int service(Recordset inputParams) throws Throwable JavaDoc
25     {
26         int rc = 0;
27         
28         //reuse superclass code
29
super.service(inputParams);
30         
31         //get security datasource
32
String JavaDoc jndiName = (String JavaDoc)getContext().getAttribute("dinamica.security.datasource");
33         if (jndiName==null)
34             throw new Throwable JavaDoc("Context attribute [dinamica.security.datasource] is null, check your security filter configuration.");
35         
36         //get datasource and DB connection
37
DataSource JavaDoc ds = Jndi.getDataSource(jndiName);
38         Connection conn = ds.getConnection();
39         this.setConnection(conn);
40
41         try
42         {
43             
44             //get db channel
45
Db db = getDb();
46             
47             //build sql
48
String JavaDoc sql = getSQL(getResource("query-master.sql"), inputParams);
49             
50             //get menus
51
Recordset menu = db.get(sql);
52             
53             publish("menu", menu);
54             
55         }
56         catch (Throwable JavaDoc e)
57         {
58             throw e;
59         }
60         finally
61         {
62             if (conn!=null)
63                 conn.close();
64         }
65         
66         return rc;
67         
68     }
69
70     public Recordset getMenuItems(Recordset menu) throws Throwable JavaDoc
71     {
72         //get security datasource
73
String JavaDoc jndiName = (String JavaDoc)getContext().getAttribute("dinamica.security.datasource");
74         if (jndiName==null)
75             throw new Throwable JavaDoc("Context attribute [dinamica.security.datasource] is null, check your security filter configuration.");
76         
77         //get datasource and DB connection
78
DataSource JavaDoc ds = Jndi.getDataSource(jndiName);
79         Connection conn = ds.getConnection();
80         this.setConnection(conn);
81
82         try
83         {
84             
85             //get db channel
86
Db db = getDb();
87             
88             //build sql
89
String JavaDoc sql = getSQL(getResource("query-detail.sql"), menu);
90             
91             //get menu items
92
Recordset items = db.get(sql);
93             
94             return items;
95             
96         }
97         catch (Throwable JavaDoc e)
98         {
99             throw e;
100         }
101         finally
102         {
103             if (conn!=null)
104                 conn.close();
105         }
106         
107     }
108
109 }
110
Popular Tags