Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/data/ejb/disguiserecord/DisguiseRecordData.java


1   /*
2    * DisguiseRecordData.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:28 $ 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.disguiserecord;
12  
13  import java.util.Enumeration;
14  import java.util.Vector;
15  
16  import com.flexstor.common.data.ejb.Data;
17  
18  /**
19   * DisguiseRecordData is a class that Holds the data for a disguise record.
20   *
21   *
22   * @author  Wei Tang
23   * @version 1.0, 05/11/99
24   *
25   * @see     com.flexstor.
26   * @see     com.flexstor.
27   *
28   * @since   FLEXSTOR.db 3.0
29   *
30   * Revision History   Description of Change
31   * ----------------   ---------------------------------------------------
32   * WT     05/11/99   Creation
33   */
34  
35  public class DisguiseRecordData
36  extends Data
37  {
38     //A collection of bucket records at this level, not including the embedded ones
39     protected Vector vBucketRecordData = null;
40  
41     protected int     nDisguiseId;
42     protected boolean bToClassify          = false;
43     protected boolean bAllocRollbackSgmnt  = false; // Defines whether we should explicitly allocate
44                                                     // a rollback segment for this import transaction
45                                                     
46     protected Vector vErrors;
47  
48     public boolean setBucket(DisguiseBucketRecordData[] buckets)
49     {
50        if( buckets != null && buckets.length > 0 )
51        {
52           vBucketRecordData = new Vector();
53           for(int i = 0; i < buckets.length; i++)
54              vBucketRecordData.addElement( buckets[i] );
55  
56           return true;
57        }
58        return false;
59     }
60     
61     public void addBucket(DisguiseBucketRecordData bucket)
62     {
63        if ( vBucketRecordData == null)
64           vBucketRecordData = new Vector();
65           
66        vBucketRecordData.addElement( bucket );
67     }
68  
69     public DisguiseBucketRecordData[] getBuckets()
70     {
71        if ( vBucketRecordData != null && vBucketRecordData.size() > 0 )
72        {
73           DisguiseBucketRecordData[] buckets = new DisguiseBucketRecordData[ vBucketRecordData.size() ];
74           vBucketRecordData.copyInto( buckets );
75           return buckets;
76        }
77        return null;
78     }
79     
80     public Vector getBucketsAsVector()
81     {
82        return vBucketRecordData;
83     }
84  
85     public int getDisguiseId()
86     {
87        return nDisguiseId;
88     }
89  
90     public boolean setDisguiseId(int disguiseId)
91     {
92        nDisguiseId = disguiseId;
93        return true;
94     }
95     
96     public boolean toClassify()
97     {
98        return bToClassify;
99     }
100    
101    public void setToClassify( boolean bToClassify )
102    {
103       this.bToClassify = bToClassify;
104    }
105 
106    public void setAllocateRollBackSegment( boolean bAllocate )
107    {
108       bAllocRollbackSgmnt = bAllocate;
109    }
110 
111    public boolean allocateRollBackSegment()
112    {
113       return bAllocRollbackSgmnt;
114    }
115    
116    /**
117    * Get a list of all assets that matches the role, type and temp/parent flag specified
118    * This method also set the traversal path information for each asset, only if the
119    * record ids are already set, otherwise, callin the getTraversalInfo() in the asset
120    * will return null.
121    */
122    public Vector getAssets( String sAssetRole, String sAssetType, String sAssetFlag )
123    {
124       Vector vAssets = new Vector();
125 
126       if ( vBucketRecordData != null )
127       {
128          Vector vTraversalPath = new Vector();
129          for ( int i = 0; i < vBucketRecordData.size(); i++ )
130          {
131             ((DisguiseBucketRecordData)vBucketRecordData.elementAt(i)).getAssets( vTraversalPath, vAssets, sAssetRole, sAssetType, sAssetFlag );
132          }
133       }
134       return vAssets;
135    }
136    
137    /**
138    * Get a list of all primary assets
139    * This method also returns the traversal path information for each asset, only if the
140    * record ids have been set already, otherwise, calling the getTraversalInfo() in the asset
141    * will return null.
142    */
143    public Vector getPrimaryAssets()
144    {
145       Vector vAssets = new Vector();
146 
147       if ( vBucketRecordData != null )
148          for ( int i = 0; i < vBucketRecordData.size(); i++ )
149             ((DisguiseBucketRecordData)vBucketRecordData.elementAt(i)).getPrimaryAssets( vAssets );
150 
151       return vAssets;
152    }
153 
154    /**
155    * Delete all assets that matches the role, type and temp/parent flag specified
156    */
157    public void deleteAssets( String sAssetRole, String sAssetType, String sAssetFlag )
158    {
159       if ( vBucketRecordData != null )
160       {
161          DisguiseBucketRecordData bucket = null;
162          // Create a shallow clone for scanning and to delete items from the original vector
163          Vector vBucketClone = (Vector) vBucketRecordData.clone();
164          for ( Enumeration e = vBucketClone.elements(); e.hasMoreElements(); )
165          {
166             bucket = (DisguiseBucketRecordData)e.nextElement();
167             if ( bucket.deleteAssets( sAssetRole, sAssetType, sAssetFlag ) )
168                vBucketRecordData.removeElement( bucket );
169          }
170       }
171    }
172    
173    /**
174    * Delete all assets (primary, parents, children) that are represented by the argument asset
175    * @return The number of assets deleted, or zero for none
176    */
177    public int deleteAsset( DisguiseAssetRecordData assetToDelete )
178    {
179       int[] nAssetsDeleted = new int[1]; //An array so we can update its value thru method calls
180       if ( vBucketRecordData != null )
181       {
182          DisguiseBucketRecordData bucket = null;
183          // Create a shallow clone for scanning and to delete items from the original vector
184          Vector vBucketClone = (Vector) vBucketRecordData.clone();
185          for ( Enumeration e = vBucketClone.elements(); e.hasMoreElements(); )
186          {
187             bucket = (DisguiseBucketRecordData)e.nextElement();
188             if ( bucket.deleteAsset( assetToDelete, nAssetsDeleted ) )
189                vBucketRecordData.removeElement( bucket );
190          }
191       }
192       return nAssetsDeleted[0];
193    }
194    
195    /**
196    * Delete all elements that are represented by the argument element.
197    * This call is recursive; it will parse all the tree structure until the desired element is found;
198    * if multiple instances of this element are found, all of them will be removed.
199    * @return The number of elements deleted, or zero for none
200    */
201    public int deleteElement( DisguiseElementRecordData elementToDelete )
202    {
203       int[] nElementsDeleted = new int[1]; // An array so we can update its value thru method calls
204       if ( vBucketRecordData != null )
205       {
206          DisguiseBucketRecordData bucket = null;
207          for ( Enumeration e = vBucketRecordData.elements(); e.hasMoreElements(); )
208          {
209             bucket = (DisguiseBucketRecordData)e.nextElement();
210             bucket.deleteElement( elementToDelete, nElementsDeleted );
211          }
212       }
213       return nElementsDeleted[0];
214    }
215    
216    /**
217    * Delete all buckets that are represented by the argument bucket.
218    * This call is recursive; it will parse all the tree structure until the desired bucket is found;
219    * if multiple instances of this bucket are found, all of them will be removed.
220    * @return The number of buckets deleted, or zero for none
221    */
222    public int deleteBucket( GenericBucketRecordData bucketToDelete )
223    {
224       if ( bucketToDelete instanceof DisguiseElementRecordData )
225          return deleteElement( (DisguiseElementRecordData)bucketToDelete );
226       else
227       {
228          int[] nBucketsDeleted = new int[1]; // An array so we can update its value thru method calls
229          if ( vBucketRecordData != null )
230          {
231             if ( vBucketRecordData.removeElement( bucketToDelete ) )
232                nBucketsDeleted[0] = 1;
233             else
234             {
235                DisguiseBucketRecordData bucket = null;
236                for ( Enumeration e = vBucketRecordData.elements(); e.hasMoreElements(); )
237                {
238                   bucket = (DisguiseBucketRecordData)e.nextElement();
239                   bucket.deleteBucket( (DisguiseBucketRecordData)bucketToDelete, nBucketsDeleted );
240                }
241             }
242          }
243          return nBucketsDeleted[0];
244       }
245    }
246    
247    /**
248     * Add error messages generated by a call to DisguiseRecordPersistBean
249     * The elements of the Vector are Strings of the following format:
250     *    1000,%%1,%%2,%%3
251     * where the first item is the resource id and the next, if any, are arguments 
252     * to be included in the resource
253     */
254    public void setErrors( Vector vErrors ) { this.vErrors = vErrors; }
255    
256    /**
257     * Retrieve any error messages generated by a call to DisguiseRecordPersistBean
258     */
259    public Vector getErrors() { return vErrors; }
260    
261    public synchronized Object cloneData()
262    {
263       DisguiseRecordData clonedObject = new DisguiseRecordData();
264       clonedObject.setDisguiseId( this.getDisguiseId() );
265       clonedObject.setToClassify( this.toClassify() );
266       if ( vBucketRecordData != null )
267       {
268          for ( int i = 0; i < vBucketRecordData.size(); i++ )
269          {
270             DisguiseBucketRecordData aBucket = (DisguiseBucketRecordData) vBucketRecordData.elementAt(i);
271             clonedObject.addBucket( (DisguiseBucketRecordData) aBucket.cloneBucket(true) );
272          }
273       }
274       return clonedObject;
275    }
276 }
277