Source code: com/flexstor/common/data/ejb/disguise/DisguiseDataBuild.java
1 /*
2 * DisguiseDataBuild.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:35 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.common.data.ejb.disguise;
12
13 import java.util.Vector;
14
15 import com.flexstor.common.data.ejb.disguise.bucket.DisguiseBucketData;
16 import com.flexstor.common.data.ejb.display.DisplayData;
17 import com.flexstor.common.data.ejb.exporttemplate.ExportTemplateData;
18 import com.flexstor.common.data.ejb.reporttemplate.ReportTemplateData;
19 import com.flexstor.common.keys.ejb.ApplicationKey;
20 import com.flexstor.common.keys.ejb.DisguiseKey;
21
22 /**
23 * This interface defines a Disguise of the FLEXSTOR.db system. <br>
24 * An instance of Disguise is accessed by the client to retrieve all of the user information. <br>
25 *
26 *
27 * <p>
28 * <b>Developer Notes:</b><br>
29 * <ul>
30 * <li>There will be a MaintenanceBean for adding, deleting, and updating
31 * Disguise objects to the database.
32 * <li>A User will request a Disguise Object by the Identifier
33 * </ul>
34 *
35 * @author Daniel Nickel
36 * @version 1.0, 10/19/98
37 *
38 * @see com.flexstor.ejb.disguise.DisguiseBean
39 *
40 * @since FLEXSTOR.db 3.0
41 *
42 */
43
44 public class DisguiseDataBuild
45 extends DisguiseData
46 {
47
48 final static String IDENTIFIER="$Id: DisguiseDataBuild.java,v 1.4 2003/08/11 02:22:35 aleric Exp $";
49 static final long serialVersionUID = 9061875223642836883L;
50
51 /**
52 * Constructor
53 *
54 */
55
56 public DisguiseDataBuild()
57 {
58 super();
59 }
60
61 /**
62 * Constructor
63 *
64 * @param name Name of Disguise Object
65 */
66
67 public DisguiseDataBuild(String name)
68 {
69 super();
70 label = name;
71 }
72
73 /**
74 * Set the ID for the application
75 *
76 * @param Id Id of Disguise Object
77 */
78
79 public void setId(int Id)
80 {
81 id = Id;
82 }
83
84 /**
85 * This will add a Display Object to collection
86 *
87 * @param disDat This is a DisplayData Object
88 * @see com.flexstor.ejb.dataobject.DisplayData
89 */
90
91 public void addDisplayDataObject(DisplayData disDat)
92 {
93 if (displays == null)
94 displays = new Vector();
95
96 displays.addElement(disDat);
97
98 }
99
100
101 /**
102 * This will set a DisplayData Collection
103 *
104 * @param disDat This is a vector of DisplayData Objects
105 */
106
107 public void setDisplayDataObjects(Vector disDat)
108 {
109 displays = disDat;
110 }
111
112 /**
113 * This will set an ApplicationKey associated with a disguise
114 *
115 * @param appDat ApplicationData Object
116 * @see com.flexstor.ejb.dataobject.ApplicationData
117 */
118
119 public void setApplicationKey(ApplicationKey appDat)
120 {
121 appKey = appDat;
122 }
123
124
125 /**
126 * This will set an Application Name associated with a disguise
127 *
128 * @param appDat String Application Name
129 */
130
131 public void setAppName(String appDat)
132 {
133 appName = appDat;
134 }
135
136 /**
137 * Set disguise to a valid state
138 * This always returns true for now. (Not Implemented)
139 * @param boolean True/False depending on validity
140 */
141
142 public void setValid(boolean disVal)
143 {
144 valid = disVal;
145 }
146
147 /**
148 * This will validate a disguise based on the following
149 * criteria:<br>
150 * <br>
151 * Does the DisplayField names match the Field name they reference??
152 *
153 * @return True/False Validation Result
154 */
155 public boolean validateDisguise()
156 {
157 boolean val = true;
158
159 // Need to put criteria To_Be_Implemented
160 setValid(val);
161
162 return val;
163 }
164
165 /**
166 * This will set Privilege Object for a disguise
167 *
168 * @param Vector - List of PrivAssetData
169 * @see com.flexstor.ejb.dataobject.PrivAssetData
170 */
171
172 public void setPrivilegeDataObjects(Vector privDat)
173 {
174 privileges = privDat;
175 }
176
177
178 /**
179 * This will set whether to Load All Classes for this disguise
180 * or just references. At the moment it will only load references.
181 *
182 * @param com.flexstor.ejb.dataobject.PrivilegeData Privilege Data
183 * @see com.flexstor.ejb.dataobject.PrivilegeData
184 */
185
186 public void setLoad(String load)
187 {
188 if ((load.toLowerCase().getBytes())[0] == 'y')
189 bLoad = true;
190 else
191 bLoad = false;
192 }
193
194 /**
195 * Add a report template object to collection
196 * @param datDat This is a ReportData Object
197 * @see com.flexstor.ejb.dataobject.ReportData
198 */
199
200 public void addReportObject(ReportTemplateData datDat)
201 {
202 if (reports == null)
203 reports = new Vector();
204
205 reports.addElement(datDat);
206 }
207
208
209 /**
210 * Set ReportTemplate Vector collection
211 *
212 * @param datDat A Vector of Report Templates (ReportTemplateData)
213 * @see java.util.Vector
214 */
215
216 public void setReportDataObjects(Vector datDat)
217 {
218 reports = datDat;
219 }
220
221 /**
222 * Add Export Template to collection
223 *
224 * @param ex This is an ExportTemplateData Object
225 * @see com.flexstor.ejb.dataobject.ExportTemplateData
226 */
227
228 public void addExportObject(ExportTemplateData ex)
229 {
230 if (exports == null)
231 exports = new Vector();
232
233 exports.addElement(ex);
234 }
235
236 /**
237 * sets a collection of Keys to Export Templates
238 *
239 * @param ex This is a Vector of ExportTemplateData Objects
240 * @see com.flexstor.ejb.dataobject.ExportTemplateData
241 */
242
243 public void setExportDataObjects(Vector ex)
244 {
245 exports = ex;
246 }
247
248 /**
249 * sets a collection of DisguiseBucketDataObjects
250 *
251 * @param list This is a Vector of DisguiseBucketData Objects
252 * @see com.flexstor.ejb.dataobject.DisguiseBucketData
253 */
254 public void setDisguiseBucketDataObjects( Vector buckThisList )
255 {
256 disguiseBuckets = buckThisList;
257 }
258
259 /**
260 * sets a collection of Keys to Export Templates
261 *
262 * @param ex This is a Vector of ExportTemplateData Objects
263 * @see com.flexstor.ejb.dataobject.ExportTemplateData
264 */
265
266 public void setKey(DisguiseKey key)
267 {
268 this.key = key;
269 }
270
271 /**
272 * Set the label for the Disguise. This can be modified
273 * by a client, but in order to be persisted has to be
274 * passed to the update method in the bean.
275 *
276 * @param sLabel java.lang.String user's Disguise Name
277 * @return True if label set successfully <br>
278 * False if couldn't set Label
279 * @see java.lang.String
280 */
281
282 public void setName(String sLabel)
283 {
284 label = sLabel;
285 }
286
287
288 /**
289 * This is a helper function that will
290 * take the display fields and order them
291 * by position. It uses a bubble sort algorithm
292 * which is slow for large Vectors, but should be
293 * acceptable because of the small number of
294 * displayable fields for a layout.
295 *
296 * @return boolean
297 * @since FlexDB 3.0
298 * @see com.flexstor.ejb.dataobject.DisplayFieldData
299 */
300 public boolean orderBuckets()
301 {
302 int iVectorLen = 0;
303
304 if ( disguiseBuckets == null )
305 return true;
306
307 iVectorLen = disguiseBuckets.size();
308
309 for ( int iPos1 = 0; iPos1 < iVectorLen ; iPos1++ )
310 {
311 int iPos2;
312
313 /* for ( iPos2 = iPos1 + 1 ; iPos2 < iVectorLen ; iPos2++ )
314 {
315 DisguiseBucketData dis1 = (DisguiseBucketData) disguiseBuckets.elementAt(iPos1);
316 DisguiseBucketData dis2 = (DisguiseBucketData) disguiseBuckets.elementAt(iPos2);
317
318 if ( dis1.getBucketType() > dis2.getBucketType() )
319 {
320 disguiseBuckets.setElementAt( dis2 , iPos1 );
321 disguiseBuckets.setElementAt( dis1 , iPos2 );
322 continue;
323 }
324
325
326
327 }
328 */
329 iVectorLen = disguiseBuckets.size();
330
331 for ( iPos2 = iPos1 + 1 ; iPos2 < iVectorLen ; iPos2++ )
332 {
333 DisguiseBucketData dis1 = (DisguiseBucketData) disguiseBuckets.elementAt(iPos1);
334 DisguiseBucketData dis2 = (DisguiseBucketData) disguiseBuckets.elementAt(iPos2);
335
336 if ( dis1.getLevel() > dis2.getLevel() )// &&
337 // dis1.getBucketType() != BucketConstantsI.ELEMENT_BUCKET &&
338 // dis2.getBucketType() != BucketConstantsI.ASSET_BUCKET &&
339 // dis2.getBucketType() != BucketConstantsI.ASSET_ROLE_BUCKET )
340 {
341 disguiseBuckets.setElementAt( dis2 , iPos1 );
342 disguiseBuckets.setElementAt( dis1 , iPos2 );
343 }
344
345 }
346 }
347
348 return true;
349 }
350
351
352 /**
353 * Set the classify flag true or false based upon
354 * the first byte of a String 'Y' or 'N'.
355 *
356 * @param classify whether object is classified
357 *
358 */
359 public boolean setClassify( String classify )
360 {
361 // If null don't modify state
362 if ( classify == null )
363 return false;
364
365 if ((classify.toLowerCase().getBytes())[0] == 'y')
366 this.classify = true;
367 else
368 this.classify = false;
369
370 return true;
371 }
372
373 /**
374 * This will set a list of properties.
375 *
376 */
377 public void setPropertyDataObjects( Vector props )
378 {
379 properties = props;
380 }
381 }