KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sessionsystem > SessionSQL


1 package com.daffodilwoods.daffodildb.server.sessionsystem;
2
3 import java.util.TimeZone JavaDoc;
4 import com.daffodilwoods.database.resource.*;
5 import com.daffodilwoods.daffodildb.server.serversystem.*;
6 import java.util.Stack JavaDoc;
7 import java.util.ArrayList JavaDoc;
8 import java.sql.*;
9 import java.io.Serializable JavaDoc;
10 public class SessionSQL implements Serializable JavaDoc {
11   Stack JavaDoc authorisationStack;
12   SessionTransactionMode transactionMode;
13   transient DateTimeFunctions dateTime;
14   public SessionSQL() throws DException {
15     authorisationStack = new Stack JavaDoc();
16     dateTime = new DateTimeFunctions();
17   }
18
19   /**
20    * adds the user to authorisationStack.
21    * @param athrznIdntfr
22    * @throws DException
23    */

24
25   public void pushAuthorizationIdentifier(AuthorizationIdentifier athrznIdntfr) throws DException {
26     authorisationStack.push(athrznIdntfr);
27   }
28
29   /**
30    * sets the role for the user in authorisationStack.
31    * @param role
32    * @throws DException
33    */

34
35   public void setRole(String JavaDoc role) throws DException {
36     AuthorizationIdentifier authrztnIdntfr = (AuthorizationIdentifier)authorisationStack.peek();
37     authrztnIdntfr.setRole(role);
38   }
39
40   /**
41    * Authorises a user name from authorisationStack.
42    * @param user
43    * @throws DException
44    */

45
46   public void setUser(String JavaDoc user) throws DException {
47     AuthorizationIdentifier authrztnIdntfr = (AuthorizationIdentifier)authorisationStack.peek();
48     authrztnIdntfr.setUser(user);
49   }
50
51   /**
52    * returns true if the user exists in the authorisationStack.
53    * @param authorizationIdentifier
54    * @param globalSession
55    * @return boolean
56    * @throws DException
57    */

58
59   public boolean isEnabledAuthorizationIdentifier(String JavaDoc authorizationIdentifier, _ServerSession globalSession) throws DException{
60     AuthorizationIdentifier authrztnIdntfr = (AuthorizationIdentifier)authorisationStack.peek();
61     ArrayList JavaDoc s = authrztnIdntfr.getEnabledAuthorizationIdentifiers( globalSession );
62     for (int i = 0; i < s.size(); i++) {
63        if( authorizationIdentifier.equalsIgnoreCase((String JavaDoc)s.get(i)) )
64           return true;
65     }
66     return false;
67   }
68
69   /**
70    * returns the current AuthorizationIdentifier from the authorisationStack.
71    * @return String
72    * @throws DException
73    */

74
75   public String JavaDoc getAuthorizationIdentifier() throws DException {
76     AuthorizationIdentifier authrztnIdntfr = (AuthorizationIdentifier)authorisationStack.peek();
77     return authrztnIdntfr.getCurrentAuthorizationIdentifier();
78   }
79
80   /**
81    * returns the role for the user
82    * @return String
83    * @throws DException
84    */

85
86   public String JavaDoc getCurrentRole() throws DException {
87     AuthorizationIdentifier authrztnIdntfr = (AuthorizationIdentifier)authorisationStack.peek();
88     return authrztnIdntfr.getRole();
89   }
90
91   /**
92    * returns the user from authorisationStack
93    * @return String
94    * @throws DException
95    */

96
97   public String JavaDoc getCurrentUser() throws DException {
98     AuthorizationIdentifier authrztnIdntfr = (AuthorizationIdentifier)authorisationStack.peek();
99     return authrztnIdntfr.getUser();
100   }
101
102   /**
103    * Sets the transaction mode for session.
104    * @param transactinMode
105    * @throws DException
106    */

107
108   public void setTransactionMode(SessionTransactionMode transactinMode) throws DException {
109     this.transactionMode = transactinMode;
110   }
111
112   /**
113    * retrives the transaction mode for the session.
114    * @return SessionTransactionMode
115    * @throws DException
116    */

117
118   public SessionTransactionMode getTransactionMode() throws DException {
119     return transactionMode;
120    }
121
122    /**
123     * returns the current Date.
124     * @return Date
125     * @throws DException
126     */

127
128    public Date getDate() throws DException {
129      return dateTime.getDate();
130    }
131
132    /**
133     * returns the current time.
134     * @return Time
135     * @throws DException
136     */

137
138    public Time getTime() throws DException {
139      return dateTime.getTime();
140    }
141
142    /**
143     * returns the current Month.
144     * @return int
145     * @throws DException
146     */

147
148    public int getMonth() throws DException {
149      dateTime.setCurrentTime();
150      return dateTime.getMonth();
151    }
152
153    /**
154     * returns the current Year.
155     * @return int
156     * @throws DException
157     */

158
159    public int getYear() throws DException {
160      dateTime.setCurrentTime();
161      return dateTime.getYear();
162    }
163
164    /**
165     * returns the current hour.
166     * @return int
167     * @throws DException
168     */

169
170    public int getHour() throws DException {
171      dateTime.setCurrentTime();
172      return dateTime.getHour();
173    }
174
175    /**
176     * returns the current minutes
177     * @return int
178     * @throws DException
179     */

180
181   public int getMinutes() throws DException {
182     dateTime.setCurrentTime();
183     return dateTime.getMinutes();
184   }
185
186   /**
187    * returns the current second.
188    * @return int
189    * @throws DException
190    */

191
192   public int getSeconds() throws DException {
193     dateTime.setCurrentTime();
194     return dateTime.getSeconds();
195   }
196
197   /**
198    * returns the Time zone set.
199    * @return Time Zone
200    * @throws DException
201    */

202
203   public TimeZone JavaDoc getTimeZone() throws DException {
204     return TimeZone.getDefault();
205   }
206
207   /**
208    * return sthe currnet Time Stamp.
209    * @return TimeStamp
210    * @throws DException
211    */

212
213   public java.sql.Timestamp JavaDoc getTimeStamp( ) throws DException {
214     return dateTime.getTimeStamp();
215   }
216   public void resetTransactionDate(){
217   dateTime.resetTransactionDate();
218  }
219
220 }
221
Popular Tags