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/DisguiseElementRecordData.java


1   /*
2    * DisguiseElementRecordData.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.Vector;
14  
15  /**
16   * DisguiseElementRecordData is a class that encapsulates
17   * data for the initialization of PreIdxService.
18   *
19   *
20   * @author  Wei Tang
21   * @version 1.0, 05/11/99
22   *
23   * @see     com.flexstor.
24   * @see     com.flexstor.
25   *
26   * @since   FLEXSTOR.db 3.0
27   *
28   * Revision History   Description of Change
29   * ----------------   ---------------------------------------------------
30   * WT     05/11/99   Creation
31   */
32  
33  public class DisguiseElementRecordData
34  extends GenericBucketRecordData
35  {
36     protected DisguiseAssetRecordData parentAsset = null;
37      static final long serialVersionUID = 1189743995201545969L;
38      
39     public DisguiseAssetRecordData getParentAsset()
40     {
41        return parentAsset;
42     }
43  
44     public boolean setParentAsset(DisguiseAssetRecordData parent)
45     {
46        this.parentAsset = parent;
47        return true;
48     }
49         
50     public void getAssets( Vector vAssets, String sRole, String sType, String sFlag )
51     {
52        getAssets( null, vAssets, sRole, sType, sFlag );
53     }
54  
55     void getAssets( Vector vTraversalPath, Vector vAssets, String sRole, String sType, String sFlag )
56     {
57        if ( parentAsset != null )
58        {
59           // Attempt to update the information for the traversal path, only if the vTraversalPath isn't null
60           // and the record id exists.
61           if ( vTraversalPath != null )
62              vTraversalPath.addElement( this );
63  
64           parentAsset.getAssets( vTraversalPath, vAssets, sRole, sType, sFlag );
65  
66           // Remove the traveral item corresponding to this bucket.
67           if ( vTraversalPath != null )
68              vTraversalPath.removeElement( vTraversalPath.lastElement() );
69        }
70     }
71  
72     public void getPrimaryAssets( Vector vAssets )
73     {
74        if ( parentAsset != null )
75           vAssets.addElement ( parentAsset );
76     }
77  
78     /**
79     * If the role and type of the primary asset don't match the arguments, return true
80     * so the caller can remove this element from the list.
81     */
82     public boolean removePrimaryAssetsNotInRoleType( String sRole, String sType )
83     {
84        if ( parentAsset == null )
85           return true;
86  
87        if ( parentAsset.deleteAssetsNotInRoleType( sRole, sType, "PARENT" ) == false )
88           return false;
89        else
90           return true;
91     }
92  
93     /**
94     * This method will return true only if there is a parentAsset and if it was deleted;
95     * this way we will allow the insert of empty elements in the database without fear of
96     * removing them beforehands because they didn't have any assets.
97     */
98     public boolean deleteAssets( String sRole, String sType, String sFlag )
99     {
100       if ( parentAsset != null && parentAsset.deleteAssets( sRole, sType, sFlag ) )
101       {
102          parentAsset = null;
103          return true;
104       }
105       return false;
106    }
107    
108    /**
109    * Will delete an assets that meet the criteria of the argument asset.
110    *
111    * @param assetToDelete
112    * @param nAssetsDeleted keeps a count of the assets deleted so far, at the end of the
113    *        method, this value will be updated with the number of assets (including children
114    *        and itself) deleted.
115    * @return true if this element should be deleted.
116    */
117    public boolean deleteAsset( DisguiseAssetRecordData assetToDelete, int[] nAssetsDeleted )
118    {
119       if ( parentAsset != null && parentAsset.deleteAsset( assetToDelete, nAssetsDeleted ) )
120       {
121             parentAsset = null;
122             return true;
123       }
124       return false;
125    }
126    
127    public boolean hasAssets()
128    {
129       if ( parentAsset != null )
130          return true;
131       else
132          return false;
133    }
134    
135    /**
136    * Clones the element. The bFullClone argument determines if this clone will
137    * include a clone copy of the primary asset, or not. This provides for
138    * creating lite clones of the object.
139    */
140    public synchronized Object cloneElement( boolean bFullClone )
141    {
142       DisguiseElementRecordData clonedObject = new DisguiseElementRecordData();
143       super.cloneRecord( clonedObject );
144       if ( bFullClone && parentAsset != null )
145          clonedObject.setParentAsset( (DisguiseAssetRecordData) parentAsset.cloneAsset(true) );
146 
147       return clonedObject;
148    }
149 }