Source code: com/flexstor/ejb/disguise/persist/ServerDisguiseExtendData.java
1 /*
2 * ServerDisguiseExtendData.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:43 $ 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.ejb.disguise.persist;
12
13 import java.util.Enumeration;
14 import java.util.Vector;
15
16 import com.flexstor.common.constants.BucketConstantsI;
17 import com.flexstor.common.data.ejb.Data;
18 import com.flexstor.ejb.bucket.persist.ServerBucketExtendData;
19
20
21
22 /**
23 * This is the dataobject used to retrieve information
24 * for a particular ServerDisguiseExtend. It is used exclusively
25 * by the client.
26 *
27 * This object is normally created by the Bean after
28 * a user request.
29 *
30 * @author Daniel Nickel
31 * @version 1.0, 04/19/99
32 *
33 */
34
35 public class ServerDisguiseExtendData
36 extends Data
37 {
38
39 public final static String IDENTIFIER="$Id: ServerDisguiseExtendData.java,v 1.3 2003/08/11 02:22:43 aleric Exp $";
40
41 // User defined label for the Disguise
42 protected String label = null;
43
44 // This is an Instance of the application data or Reference Key
45 protected String appName = null;
46
47 protected boolean bLoad = false;
48
49 protected boolean classify = false;
50
51 protected String container = null;
52
53 // ID of the disguise
54 protected int id = 0;
55
56 // Disguise Bucket Objects
57 protected Vector disguiseBuckets = null;
58
59 protected boolean bElement = false;
60
61 protected boolean bAsset = false;
62
63 // Defines wether this disguise is a lookup disguise or not
64 protected boolean bIsLookup;
65
66 /**
67 * Constructor : Create an Empty Disguise Data Object
68 *
69 */
70
71 public ServerDisguiseExtendData()
72 {
73 super();
74 }
75 /**
76 * Retrieve the Application Name for this Disguise
77 *
78 * @return java.lang.String
79 */
80
81 public String getAppName()
82 {
83 return appName;
84 }
85 /**
86 * Returns a collection of DisguiseBuckets
87 * for this disguise.
88 *
89 * @return java.util.Vector List of ServerBucketExtendData Objects
90 */
91 public Vector getBucketDataObjects()
92 {
93 return disguiseBuckets;
94 }
95 /**
96 * This accepts a bucket id and returns a list of
97 * ServerFieldExtendData Objects
98 */
99 public Enumeration getBucketFields( int id )
100 {
101 if ( disguiseBuckets == null )
102 return null;
103
104 for ( int i=0; i<disguiseBuckets.size() ; i++ )
105 {
106 ServerBucketExtendData dat = ( ServerBucketExtendData ) disguiseBuckets.elementAt( i );
107
108 if ( dat.getId() == id )
109 return ( dat.getFieldDataObjects() != null ) ? dat.getFieldDataObjects().elements() : null;
110 }
111
112 return null;
113 }
114
115 /**
116 * This accepts a bucket name and returns a list of
117 * ServerFieldExtendData Objects. This bucket name
118 * is the application bucket name.
119 */
120 public Enumeration getBucketFields( String bucketName )
121 {
122 if ( disguiseBuckets == null )
123 return null;
124
125 for ( int i=0; i<disguiseBuckets.size() ; i++ )
126 {
127 ServerBucketExtendData dat = ( ServerBucketExtendData ) disguiseBuckets.elementAt( i );
128
129 if ( dat.getBucketName().equalsIgnoreCase( bucketName ) )
130 return ( dat.getFieldDataObjects() != null ) ? dat.getFieldDataObjects().elements() : null;
131 }
132
133 return null;
134 }
135
136 /**
137 * This accepts a bucket id and returns a bucket name
138 */
139 public String getBucketName( int id )
140 {
141 if ( disguiseBuckets == null )
142 return null;
143
144 for ( int i=0; i<disguiseBuckets.size() ; i++ )
145 {
146 ServerBucketExtendData dat = ( ServerBucketExtendData ) disguiseBuckets.elementAt( i );
147
148 if ( dat.getId() == id )
149 return dat.getBucketName();
150 }
151
152 return null;
153 }
154
155 /**
156 * This accepts a bucket name and returns a bucket id
157 */
158 public int getBucketId( String sBucketName )
159 {
160 if ( disguiseBuckets == null )
161 return -1;
162
163 for ( int i = 0; i < disguiseBuckets.size() ; i++ )
164 {
165 ServerBucketExtendData dat = ( ServerBucketExtendData ) disguiseBuckets.elementAt( i );
166
167 if ( dat.getBucketName().equals(sBucketName) )
168 return dat.getId();
169 }
170
171 return -1;
172 }
173
174 /**
175 * This accepts a bucket id and returns a bucket name
176 */
177 public ServerBucketExtendData getServerBucketExtendDataObject( int id )
178 {
179 if ( disguiseBuckets == null )
180 return null;
181
182 for ( int i=0; i<disguiseBuckets.size() ; i++ )
183 {
184 ServerBucketExtendData dat = ( ServerBucketExtendData ) disguiseBuckets.elementAt( i );
185
186 if ( dat.getId() == id )
187 return dat;
188 }
189
190 return null;
191 }
192
193 /**
194 * Returns the container name for this disguise
195 *
196 */
197
198 public String getContainer()
199 {
200 return container;
201 }
202 /**
203 * Retrieve the Identifier for this Disguise.
204 *
205 * @return int The id for this disguise
206 */
207
208 public int getId()
209 {
210 return id;
211 }
212 /**
213 * Retrieve the label for the disguise.
214 *
215 * @return java.lang.String
216 */
217
218 public String getLabel()
219 {
220 return label;
221 }
222 /**
223 * This tells if a disguise has an Asset bucket
224 *
225 * @return boolean - true if has Asset bucket
226 */
227 public boolean hasAsset()
228 {
229 return bAsset;
230 }
231 /**
232 * This tells if a disguise has an element bucket
233 *
234 * @return boolean - true if has element bucket
235 */
236 public boolean hasElement()
237 {
238 return bElement;
239 }
240 /**
241 * Is this a classified disguise
242 *
243 * @return true if we load everything on startup
244 * <br> false if we do not load everything
245 */
246
247 public boolean isClassify()
248 {
249 return classify;
250 }
251 /**
252 * This is a helper function that will
253 * take the display fields and order them
254 * by position. It uses a bubble sort algorithm
255 * which is slow for large Vectors, but should be
256 * acceptable because of the small number of
257 * displayable fields for a layout.
258 *
259 * @return boolean
260 * @since FlexDB 3.0
261 * @see com.flexstor.ejb.dataobject.DisplayFieldData
262 */
263 public boolean orderBuckets()
264 {
265 int iVectorLen = 0;
266
267 if ( disguiseBuckets == null )
268 return true;
269
270 iVectorLen = disguiseBuckets.size();
271
272 for ( int iPos1 = 0; iPos1 < iVectorLen ; iPos1++ )
273 {
274 int iPos2;
275
276 for ( iPos2 = iPos1 + 1 ; iPos2 < iVectorLen ; iPos2++ )
277 {
278 ServerBucketExtendData dis1 = (ServerBucketExtendData) disguiseBuckets.elementAt(iPos1);
279 ServerBucketExtendData dis2 = (ServerBucketExtendData) disguiseBuckets.elementAt(iPos2);
280
281 if ( dis1.getBucketType() > dis2.getBucketType() )
282 {
283 disguiseBuckets.setElementAt( dis2 , iPos1 );
284 disguiseBuckets.setElementAt( dis1 , iPos2 );
285 continue;
286 }
287
288
289
290 }
291
292 iVectorLen = disguiseBuckets.size();
293
294 for ( iPos2 = iPos1 + 1 ; iPos2 < iVectorLen ; iPos2++ )
295 {
296 ServerBucketExtendData dis1 = (ServerBucketExtendData) disguiseBuckets.elementAt(iPos1);
297 ServerBucketExtendData dis2 = (ServerBucketExtendData) disguiseBuckets.elementAt(iPos2);
298
299 if ( dis1.getLevel() > dis2.getLevel() &&
300 dis2.getBucketType() != BucketConstantsI.ELEMENT_BUCKET &&
301 dis2.getBucketType() != BucketConstantsI.ASSET_BUCKET &&
302 dis2.getBucketType() != BucketConstantsI.ASSET_ROLE_BUCKET )
303 {
304 disguiseBuckets.setElementAt( dis2 , iPos1 );
305 disguiseBuckets.setElementAt( dis1 , iPos2 );
306 continue;
307 }
308
309
310
311 }
312 }
313
314 return true;
315 }
316 /**
317 * Retrieve the Application Name for this Disguise
318 *
319 * @param java.lang.String - name of app
320 */
321
322 public void setAppName( String app )
323 {
324 appName = app;
325 }
326 /**
327 * This tells if a disguise has an Asset bucket
328 *
329 * @param boolean - true if has Asset bucket
330 */
331 public void setAsset( boolean b )
332 {
333 bAsset = b;
334 }
335 /**
336 * Returns a collection of DisguiseBuckets
337 * for this disguise.
338 *
339 * @param java.util.Vector List of ServerBucketExtendData Objects
340 */
341 public void setBucketDataObjects( Vector v )
342 {
343 disguiseBuckets = v;
344 }
345 /**
346 * Set Classify
347 *
348 * @param String - Y/N
349 */
350
351 public void setClassify( String classify )
352 {
353 // If null don't modify state
354 if ( classify == null )
355 return;
356
357 if ((classify.toLowerCase().getBytes())[0] == 'y')
358 this.classify = true;
359 else
360 this.classify = false;
361
362 return;
363 }
364 /**
365 * Sets the container name for this disguise
366 *
367 * @param String - container name
368 */
369
370 public void setContainer( String cont )
371 {
372 container = cont;
373 }
374 /**
375 * This tells if a disguise has an element bucket
376 *
377 * @param boolean - true if has element bucket
378 */
379 public void setElement( boolean b )
380 {
381 bElement = b;
382 }
383 /**
384 * Retrieve the Identifier for this Disguise.
385 *
386 * @param int The id for this disguise
387 */
388
389 public void setId( int id )
390 {
391 this.id = id;
392 }
393 /**
394 * Set the label for the disguise.
395 *
396 * @return java.lang.String
397 */
398
399 public void setLabel( String label )
400 {
401 this.label = label;
402 }
403
404 /**
405 * Defines if this disguise is a lookup disguise or not.
406 * This value is extracted from the disguise properties
407 * in the database.
408 */
409 public void setIsLookup( boolean bValue )
410 {
411 this.bIsLookup = bValue;
412 }
413
414 /**
415 * Returns true if this is a lookup disguise
416 */
417 public boolean isLookup()
418 {
419 return bIsLookup;
420 }
421 }