KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > acl > db > PolicyDBData


1 package de.webman.acl.db;
2
3 import java.sql.ResultSet JavaDoc;
4 import java.sql.SQLException JavaDoc;
5 import com.teamkonzept.db.TKQuery;
6 import de.webman.acl.Policy;
7 import com.teamkonzept.webman.mainint.db.queries.oracle.helper.ConvertBigDecimal;
8
9 /**
10  * $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/db/PolicyDBData.java,v 1.1 2001/08/20 08:25:08 mischa Exp $
11  *
12  * Data container for policies.
13  *
14  * @version 0.10
15  * @since 0.10
16  * @author © 2000 Team-Konzept
17  */

18 public class PolicyDBData
19     extends ObjectDBData
20 {
21
22     // Attributes
23

24     /**
25      * The login field of the data container.
26      */

27     private Integer JavaDoc login = null;
28
29     /**
30      * The role field of the data container.
31      */

32     private Integer JavaDoc role = null;
33
34     /**
35      * The context field of the data container.
36      */

37     private Integer JavaDoc context = null;
38
39     /**
40      * The object type field of the data container.
41      */

42     private Integer JavaDoc type = null;
43
44     /**
45      * The object reference field of the data container.
46      */

47     private Integer JavaDoc reference = null;
48
49     /**
50      * The access field of the data container.
51      */

52     private String JavaDoc access = null;
53
54
55     // Constructors
56

57     /**
58      * Creates a data container for policies.
59      *
60      * @param id the ID of the policy.
61      * @param login the login of the policy.
62      * @param role the role of the policy.
63      * @param context the context of the policy.
64      * @param type the object type of the policy.
65      * @param reference the object reference of the policy.
66      * @param access the access of the policy.
67      */

68     public PolicyDBData (Integer JavaDoc id,
69                            Integer JavaDoc login,
70                            Integer JavaDoc role,
71                            Integer JavaDoc context,
72                            Integer JavaDoc type,
73                            Integer JavaDoc reference,
74                            String JavaDoc access)
75     {
76         super(id);
77
78         this.login = login;
79         this.role = role;
80         this.context = context;
81         this.type = type;
82         this.reference = reference;
83         this.access = access;
84
85         super.setIgnore(true);
86     }
87
88     /**
89      * Creates a data container for policies.
90      *
91      * @param policy the policy.
92      */

93     public PolicyDBData (Policy policy)
94     {
95         super(policy);
96
97         this.login = policy.getLoginID();
98         this.role = policy.getRoleID();
99         this.context = policy.getContextID();
100         this.type = policy.getObjectType();
101         this.reference = policy.getObjectReference();
102         this.access = policy.isAllowed()
103                           ? PolicyDBInterface.MODE_ALLOW
104                           : PolicyDBInterface.MODE_DENY;
105     }
106
107
108     // Method implementations
109

110     /**
111      * Returns the database interface.
112      *
113      * @return the database interface.
114      */

115     public final ObjectDBInterface getDBInterface ()
116     {
117         return PolicyDBInterface.getInstance();
118     }
119
120     /**
121      * Inserts initial data into the given query.
122      * <P>
123      * This method is used for <CODE>INSERT</CODE> statements.
124      *
125      * @param query the query to be executed.
126      * @exception java.sql.SQLException if an database error occured.
127      */

128     public void insertInitialIntoQuery (TKQuery query)
129         throws SQLException JavaDoc
130     {
131         super.insertInitialIntoQuery(query);
132
133         query.setQueryParams(LoginDBInterface.getInstance().getPrimaryKeyName(), this.login);
134         query.setQueryParams(RoleDBInterface.getInstance().getPrimaryKeyName(), this.role);
135         query.setQueryParams(ContextDBInterface.getInstance().getPrimaryKeyName(), this.context);
136         query.setQueryParams("OBJECT_TYPE", this.type);
137         query.setQueryParams("OBJECT_REFERENCE", this.reference);
138         query.setQueryParams("POLICY_ACCESS", this.access);
139     }
140
141     /**
142      * Reads all data from the given result set.
143      * <P>
144      * This method is used for <CODE>SELECT</CODE> and
145      * <CODE>INSERT</CODE> statements.
146      *
147      * @param result the result set to be read.
148      * @exception java.sql.SQLException if an database error occured.
149      */

150     public void fill (ResultSet JavaDoc result)
151         throws SQLException JavaDoc
152     {
153         Object JavaDoc value = null;
154
155         this.login = new Integer JavaDoc(result.getInt(LoginDBInterface.getInstance().getPrimaryKeyName()));
156         this.role = new Integer JavaDoc(result.getInt(RoleDBInterface.getInstance().getPrimaryKeyName()));
157         this.context = new Integer JavaDoc(result.getInt(ContextDBInterface.getInstance().getPrimaryKeyName()));
158
159         value = result.getObject("OBJECT_TYPE");
160         //this.type = value != null ? (Integer) value : null;
161
// NOTE: Oracle's JDBC driver returns a java.math.BigDecimal object
162
this.type = ConvertBigDecimal.getInteger(value);
163
164         value = result.getObject("OBJECT_REFERENCE");
165         //this.reference = value != null ? (Integer) value : null;
166
// NOTE: Oracle's JDBC driver returns a java.math.BigDecimal object
167
this.reference = ConvertBigDecimal.getInteger(value);
168
169         this.access = result.getString("POLICY_ACCESS");
170
171         super.fill(result);
172     }
173
174     /**
175      * Returns the login field of the data container.
176      *
177      * @return the login field of the data container.
178      */

179     public final Integer JavaDoc getLogin ()
180     {
181         return this.login;
182     }
183
184     /**
185      * Returns the role field of the data container.
186      *
187      * @return the role field of the data container.
188      */

189     public final Integer JavaDoc getRole ()
190     {
191         return this.role;
192     }
193
194     /**
195      * Returns the context field of the data container.
196      *
197      * @return the context field of the data container.
198      */

199     public final Integer JavaDoc getContext ()
200     {
201         return this.context;
202     }
203
204     /**
205      * Returns the object type field of the data container.
206      *
207      * @return the object type field of the data container.
208      */

209     public final Integer JavaDoc getObjectType ()
210     {
211         return this.type;
212     }
213
214     /**
215      * Returns the object reference field of the data container.
216      *
217      * @return the object reference field of the data container.
218      */

219     public final Integer JavaDoc getObjectReference ()
220     {
221         return this.reference;
222     }
223
224     /**
225      * Checks wether the data container represents an allowed policy.
226      *
227      * @return <CODE>true</CODE> if the data container represents an allowed policy,
228      * otherwise <CODE>false</CODE>.
229      */

230     public final boolean isAllowed ()
231     {
232         return this.access != null && this.access.equals(PolicyDBInterface.MODE_ALLOW);
233     }
234
235     /**
236      * Checks wether the data container represents a denied policy.
237      *
238      * @return <CODE>true</CODE> if the data container represents a denied policy,
239      * otherwise <CODE>false</CODE>.
240      */

241     public final boolean isDenied ()
242     {
243         return this.access != null && this.access.equals(PolicyDBInterface.MODE_DENY);
244     }
245
246 }
247
Popular Tags